#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "valgrind/valgrind.h"
#include "cantProceed.h"
#include "epicsMutex.h"
#include "ellLib.h"
#include "dbmf.h"
Go to the source code of this file.
#define DBMF_INITIAL_ITEMS 10 |
#define REDZONE sizeof(double) |
void dbmfFree |
( |
void * |
bytes | ) |
|
Free the memory allocated by dbmfMalloc.
- Parameters
-
Definition at line 175 of file dbmf.c.
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;
struct itemHeader itemHeader
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
#define VALGRIND_MEMPOOL_FREE(pool, addr)
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
void dbmfFreeChunks |
( |
void |
| ) |
|
Free all chunks that contain only free items.
Definition at line 241 of file dbmf.c.
247 printf(
"dbmfFreeChunks called but dbmfInit never called\n");
253 printf(
"dbmfFinish: not all free\n");
#define ellCount(PLIST)
Report the number of nodes in a list.
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
#define ellNext(PNODE)
Find the next node in list.
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
void ellDelete(ELLLIST *pList, ELLNODE *pNode)
Deletes a node from a list.
#define ellFirst(PLIST)
Find the first node in list.
int dbmfInit |
( |
size_t |
size, |
|
|
int |
chunkItems |
|
) |
| |
Initialize the facility.
- Parameters
-
size | The maximum size request from dbmfMalloc() that will be allocated from the dbmf pool (Size is always made a multiple of 8). |
chunkItems | Each time malloc() must be called size*chunkItems bytes are allocated. |
- Returns
- 0 on success, -1 if already initialized
- Note
- If dbmfInit() is not called before one of the other routines then it is automatically called with size=64 and chunkItems=10
Definition at line 71 of file dbmf.c.
74 printf(
"dbmfInit: Already initialized\n");
81 pdbmfPvt->
size = size + size%
sizeof(double);
struct itemHeader itemHeader
#define epicsMutexMustCreate()
Create an epicsMutex semaphore for use from C code.
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)
#define ellInit(PLIST)
Initialize a list type.
void* dbmfMalloc |
( |
size_t |
bytes | ) |
|
Allocate memory.
- Parameters
-
bytes | If bytes > size then malloc() is used to allocate the memory. |
- Returns
- Pointer to the newly-allocated memory, or NULL on failure.
Definition at line 97 of file dbmf.c.
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);
struct chunkNode chunkNode
struct itemHeader itemHeader
#define DBMF_INITIAL_ITEMS
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
void ellAdd(ELLLIST *pList, ELLNODE *pNode)
Adds a node to the end of a list.
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size)
int dbmfInit(size_t size, int chunkItems)
Initialize the facility.
LIBCOM_API void cantProceed(const char *msg,...)
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
int dbmfShow |
( |
int |
level | ) |
|
Show the status of the dbmf memory pool.
- Parameters
-
- Returns
- 0.
Definition at line 205 of file dbmf.c.
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;
#define ellCount(PLIST)
Report the number of nodes in a list.
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
#define ellNext(PNODE)
Find the next node in list.
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
#define ellFirst(PLIST)
Find the first node in list.
char* dbmfStrcat3 |
( |
const char * |
lhs, |
|
|
const char * |
mid, |
|
|
const char * |
rhs |
|
) |
| |
Concatenate three strings.
Returns a pointer to a null-terminated string made by concatenating the three input strings.
- Parameters
-
lhs | Start string to which the others get concatenated to (left part). |
mid | Next string to be concatenated to the lhs (mid part). |
rhs | Last string to be concatenated to the lhs+mid (right part). |
- Returns
- A pointer to the new string, or NULL on failure.
Definition at line 289 of file dbmf.c.
291 size_t len = strlen(lhs) + strlen(mid) + strlen(rhs) + 1;
void * dbmfMalloc(size_t size)
Allocate memory.
char* dbmfStrdup |
( |
const char * |
str | ) |
|
Duplicate a string.
Create a copy of the input string.
- Parameters
-
str | Pointer to the null-terminated string to be copied. |
- Returns
- A pointer to the new copy, or NULL on failure.
Definition at line 159 of file dbmf.c.
161 size_t len = strlen(
str);
164 return strcpy(buf,
str);
void * dbmfMalloc(size_t size)
Allocate memory.
char* dbmfStrndup |
( |
const char * |
str, |
|
|
size_t |
len |
|
) |
| |
Duplicate a string (up to len bytes).
Copy at most len bytes of the input string into a new buffer. If no nil terminator is seen in the first len
bytes a nil terminator is added.
- Parameters
-
str | Pointer to the null-terminated string to be copied. |
len | Max number of bytes to copy. |
- Returns
- A pointer to the new string, or NULL on failure.
Definition at line 167 of file dbmf.c.
172 return strncpy(buf,
str, len);
void * dbmfMalloc(size_t size)
Allocate memory.