47 static int PoolMemset(
void *pitem,
void *initdata)
58 static bool PoolDataPreAllocated(
Pool *p,
void *data)
84 Pool *
PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
85 void *(*Alloc)(
void),
int (*Init)(
void *,
void *),
void *InitData,
86 void (*Cleanup)(
void *),
void (*Free)(
void *))
92 if (size != 0 && prealloc_size > size) {
96 if (size != 0 && elt_size == 0) {
100 if (elt_size && Free) {
104 if (elt_size == 0 && Alloc == NULL) {
125 if (p->
Init == NULL) {
126 p->
Init = PoolMemset;
140 for (u32 = 0; u32 < size; u32++) {
157 for (u32 = 0; u32 < prealloc_size; u32++) {
170 if (pb->
data == NULL) {
233 if (!PoolDataPreAllocated(p, pb->
data)) {
248 if (pb->
data!= NULL) {
251 if (!PoolDataPreAllocated(p, pb->
data)) {
290 if (p->
Alloc != NULL) {
319 void *ptr = pb->
data;
343 if (!PoolDataPreAllocated(p, data)) {
350 SCLogDebug(
"tried to return data %p to the pool %p, but no more "
351 "buckets available. Just freeing the data.", data, p);
374 static void *PoolTestAlloc(
void)
381 static int PoolTestInitArg(
void *data,
void *allocdata)
383 size_t len = strlen((
char *)allocdata) + 1;
390 static void PoolTestFree(
void *ptr)
394 static int PoolTestInit01 (
void)
396 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
403 static int PoolTestInit02 (
void)
405 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
420 static int PoolTestInit03 (
void)
422 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
436 static int PoolTestInit04 (
void)
438 Pool *p =
PoolInit(10,5,strlen(
"test") + 1,NULL, PoolTestInitArg,(
void *)
"test",PoolTestFree, NULL);
454 static int PoolTestInit05 (
void)
456 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL, NULL,PoolTestFree, NULL);
477 static int PoolTestInit06 (
void)
479 Pool *p =
PoolInit(1,0,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
504 static int PoolTestInit07 (
void)
506 Pool *p =
PoolInit(0,1,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);