fixed situations where local host name cache is repatedly created and destroyed

This commit is contained in:
Jeff Hill
2009-02-11 00:50:28 +00:00
parent e1b8caa8d7
commit 77669d793d
8 changed files with 56 additions and 15 deletions

View File

@@ -126,6 +126,7 @@ cac::cac (
epicsMutex & mutualExclusionIn,
epicsMutex & callbackControlIn,
cacContextNotify & notifyIn ) :
_refLocalHostName ( localHostNameCache.getReference () ),
programBeginTime ( epicsTime::getCurrent() ),
connTMO ( CA_CONN_VERIFY_PERIOD ),
mutex ( mutualExclusionIn ),

View File

@@ -36,6 +36,7 @@
#include "epicsTimer.h"
#include "epicsEvent.h"
#include "freeList.h"
#include "localHostName.h"
#ifdef cach_restore_epicsExportSharedSymbols
# define epicsExportSharedSymbols
@@ -212,8 +213,10 @@ public:
static unsigned highestPriorityLevelBelow ( unsigned priority );
void destroyIIU ( tcpiiu & iiu );
const char * pLocalHostName ();
private:
localHostName hostNameCache;
epicsSingleton < localHostName > :: reference _refLocalHostName;
chronIntIdResTable < nciu > chanTable;
//
// !!!! There is at this point no good reason
@@ -434,5 +437,10 @@ inline nciu * cac::lookupChannel (
return this->chanTable.lookup ( idIn );
}
inline const char * cac :: pLocalHostName ()
{
return _refLocalHostName->pointer ();
}
#endif // ifdef cach

View File

@@ -32,6 +32,18 @@
#include "localHostName.h"
#include "cacIO.h"
class CACChannelPrivate {
public:
CACChannelPrivate ();
unsigned getHostName ( char * pBuf, unsigned bufLength );
const char * pHostName ();
private:
epicsSingleton < localHostName > :: reference
_refLocalHostName;
};
static epicsThreadOnceId cacChannelIdOnce = EPICS_THREAD_ONCE_INIT;
const cacChannel::priLev cacChannel::priorityMax = 99u;
const cacChannel::priLev cacChannel::priorityMin = 0u;
const cacChannel::priLev cacChannel::priorityDefault = priorityMin;
@@ -80,15 +92,40 @@ bool cacChannel::connected (
return true;
}
CACChannelPrivate ::
CACChannelPrivate() :
_refLocalHostName ( localHostNameCache.getReference () )
{
}
inline unsigned CACChannelPrivate ::
getHostName ( char * pBuf, unsigned bufLength )
{
return _refLocalHostName->getName ( pBuf, bufLength );
}
inline const char * CACChannelPrivate ::
pHostName ()
{
return _refLocalHostName->pointer ();
}
static CACChannelPrivate * pCACChannelPrivate = 0;
// runs once only for each process
extern "C" void cacChannelSetup ( void * )
{
pCACChannelPrivate = new CACChannelPrivate ();
}
// the default is to assume that it is a locally hosted channel
unsigned cacChannel::getHostName (
epicsGuard < epicsMutex > &,
char * pBuf, unsigned bufLength ) const throw ()
{
if ( bufLength ) {
epicsSingleton < localHostName >::reference
ref ( localHostNameAtLoadTime.getReference () );
return ref->getName ( pBuf, bufLength );
epicsThreadOnce ( & cacChannelIdOnce, cacChannelSetup, 0);
return pCACChannelPrivate->getHostName ( pBuf, bufLength );
}
return 0u;
}
@@ -97,9 +134,8 @@ unsigned cacChannel::getHostName (
const char * cacChannel::pHostName (
epicsGuard < epicsMutex > & ) const throw ()
{
epicsSingleton < localHostName >::reference
ref ( localHostNameAtLoadTime.getReference () );
return ref->pointer ();
epicsThreadOnce ( & cacChannelIdOnce, cacChannelSetup, 0);
return pCACChannelPrivate->pHostName ();
}
cacContext::~cacContext () {}

View File

@@ -56,7 +56,6 @@
#include "epicsMutex.h"
#include "epicsGuard.h"
#include "epicsThread.h"
#include "epicsSingleton.h"
#ifdef cacIOh_restore_epicsExportSharedSymbols
# define epicsExportSharedSymbols

View File

@@ -23,7 +23,7 @@
#include "localHostName.h"
epicsSingleton < localHostName > localHostNameAtLoadTime;
epicsSingleton < localHostName > localHostNameCache;
localHostName::localHostName () :
attachedToSockLib ( osiSockAttach () != 0 ), length ( 0u )

View File

@@ -48,7 +48,7 @@ private:
char cache [128];
};
extern epicsSingleton < localHostName > localHostNameAtLoadTime;
extern epicsSingleton < localHostName > localHostNameCache;
inline unsigned localHostName::nameLength () const
{

View File

@@ -1259,10 +1259,8 @@ void tcpiiu::hostNameSetRequest ( epicsGuard < epicsMutex > & guard ) // X aCC 4
if ( ! CA_V41 ( this->minorProtocolVersion ) ) {
return;
}
epicsSingleton < localHostName >::reference
ref ( localHostNameAtLoadTime.getReference () );
const char * pName = ref->pointer ();
const char * pName = this->cacRef.pLocalHostName ();
unsigned size = strlen ( pName ) + 1u;
unsigned postSize = CA_MESSAGE_ALIGN ( size );
assert ( postSize < 0xffff );

View File

@@ -51,7 +51,6 @@ struct caHdrLargeArray {
ca_uint16_t m_cmmd; // operation to be performed
};
class hostNameCache;
class ipAddrToAsciiEngine;
class tcpRecvThread : private epicsThreadRunable {