26 #define REDZONE sizeof(double) 38 #ifndef DBMF_FREELIST_DEBUG 42 #define DBMF_INITIAL_ITEMS 10 74 printf(
"dbmfInit: Already initialized\n");
81 pdbmfPvt->
size = size + size%
sizeof(double);
108 if(*pfreeList ==
NULL) {
114 pmem = (
char *)malloc(nbytesTotal);
121 pchunkNode->
pchunk = pmem;
128 *pnextFree = *pfreeList; *pfreeList = (
void *)pmem;
133 if(size<=pdbmfPvt->size) {
134 pnextFree = *pfreeList; *pfreeList = *pnextFree;
135 pmem = (
void *)pnextFree;
151 (
unsigned long)size,pmem);
156 return((
void *)pmem);
161 size_t len = strlen(str);
164 return strcpy(buf, str);
172 return strncpy(buf, str, len);
177 char *pmem = (
char *)mem;
183 printf(
"dbmfFree called but dbmfInit never called\n");
192 free((
void *)pmem); pdbmfPvt->
nAlloc--;
194 void **pfreeList = &pdbmfPvt->
freeList;
195 void **pnextFree = &pitemHeader->
pnextFree;
199 *pnextFree = *pfreeList; *pfreeList = pnextFree;
208 printf(
"Never initialized\n");
211 printf(
"size %lu allocSize %lu chunkItems %d ",
212 (
unsigned long)pdbmfPvt->
size,
214 printf(
"nAlloc %d nFree %d nChunks %d nGtSize %d\n",
222 printf(
"pchunkNode %p nNotFree %d\n",
223 (
void*)pchunkNode,pchunkNode->
nNotFree);
231 pnextFree = (
void**)pdbmfPvt->
freeList;
233 printf(
"%p\n",*pnextFree);
234 pnextFree = (
void**)*pnextFree;
247 printf(
"dbmfFreeChunks called but dbmfInit never called\n");
253 printf(
"dbmfFinish: not all free\n");
270 int dbmfInit(
size_t size,
int chunkItems)
274 {
return malloc(size); }
277 {
return strdup((
char*)str); }
289 char *
dbmfStrcat3(
const char *lhs,
const char *mid,
const char *rhs)
291 size_t len = strlen(lhs) + strlen(mid) + strlen(rhs) + 1;
struct chunkNode chunkNode
char * dbmfStrdup(const char *str)
Duplicate a string.
struct itemHeader itemHeader
#define ellCount(PLIST)
Report the number of nodes in a list.
char * dbmfStrcat3(const char *lhs, const char *mid, const char *rhs)
Concatenate three strings.
char * strdup(const char *)
int dbmfShow(int level)
Show the status of the dbmf memory pool.
#define epicsMutexMustCreate()
Create an epicsMutex semaphore for use from C code.
#define DBMF_INITIAL_ITEMS
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
void dbmfFreeChunks(void)
Free all chunks that contain only free items.
A library to manage storage that is allocated and quickly freed.
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)
A doubly-linked list library.
void ellAdd(ELLLIST *pList, ELLNODE *pNode)
Adds a node to the end of a list.
#define ellNext(PNODE)
Find the next node in list.
APIs for the epicsMutex mutual exclusion semaphore.
void dbmfFree(void *mem)
Free the memory allocated by dbmfMalloc.
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size)
int dbmfInit(size_t size, int chunkItems)
Initialize the facility.
#define ellInit(PLIST)
Initialize a list type.
LIBCOM_API void cantProceed(const char *msg,...)
Routines for code that can't continue or return after an error.
#define VALGRIND_MEMPOOL_FREE(pool, addr)
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
void ellDelete(ELLLIST *pList, ELLNODE *pNode)
Deletes a node from a list.
char * dbmfStrndup(const char *str, size_t len)
Duplicate a string (up to len bytes).
void * dbmfMalloc(size_t size)
Allocate memory.
struct dbmfPrivate dbmfPrivate
#define ellFirst(PLIST)
Find the first node in list.