47 static int PoolMemset(
void *pitem,
void *initdata)
58 static bool PoolDataPreAllocated(
Pool *p,
void *data)
81 Pool *
PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
82 void *(*Alloc)(
void),
int (*Init)(
void *,
void *),
void *InitData,
83 void (*Cleanup)(
void *),
void (*Free)(
void *))
89 if (size != 0 && prealloc_size > size) {
93 if (size != 0 && elt_size == 0) {
97 if (elt_size && Free) {
101 if (elt_size == 0 && Alloc == NULL) {
122 if (p->
Init == NULL) {
123 p->
Init = PoolMemset;
137 for (u32 = 0; u32 < size; u32++) {
154 for (u32 = 0; u32 < prealloc_size; u32++) {
167 if (pb->
data == NULL) {
230 if (!PoolDataPreAllocated(p, pb->
data)) {
245 if (pb->
data!= NULL) {
248 if (!PoolDataPreAllocated(p, pb->
data)) {
287 if (p->
Alloc != NULL) {
316 void *ptr = pb->
data;
340 if (!PoolDataPreAllocated(p, data)) {
347 SCLogDebug(
"tried to return data %p to the pool %p, but no more "
348 "buckets available. Just freeing the data.", data, p);
371 static void *PoolTestAlloc(
void)
378 static int PoolTestInitArg(
void *data,
void *allocdata)
380 size_t len = strlen((
char *)allocdata) + 1;
387 static void PoolTestFree(
void *ptr)
391 static int PoolTestInit01 (
void)
393 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
400 static int PoolTestInit02 (
void)
402 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
417 static int PoolTestInit03 (
void)
419 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
433 static int PoolTestInit04 (
void)
435 Pool *p =
PoolInit(10,5,strlen(
"test") + 1,NULL, PoolTestInitArg,(
void *)
"test",PoolTestFree, NULL);
451 static int PoolTestInit05 (
void)
453 Pool *p =
PoolInit(10,5,10,PoolTestAlloc,NULL, NULL,PoolTestFree, NULL);
474 static int PoolTestInit06 (
void)
476 Pool *p =
PoolInit(1,0,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
501 static int PoolTestInit07 (
void)
503 Pool *p =
PoolInit(0,1,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);