diff --git a/src/ca/nciu.cpp b/src/ca/nciu.cpp index dc0ca29cf..4ba522319 100644 --- a/src/ca/nciu.cpp +++ b/src/ca/nciu.cpp @@ -29,6 +29,7 @@ */ #include +#include #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" @@ -41,8 +42,6 @@ #include "cadef.h" #include "db_access.h" // for INVALID_DB_REQ -epicsSingleton < tsFreeList < class nciu, 1024 > > nciu::pFreeList; - nciu::nciu ( cac & cacIn, netiiu & iiuIn, cacChannelNotify & chanIn, const char *pNameIn, cacChannel::priLev pri ) : cacChannel ( chanIn ), @@ -76,12 +75,21 @@ nciu::nciu ( cac & cacIn, netiiu & iiuIn, cacChannelNotify & chanIn, nciu::~nciu () { - // care is taken so that a lock is not applied during this phase - this->cacCtx.uninstallChannel ( *this ); - delete [] this->pNameStr; } +void nciu::destroy () +{ + // care is taken so that a lock is not applied during this phase + this->cacCtx.destroyChannel ( *this ); +} + +void nciu::operator delete ( void * pCadaver ) +{ + throw std::logic_error + ( "compiler is confused about placement delete" ); +} + void nciu::initiateConnect () { this->cacCtx.initiateConnect ( *this ); diff --git a/src/ca/nciu.h b/src/ca/nciu.h index dddb29f76..01a776dd8 100644 --- a/src/ca/nciu.h +++ b/src/ca/nciu.h @@ -35,7 +35,7 @@ #include "tsDLList.h" #include "tsFreeList.h" #include "epicsMutex.h" -#include "epicsSingleton.h" +#include "cxxCompilerDepPlacementDelete.h" #ifdef nciuh_restore_epicsExportSharedSymbols # define epicsExportSharedSymbols @@ -66,7 +66,8 @@ class nciu : public cacChannel, public tsDLNode < nciu >, public: nciu ( cac &, netiiu &, cacChannelNotify &, const char *pNameIn, cacChannel::priLev ); - ~nciu (); // force pool allocation + ~nciu (); + void destroy (); void connect ( unsigned nativeType, unsigned nativeCount, unsigned sid, bool v41Ok ); void connect (); @@ -76,8 +77,6 @@ public: bool searchMsg ( class udpiiu & iiu, unsigned & retryNoForThisChannel ); void createChannelRequest ( class tcpiiu & iiu ); bool identifierEquivelence ( unsigned idToMatch ); - void * operator new ( size_t size ); - void operator delete ( void *pCadaver, size_t size ); void beaconAnomalyNotify (); void serviceShutdownNotify (); void accessRightsStateChange ( const caAccessRights & ); @@ -98,6 +97,10 @@ public: void writeException ( epicsGuard < callbackMutex > &, int status, const char *pContext, unsigned type, arrayElementCount count ); cacChannel::priLev getPriority () const; + void * operator new ( size_t size, tsFreeList < class nciu, 1024 > & ); +# ifdef CXX_PLACEMENT_DELETE + void operator delete ( void *, tsFreeList < class nciu, 1024 > & ); +# endif private: caAccessRights accessRightState; cac & cacCtx; @@ -129,20 +132,27 @@ private: bool ca_v42_ok () const; void hostName ( char *pBuf, unsigned bufLength ) const; static void stringVerify ( const char *pStr, const unsigned count ); - static epicsSingleton < tsFreeList < class nciu, 1024 > > pFreeList; nciu ( const nciu & ); nciu & operator = ( const nciu & ); + void * operator new ( size_t ); + void operator delete ( void * ); + void * operator new [] ( size_t ); + void operator delete [] ( void * ); }; -inline void * nciu::operator new ( size_t size ) +inline void * nciu::operator new ( size_t size, + tsFreeList < class nciu, 1024 > & freeList ) { - return nciu::pFreeList->allocate ( size ); + return freeList.allocate ( size ); } -inline void nciu::operator delete ( void *pCadaver, size_t size ) +#ifdef CXX_PLACEMENT_DELETE +inline void nciu::operator delete ( void * pCadaver, + tsFreeList < class nciu, 1024 > & freeList ) { - nciu::pFreeList->release ( pCadaver, size ); + freeList.release ( pCadaver, sizeof ( nciu ) ); } +#endif inline bool nciu::identifierEquivelence ( unsigned idToMatch ) { diff --git a/src/ca/netIO.h b/src/ca/netIO.h index 392b12e39..e4b3b739f 100644 --- a/src/ca/netIO.h +++ b/src/ca/netIO.h @@ -27,17 +27,7 @@ #define netIOh #include "nciu.h" - -// does the compiler support placement delete -#if defined (_MSC_VER) && ( _MSC_VER >= 1200 ) -# define NETIO_PLACEMENT_DELETE -#elif defined ( __HP_aCC ) && ( _HP_aCC > 033300 ) -# define NETIO_PLACEMENT_DELETE -#elif defined ( __BORLANDC__ ) && ( __BORLANDC__ > 0x550 ) -# define NETIO_PLACEMENT_DELETE -#else -# define NETIO_PLACEMENT_DELETE -#endif +#include "cxxCompilerDepPlacementDelete.h" // SUN PRO generates multiply defined symbols if the baseNMIU // destructor is virtual (therefore it is protected). @@ -96,7 +86,7 @@ private: void operator delete ( void * ); void * operator new ( size_t, tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & ); -# if defined ( NETIO_PLACEMENT_DELETE ) +# if defined ( CXX_PLACEMENT_DELETE ) void operator delete ( void *, tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & ); # endif @@ -129,7 +119,7 @@ private: void operator delete ( void * ); void * operator new ( size_t, tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & ); -# if defined ( NETIO_PLACEMENT_DELETE ) +# if defined ( CXX_PLACEMENT_DELETE ) void operator delete ( void *, tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & ); # endif @@ -161,7 +151,7 @@ private: void operator delete ( void * ); void * operator new ( size_t, tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & ); -# if defined ( NETIO_PLACEMENT_DELETE ) +# if defined ( CXX_PLACEMENT_DELETE ) void operator delete ( void *, tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & ); # endif @@ -185,24 +175,14 @@ inline void * netSubscription::operator new ( size_t size, return freeList.allocate ( size ); } -#if defined ( NETIO_PLACEMENT_DELETE ) +#if defined ( CXX_PLACEMENT_DELETE ) inline void netSubscription::operator delete ( void *pCadaver, tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList ) { - freeList.release ( pCadaver, sizeof ( netSubscription ) ); + freeList.release ( pCadaver ); } #endif -inline void * netSubscription::operator new ( size_t sizeIn ) -{ - return ::operator new ( sizeIn ); -} - -inline void netSubscription::operator delete ( void * p ) -{ - ::operator delete ( p ); -} - inline netSubscription * netSubscription::factory ( tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList, nciu &chan, unsigned type, arrayElementCount count, @@ -246,24 +226,14 @@ inline void * netReadNotifyIO::operator new ( size_t size, return freeList.allocate ( size ); } -#if defined ( NETIO_PLACEMENT_DELETE ) +#if defined ( CXX_PLACEMENT_DELETE ) inline void netReadNotifyIO::operator delete ( void *pCadaver, tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > &freeList ) { - freeList.release ( pCadaver, sizeof ( netWriteNotifyIO ) ); + freeList.release ( pCadaver ); } #endif -inline void * netReadNotifyIO::operator new ( size_t sizeIn ) -{ - return ::operator new ( sizeIn ); -} - -inline void netReadNotifyIO::operator delete ( void * p ) -{ - ::operator delete ( p ); -} - inline netWriteNotifyIO * netWriteNotifyIO::factory ( tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList, nciu &chan, cacWriteNotify ¬ify ) @@ -277,22 +247,12 @@ inline void * netWriteNotifyIO::operator new ( size_t size, return freeList.allocate ( size ); } -#if defined ( NETIO_PLACEMENT_DELETE ) +#if defined ( CXX_PLACEMENT_DELETE ) inline void netWriteNotifyIO::operator delete ( void *pCadaver, tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList ) { - freeList.release ( pCadaver, sizeof ( netWriteNotifyIO ) ); + freeList.release ( pCadaver ); } #endif -inline void * netWriteNotifyIO::operator new ( size_t sizeIn ) -{ - return ::operator new ( sizeIn ); -} - -inline void netWriteNotifyIO::operator delete ( void * p ) -{ - ::operator delete ( p ); -} - #endif // ifdef netIOh