55 #ifdef EPICS_FREELIST_DEBUG
56 # define tsFreeListDebugBypass 1
57 # define tsFreeListMemSetNew(P,SIZE) memset ( (P), 0xaa, (SIZE) )
58 # define tsFreeListMemSetDelete(P,SIZE) memset ( (P), 0xdd, (SIZE) )
60 # define tsFreeListDebugBypass 0
61 # define tsFreeListMemSetNew(P,SIZE)
62 # define tsFreeListMemSetDelete(P,SIZE)
70 #include "epicsGuard.h"
76 #if defined ( _MSC_VER ) && _MSC_VER <= 1200
77 # pragma warning ( disable : 4291 )
83 template <
class T,
unsigned N = 0x400,
89 void * allocate (
size_t size );
90 void release (
void * p );
91 void release (
void * p,
size_t size );
96 void * allocateFromNewChunk ();
102 char pad [
sizeof ( T ) ];
106 template <
class T,
unsigned N = 0x400 >
112 template <
class T,
unsigned N,
class MUTEX >
114 pFreeList ( 0 ), pChunkList ( 0 ) {}
116 template <
class T,
unsigned N,
class MUTEX >
120 this->pChunkList = this->pChunkList->pNext;
125 template <
class T,
unsigned N,
class MUTEX >
128 if ( size !=
sizeof ( T ) || N == 0u || tsFreeListDebugBypass ) {
129 void * p = ::operator
new ( size );
130 tsFreeListMemSetNew ( p, size );
138 this->pFreeList = p->pNext;
139 return static_cast <
void * > ( p );
141 return this->allocateFromNewChunk ();
144 template <
class T,
unsigned N,
class MUTEX >
150 for (
unsigned i=1u; i < N-1; i++ ) {
151 pChunk->items[i].pNext = &pChunk->items[i+1];
153 pChunk->items[N-1].pNext = 0;
155 this->pFreeList = &pChunk->items[1u];
157 pChunk->pNext = this->pChunkList;
158 this->pChunkList = pChunk;
160 return static_cast <
void *> ( &pChunk->items[0] );
163 template <
class T,
unsigned N,
class MUTEX >
166 if ( size !=
sizeof ( T ) ) {
167 tsFreeListMemSetDelete ( pCadaver, size );
168 ::operator
delete ( pCadaver );
171 this->release ( pCadaver );
175 template <
class T,
unsigned N,
class MUTEX >
178 if ( N == 0u || tsFreeListDebugBypass ) {
179 tsFreeListMemSetDelete ( pCadaver,
sizeof ( T ) );
180 ::operator
delete ( pCadaver );
182 else if ( pCadaver ) {
186 p->pNext = this->pFreeList;
191 #endif // tsFreeList_h
Compiler specific declarations.
The C++ API for an epicsMutex.
APIs for the epicsMutex mutual exclusion semaphore.