placement new issues

This commit is contained in:
Jeff Hill
2002-04-25 18:26:33 +00:00
parent f670103a0c
commit 8334b8d261
4 changed files with 111 additions and 54 deletions

View File

@@ -20,6 +20,19 @@
#include "nciu.h"
// does the local compiler support placement delete
#if defined (_MSC_VER)
# if _MSC_VER >= 1200
# define NETIO_PLACEMENT_DELETE
# endif
#elif defined (__GNUC__) && 0
# if __GNUC__>2 || ( __GNUC__==2 && __GNUC_MINOR_>=96 )
# define NETIO_PLACEMENT_DELETE
# endif
#else
# define NETIO_PLACEMENT_DELETE
#endif
class baseNMIU : public tsDLNode < baseNMIU >,
public chronIntIdRes < baseNMIU > {
public:
@@ -38,7 +51,7 @@ public:
ca_uint32_t getID () const;
nciu & channel () const;
protected:
virtual ~baseNMIU () = 0;
virtual ~baseNMIU ();
//
// perhaps we should not store the channel here and instead fetch it out of the
// notify
@@ -68,8 +81,6 @@ public:
void exception ( int status,
const char *pContext, unsigned type,
arrayElementCount count );
protected:
~netSubscription ();
private:
const arrayElementCount count;
cacStateNotify &notify;
@@ -80,12 +91,19 @@ private:
class netSubscription * isSubscription ();
void * operator new ( size_t,
tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & );
# if ! defined ( NO_PLACEMENT_DELETE )
void operator delete ( void *, size_t,
# if defined ( NETIO_PLACEMENT_DELETE )
void operator delete ( void *,
tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & );
# endif
netSubscription ( const netSubscription & );
netSubscription & operator = ( const netSubscription & );
~netSubscription ();
# if defined (_MSC_VER) && _MSC_VER == 1300
void operator delete ( void * ); // avoid visual c++ 7 bug
# endif
# if __GNUC__==2 && __GNUC_MINOR_<96
void operator delete ( void *, size_t ); // avoid gnu g++ bug
# endif
};
class netReadNotifyIO : public baseNMIU {
@@ -101,19 +119,24 @@ public:
arrayElementCount count, const void *pData );
void exception ( int status, const char *pContext,
unsigned type, arrayElementCount count );
protected:
~netReadNotifyIO ();
private:
cacReadNotify &notify;
netReadNotifyIO ( nciu &chan, cacReadNotify &notify );
cacReadNotify & notify;
netReadNotifyIO ( nciu & chan, cacReadNotify & notify );
void * operator new ( size_t,
tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & );
# if ! defined ( NO_PLACEMENT_DELETE )
void operator delete ( void *, size_t,
# if defined ( NETIO_PLACEMENT_DELETE )
void operator delete ( void *,
tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & );
# endif
~netReadNotifyIO ();
netReadNotifyIO ( const netReadNotifyIO & );
netReadNotifyIO & operator = ( const netReadNotifyIO & );
# if defined (_MSC_VER) && _MSC_VER == 1300
void operator delete ( void * ); // avoid visual c++ 7 bug
# endif
# if __GNUC__==2 && __GNUC_MINOR_<96
void operator delete ( void *, size_t ); // avoid gnu g++ bug
# endif
};
class netWriteNotifyIO : public baseNMIU {
@@ -129,19 +152,24 @@ public:
arrayElementCount count, const void *pData );
void exception ( int status, const char *pContext,
unsigned type, arrayElementCount count );
protected:
~netWriteNotifyIO ();
private:
cacWriteNotify &notify;
netWriteNotifyIO ( nciu &chan, cacWriteNotify &notify );
void * operator new ( size_t,
tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & );
# if ! defined ( NO_PLACEMENT_DELETE )
void operator delete ( void *, size_t,
# if defined ( NETIO_PLACEMENT_DELETE )
void operator delete ( void *,
tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & );
# endif
netWriteNotifyIO ( const netWriteNotifyIO & );
netWriteNotifyIO & operator = ( const netWriteNotifyIO & );
~netWriteNotifyIO ();
# if defined (_MSC_VER) && _MSC_VER == 1300
void operator delete ( void * ); // avoid visual c++ 7 bug
# endif
# if __GNUC__==2 && __GNUC_MINOR_<96
void operator delete ( void *, size_t ); // avoid gnu g++ bug
# endif
};
inline ca_uint32_t baseNMIU::getID () const
@@ -160,19 +188,6 @@ inline void * netSubscription::operator new ( size_t size,
return freeList.allocate ( size );
}
// NOTE: The constructor for netSubscription::netSubscription() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netSubscription when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netSubscription::netSubscription()
#if ! defined ( NO_PLACEMENT_DELETE )
inline void netSubscription::operator delete ( void *pCadaver, size_t size,
tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList )
{
freeList.release ( pCadaver, size );
}
#endif
inline netSubscription * netSubscription::factory (
tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList,
nciu &chan, unsigned type, arrayElementCount count,
@@ -216,18 +231,6 @@ inline void * netReadNotifyIO::operator new ( size_t size,
return freeList.allocate ( size );
}
// NOTE: The constructor for netReadNotifyIO::netReadNotifyIO() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netReadNotifyIO when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netReadNotifyIO::netReadNotifyIO()
#if ! defined ( NO_PLACEMENT_DELETE )
inline void netReadNotifyIO::operator delete ( void *pCadaver, size_t size,
tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > &freeList ) {
freeList.release ( pCadaver, size );
}
#endif
inline netWriteNotifyIO * netWriteNotifyIO::factory (
tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList,
nciu &chan, cacWriteNotify &notify )
@@ -241,17 +244,4 @@ inline void * netWriteNotifyIO::operator new ( size_t size,
return freeList.allocate ( size );
}
// NOTE: The constructor for netWriteNotifyIO::netWriteNotifyIO() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netWriteNotifyIO when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netWriteNotifyIO::netWriteNotifyIO()
#if ! defined ( NO_PLACEMENT_DELETE )
inline void netWriteNotifyIO::operator delete ( void *pCadaver, size_t size,
tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList )
{
freeList.release ( pCadaver, size );
}
#endif
#endif // ifdef netIOh

View File

@@ -10,13 +10,15 @@
* Author: Jeff Hill
*/
#include <stdexcept>
#define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
#include "iocinf.h"
#include "nciu.h"
#include "cac.h"
netReadNotifyIO::netReadNotifyIO ( nciu &chan, cacReadNotify &notify ) :
netReadNotifyIO::netReadNotifyIO ( nciu & chan, cacReadNotify & notify ) :
baseNMIU ( chan ), notify ( notify )
{
}
@@ -62,5 +64,24 @@ void netReadNotifyIO::completion ( unsigned type,
this->notify.completion ( type, count, pData );
}
// NOTE: The constructor for netReadNotifyIO::netReadNotifyIO() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netReadNotifyIO when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netReadNotifyIO::netReadNotifyIO()
#if defined ( NETIO_PLACEMENT_DELETE )
void netReadNotifyIO::operator delete ( void *pCadaver,
tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & freeList ) {
freeList.release ( pCadaver, sizeof ( netReadNotifyIO ) );
}
#endif
# if defined (_MSC_VER) && _MSC_VER == 1300
void netReadNotifyIO::operator delete ( void * ) // avoid visual c++ 7 bug
{
throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" );
}
# endif

View File

@@ -10,6 +10,8 @@
* Author: Jeff Hill
*/
#include <stdexcept>
#define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
#define epicsExportSharedSymbols
@@ -80,5 +82,26 @@ void netSubscription::completion ( unsigned typeIn,
this->notify.current ( typeIn, countIn, pDataIn );
}
// NOTE: The constructor for netSubscription::netSubscription() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netSubscription when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netSubscription::netSubscription()
#if defined ( NETIO_PLACEMENT_DELETE )
void netSubscription::operator delete ( void *pCadaver,
tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList )
{
freeList.release ( pCadaver, sizeof ( netSubscription ) );
}
#endif
# if defined (_MSC_VER) && _MSC_VER == 1300
void netSubscription::operator delete ( void * ) // avoid visual c++ 7 bug
{
throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" );
}
# endif

View File

@@ -10,6 +10,8 @@
* Author: Jeff Hill
*/
#include <stdexcept>
#define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
#include "iocinf.h"
@@ -63,5 +65,26 @@ void netWriteNotifyIO::completion ( unsigned /* type */,
this->chan.getClient().printf ( "Write response with data ?\n" );
}
// NOTE: The constructor for netWriteNotifyIO::netWriteNotifyIO() currently does
// not throw an exception, but we should eventually have placement delete
// defined for class netWriteNotifyIO when compilers support this so that
// there is no possibility of a leak if there was an exception in
// a future version of netWriteNotifyIO::netWriteNotifyIO()
#if defined ( NETIO_PLACEMENT_DELETE )
void netWriteNotifyIO::operator delete ( void *pCadaver,
tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList )
{
freeList.release ( pCadaver, sizeof ( netWriteNotifyIO ) );
}
#endif
# if defined (_MSC_VER) && _MSC_VER == 1300
void netWriteNotifyIO::operator delete ( void * ) // avoid visual c++ 7 bug
{
throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" );
}
# endif