suricata
util-pool.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \defgroup utilpool Pool
20  *
21  * ::Pool are an effective way to maintain a set of ready to use
22  * structures.
23  *
24  * To create a ::Pool, you need to use PoolInit(). You can
25  * get an item from the ::Pool by using PoolGet(). When you're
26  * done with it call PoolReturn().
27  * To destroy the ::Pool, call PoolFree(), it will free all used
28  * memory.
29  *
30  * @{
31  */
32 
33 /**
34  * \file
35  *
36  * \author Victor Julien <victor@inliniac.net>
37  *
38  * Pool utility functions
39  */
40 
41 #include "suricata-common.h"
42 #include "util-pool.h"
43 #include "util-pool-thread.h"
44 #include "util-unittest.h"
45 #include "util-debug.h"
46 
47 static int PoolMemset(void *pitem, void *initdata)
48 {
49  Pool *p = (Pool *) initdata;
50 
51  memset(pitem, 0, p->elt_size);
52  return 1;
53 }
54 
55 /**
56  * \brief Check if data is preallocated
57  * \retval 0 if not inside the prealloc'd block, 1 if inside */
58 static int PoolDataPreAllocated(Pool *p, void *data)
59 {
60  ptrdiff_t delta = data - p->data_buffer;
61  if ((delta < 0) || (delta > p->data_buffer_size)) {
62  return 0;
63  }
64  return 1;
65 }
66 
67 /** \brief Init a Pool
68  *
69  * PoolInit() creates a ::Pool. The Alloc function must only do
70  * allocation stuff. The Cleanup function must not try to free
71  * the PoolBucket::data. This is done by the ::Pool management
72  * system.
73  *
74  * \param size
75  * \param prealloc_size
76  * \param elt_size Memory size of an element
77  * \param Alloc An allocation function or NULL to use a standard SCMalloc
78  * \param Init An init function or NULL to use a standard memset to 0
79  * \param InitData Init data
80  * \param Cleanup a free function or NULL if no special treatment is needed
81  * \param Free free func
82  * \retval the allocated Pool
83  */
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 *))
87 {
88  Pool *p = NULL;
89 
90  if (size != 0 && prealloc_size > size) {
91  SCLogError(SC_ERR_POOL_INIT, "size error");
92  goto error;
93  }
94  if (size != 0 && elt_size == 0) {
95  SCLogError(SC_ERR_POOL_INIT, "size != 0 && elt_size == 0");
96  goto error;
97  }
98  if (elt_size && Free) {
99  SCLogError(SC_ERR_POOL_INIT, "elt_size && Free");
100  goto error;
101  }
102 
103  /* setup the filter */
104  p = SCMalloc(sizeof(Pool));
105  if (unlikely(p == NULL)) {
106  SCLogError(SC_ERR_POOL_INIT, "alloc error");
107  goto error;
108  }
109 
110  memset(p,0,sizeof(Pool));
111 
112  p->max_buckets = size;
113  p->preallocated = prealloc_size;
114  p->elt_size = elt_size;
115  p->data_buffer_size = prealloc_size * elt_size;
116  p->Alloc = Alloc;
117  p->Init = Init;
118  p->InitData = InitData;
119  p->Cleanup = Cleanup;
120  p->Free = Free;
121  if (p->Init == NULL) {
122  p->Init = PoolMemset;
123  p->InitData = p;
124  }
125 
126  /* alloc the buckets and place them in the empty list */
127  uint32_t u32 = 0;
128  if (size > 0) {
129  PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket));
130  if (unlikely(pb == NULL)) {
131  SCLogError(SC_ERR_POOL_INIT, "alloc error");
132  goto error;
133  }
134  memset(pb, 0, size * sizeof(PoolBucket));
135  p->pb_buffer = pb;
136  for (u32 = 0; u32 < size; u32++) {
137  /* populate pool */
138  pb->next = p->empty_stack;
140  p->empty_stack = pb;
141  p->empty_stack_size++;
142  pb++;
143  }
144 
145  p->data_buffer = SCCalloc(prealloc_size, elt_size);
146  /* FIXME better goto */
147  if (p->data_buffer == NULL) {
148  SCLogError(SC_ERR_POOL_INIT, "alloc error");
149  goto error;
150  }
151  }
152  /* prealloc the buckets and requeue them to the alloc list */
153  for (u32 = 0; u32 < prealloc_size; u32++) {
154  if (size == 0) { /* unlimited */
155  PoolBucket *pb = SCMalloc(sizeof(PoolBucket));
156  if (unlikely(pb == NULL)) {
157  SCLogError(SC_ERR_POOL_INIT, "alloc error");
158  goto error;
159  }
160  memset(pb, 0, sizeof(PoolBucket));
161 
162  if (p->Alloc) {
163  pb->data = p->Alloc();
164  } else {
165  pb->data = SCMalloc(p->elt_size);
166  }
167  if (pb->data == NULL) {
168  SCLogError(SC_ERR_POOL_INIT, "alloc error");
169  SCFree(pb);
170  goto error;
171  }
172  if (p->Init(pb->data, p->InitData) != 1) {
173  SCLogError(SC_ERR_POOL_INIT, "init error");
174  if (p->Free)
175  p->Free(pb->data);
176  else
177  SCFree(pb->data);
178  SCFree(pb);
179  goto error;
180  }
181  p->allocated++;
182 
183  pb->next = p->alloc_stack;
184  p->alloc_stack = pb;
185  p->alloc_stack_size++;
186  } else {
187  PoolBucket *pb = p->empty_stack;
188  if (pb == NULL) {
189  SCLogError(SC_ERR_POOL_INIT, "alloc error");
190  goto error;
191  }
192 
193  pb->data = (char *)p->data_buffer + u32 * elt_size;
194  if (p->Init(pb->data, p->InitData) != 1) {
195  SCLogError(SC_ERR_POOL_INIT, "init error");
196  pb->data = NULL;
197  goto error;
198  }
199 
200  p->empty_stack = pb->next;
201  p->empty_stack_size--;
202 
203  p->allocated++;
204 
205  pb->next = p->alloc_stack;
206  p->alloc_stack = pb;
207  p->alloc_stack_size++;
208  }
209  }
210 
211  return p;
212 
213 error:
214  if (p != NULL) {
215  PoolFree(p);
216  }
217  return NULL;
218 }
219 
220 void PoolFree(Pool *p)
221 {
222  if (p == NULL)
223  return;
224 
225  while (p->alloc_stack != NULL) {
226  PoolBucket *pb = p->alloc_stack;
227  p->alloc_stack = pb->next;
228  if (p->Cleanup)
229  p->Cleanup(pb->data);
230  if (PoolDataPreAllocated(p, pb->data) == 0) {
231  if (p->Free)
232  p->Free(pb->data);
233  else
234  SCFree(pb->data);
235  }
236  pb->data = NULL;
237  if (!(pb->flags & POOL_BUCKET_PREALLOCATED)) {
238  SCFree(pb);
239  }
240  }
241 
242  while (p->empty_stack != NULL) {
243  PoolBucket *pb = p->empty_stack;
244  p->empty_stack = pb->next;
245  if (pb->data!= NULL) {
246  if (p->Cleanup)
247  p->Cleanup(pb->data);
248  if (PoolDataPreAllocated(p, pb->data) == 0) {
249  if (p->Free)
250  p->Free(pb->data);
251  else
252  SCFree(pb->data);
253  }
254  pb->data = NULL;
255  }
256  if (!(pb->flags & POOL_BUCKET_PREALLOCATED)) {
257  SCFree(pb);
258  }
259  }
260 
261  if (p->pb_buffer)
262  SCFree(p->pb_buffer);
263  if (p->data_buffer)
264  SCFree(p->data_buffer);
265  SCFree(p);
266 }
267 
268 void PoolPrint(Pool *p)
269 {
270  printf("\n----------- Hash Table Stats ------------\n");
271  printf("Buckets: %" PRIu32 "\n", p->empty_stack_size + p->alloc_stack_size);
272  printf("-----------------------------------------\n");
273 }
274 
275 void *PoolGet(Pool *p)
276 {
277  SCEnter();
278 
279  PoolBucket *pb = p->alloc_stack;
280  if (pb != NULL) {
281  /* pull from the alloc list */
282  p->alloc_stack = pb->next;
283  p->alloc_stack_size--;
284 
285  /* put in the empty list */
286  pb->next = p->empty_stack;
287  p->empty_stack = pb;
288  p->empty_stack_size++;
289  } else {
290  if (p->max_buckets == 0 || p->allocated < p->max_buckets) {
291  void *pitem;
292  SCLogDebug("max_buckets %"PRIu32"", p->max_buckets);
293 
294  if (p->Alloc != NULL) {
295  pitem = p->Alloc();
296  } else {
297  pitem = SCMalloc(p->elt_size);
298  }
299 
300  if (pitem != NULL) {
301  if (p->Init(pitem, p->InitData) != 1) {
302  if (p->Free != NULL)
303  p->Free(pitem);
304  else
305  SCFree(pitem);
306  SCReturnPtr(NULL, "void");
307  }
308 
309  p->allocated++;
310  p->outstanding++;
311 #ifdef DEBUG
312  if (p->outstanding > p->max_outstanding)
313  p->max_outstanding = p->outstanding;
314 #endif
315  }
316 
317  SCReturnPtr(pitem, "void");
318  } else {
319  SCReturnPtr(NULL, "void");
320  }
321  }
322 
323  void *ptr = pb->data;
324  pb->data = NULL;
325  p->outstanding++;
326 #ifdef DEBUG
327  if (p->outstanding > p->max_outstanding)
328  p->max_outstanding = p->outstanding;
329 #endif
330  SCReturnPtr(ptr,"void");
331 }
332 
333 void PoolReturn(Pool *p, void *data)
334 {
335  SCEnter();
336 
337  PoolBucket *pb = p->empty_stack;
338 
339  SCLogDebug("pb %p", pb);
340 
341  if (pb == NULL) {
342  p->allocated--;
343  p->outstanding--;
344  if (p->Cleanup != NULL) {
345  p->Cleanup(data);
346  }
347  if (PoolDataPreAllocated(p, data) == 0) {
348  if (p->Free)
349  p->Free(data);
350  else
351  SCFree(data);
352  }
353 
354  SCLogDebug("tried to return data %p to the pool %p, but no more "
355  "buckets available. Just freeing the data.", data, p);
356  SCReturn;
357  }
358 
359  /* pull from the alloc list */
360  p->empty_stack = pb->next;
361  p->empty_stack_size--;
362 
363  /* put in the alloc list */
364  pb->next = p->alloc_stack;
365  p->alloc_stack = pb;
366  p->alloc_stack_size++;
367 
368  pb->data = data;
369  p->outstanding--;
370  SCReturn;
371 }
372 
374 {
375  SCLogDebug("pool %p is using %" PRIu32 " out of %" PRIu32 " items (%02.1f%%), max %" PRIu32
376  " (%02.1f%%): pool struct memory %" PRIu64 ".",
377  p, p->outstanding, p->max_buckets,
378  (float)(p->outstanding) / (float)(p->max_buckets) * 100, p->max_outstanding,
379  (float)(p->max_outstanding) / (float)(p->max_buckets) * 100,
380  (uint64_t)(p->max_buckets * sizeof(PoolBucket)));
381 }
382 
383 /*
384  * ONLY TESTS BELOW THIS COMMENT
385  */
386 
387 #ifdef UNITTESTS
388 static void *PoolTestAlloc(void)
389 {
390  void *ptr = SCMalloc(10);
391  if (unlikely(ptr == NULL))
392  return NULL;
393  return ptr;
394 }
395 static int PoolTestInitArg(void *data, void *allocdata)
396 {
397  size_t len = strlen((char *)allocdata) + 1;
398  char *str = data;
399  if (str != NULL)
400  strlcpy(str,(char *)allocdata,len);
401  return 1;
402 }
403 
404 static void PoolTestFree(void *ptr)
405 {
406  return;
407 }
408 
409 static int PoolTestInit01 (void)
410 {
411  Pool *p = PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
412  if (p == NULL)
413  return 0;
414 
415  PoolFree(p);
416  return 1;
417 }
418 
419 static int PoolTestInit02 (void)
420 {
421  int retval = 0;
422 
423  Pool *p = PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
424  if (p == NULL)
425  goto end;
426 
427  if (p->alloc_stack == NULL || p->empty_stack == NULL) {
428  printf("list(s) not properly initialized (a:%p e:%p): ",
429  p->alloc_stack, p->empty_stack);
430  retval = 0;
431  goto end;
432  }
433 
434  if (p->Alloc != PoolTestAlloc) {
435  printf("Alloc func ptr %p != %p: ",
436  p->Alloc, PoolTestAlloc);
437  retval = 0;
438  goto end;
439  }
440 
441  if (p->Cleanup != PoolTestFree) {
442  printf("Free func ptr %p != %p: ",
443  p->Cleanup, PoolTestFree);
444  retval = 0;
445  goto end;
446  }
447 
448  retval = 1;
449 end:
450  if (p != NULL)
451  PoolFree(p);
452  return retval;
453 }
454 
455 static int PoolTestInit03 (void)
456 {
457  int retval = 0;
458  void *data = NULL;
459 
460  Pool *p = PoolInit(10,5,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
461  if (p == NULL)
462  goto end;
463 
464  data = PoolGet(p);
465  if (data == NULL) {
466  printf("PoolGet returned NULL: ");
467  retval = 0;
468  goto end;
469  }
470 
471  if (p->alloc_stack_size != 4) {
472  printf("p->alloc_stack_size 4 != %" PRIu32 ": ", p->alloc_stack_size);
473  retval = 0;
474  goto end;
475  }
476 
477  if (p->empty_stack_size != 6) {
478  printf("p->empty_stack_size 6 != %" PRIu32 ": ", p->empty_stack_size);
479  retval = 0;
480  goto end;
481  }
482 
483  retval = 1;
484 end:
485  if (p != NULL)
486  PoolFree(p);
487  return retval;
488 }
489 
490 static int PoolTestInit04 (void)
491 {
492  int retval = 0;
493  char *str = NULL;
494 
495  Pool *p = PoolInit(10,5,strlen("test") + 1,NULL, PoolTestInitArg,(void *)"test",PoolTestFree, NULL);
496  if (p == NULL)
497  goto end;
498 
499  str = PoolGet(p);
500  if (str == NULL) {
501  printf("PoolGet returned NULL: ");
502  retval = 0;
503  goto end;
504  }
505 
506  if (strcmp(str, "test") != 0) {
507  printf("Memory not properly initialized: ");
508  retval = 0;
509  goto end;
510  }
511 
512  if (p->alloc_stack_size != 4) {
513  printf("p->alloc_stack_size 4 != %" PRIu32 ": ", p->alloc_stack_size);
514  retval = 0;
515  goto end;
516  }
517 
518  if (p->empty_stack_size != 6) {
519  printf("p->empty_stack_size 6 != %" PRIu32 ": ", p->empty_stack_size);
520  retval = 0;
521  goto end;
522  }
523 
524  retval = 1;
525 end:
526  if (p != NULL)
527  PoolFree(p);
528  return retval;
529 }
530 
531 static int PoolTestInit05 (void)
532 {
533  int retval = 0;
534  void *data = NULL;
535 
536  Pool *p = PoolInit(10,5,10,PoolTestAlloc,NULL, NULL,PoolTestFree, NULL);
537  if (p == NULL)
538  goto end;
539 
540  data = PoolGet(p);
541  if (data == NULL) {
542  printf("PoolGet returned NULL: ");
543  retval = 0;
544  goto end;
545  }
546 
547  if (p->alloc_stack_size != 4) {
548  printf("p->alloc_stack_size 4 != %" PRIu32 ": ", p->alloc_stack_size);
549  retval = 0;
550  goto end;
551  }
552 
553  if (p->empty_stack_size != 6) {
554  printf("p->empty_stack_size 6 != %" PRIu32 ": ", p->empty_stack_size);
555  retval = 0;
556  goto end;
557  }
558 
559  PoolReturn(p, data);
560  data = NULL;
561 
562  if (p->alloc_stack_size != 5) {
563  printf("p->alloc_stack_size 5 != %" PRIu32 ": ", p->alloc_stack_size);
564  retval = 0;
565  goto end;
566  }
567 
568  if (p->empty_stack_size != 5) {
569  printf("p->empty_stack_size 5 != %" PRIu32 ": ", p->empty_stack_size);
570  retval = 0;
571  goto end;
572  }
573 
574  retval = 1;
575 end:
576  if (p != NULL)
577  PoolFree(p);
578  return retval;
579 }
580 
581 static int PoolTestInit06 (void)
582 {
583  int retval = 0;
584  void *data = NULL;
585  void *data2 = NULL;
586 
587  Pool *p = PoolInit(1,0,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
588  if (p == NULL)
589  goto end;
590 
591  if (p->allocated != 0) {
592  printf("p->allocated 0 != %" PRIu32 ": ", p->allocated);
593  retval = 0;
594  goto end;
595  }
596 
597  data = PoolGet(p);
598  if (data == NULL) {
599  printf("PoolGet returned NULL: ");
600  retval = 0;
601  goto end;
602  }
603 
604  if (p->allocated != 1) {
605  printf("p->allocated 1 != %" PRIu32 ": ", p->allocated);
606  retval = 0;
607  goto end;
608  }
609 
610  data2 = PoolGet(p);
611  if (data2 != NULL) {
612  printf("PoolGet returned %p, expected NULL: ", data2);
613  retval = 0;
614  goto end;
615  }
616 
617  PoolReturn(p,data);
618  data = NULL;
619 
620  if (p->allocated != 1) {
621  printf("p->allocated 1 != %" PRIu32 ": ", p->allocated);
622  retval = 0;
623  goto end;
624  }
625 
626  if (p->alloc_stack_size != 1) {
627  printf("p->alloc_stack_size 1 != %" PRIu32 ": ", p->alloc_stack_size);
628  retval = 0;
629  goto end;
630  }
631 
632  retval = 1;
633 end:
634  if (p != NULL)
635  PoolFree(p);
636  return retval;
637 }
638 
639 /** \test pool with unlimited size */
640 static int PoolTestInit07 (void)
641 {
642  int retval = 0;
643  void *data = NULL;
644  void *data2 = NULL;
645 
646  Pool *p = PoolInit(0,1,10,PoolTestAlloc,NULL,NULL,PoolTestFree, NULL);
647  if (p == NULL)
648  goto end;
649 
650  if (p->max_buckets != 0) {
651  printf("p->max_buckets 0 != %" PRIu32 ": ", p->max_buckets);
652  retval = 0;
653  goto end;
654  }
655 
656  if (p->allocated != 1) {
657  printf("p->allocated 1 != %" PRIu32 ": ", p->allocated);
658  retval = 0;
659  goto end;
660  }
661 
662  data = PoolGet(p);
663  if (data == NULL) {
664  printf("PoolGet returned NULL: ");
665  retval = 0;
666  goto end;
667  }
668 
669  if (p->allocated != 1) {
670  printf("(2) p->allocated 1 != %" PRIu32 ": ", p->allocated);
671  retval = 0;
672  goto end;
673  }
674 
675  data2 = PoolGet(p);
676  if (data2 == NULL) {
677  printf("PoolGet returned NULL: ");
678  retval = 0;
679  goto end;
680  }
681 
682  if (p->allocated != 2) {
683  printf("(3) p->allocated 2 != %" PRIu32 ": ", p->allocated);
684  retval = 0;
685  goto end;
686  }
687 
688  PoolReturn(p,data);
689  data = NULL;
690 
691  if (p->allocated != 2) {
692  printf("(4) p->allocated 2 != %" PRIu32 ": ", p->allocated);
693  retval = 0;
694  goto end;
695  }
696 
697  if (p->alloc_stack_size != 1) {
698  printf("p->alloc_stack_size 1 != %" PRIu32 ": ", p->alloc_stack_size);
699  retval = 0;
700  goto end;
701  }
702 
703  PoolReturn(p,data2);
704  data2 = NULL;
705 
706  if (p->allocated != 1) {
707  printf("(5) p->allocated 1 != %" PRIu32 ": ", p->allocated);
708  retval = 0;
709  goto end;
710  }
711 
712  retval = 1;
713 end:
714  if (p != NULL)
715  PoolFree(p);
716  return retval;
717 }
718 #endif /* UNITTESTS */
719 
721 {
722 #ifdef UNITTESTS
723  UtRegisterTest("PoolTestInit01", PoolTestInit01);
724  UtRegisterTest("PoolTestInit02", PoolTestInit02);
725  UtRegisterTest("PoolTestInit03", PoolTestInit03);
726  UtRegisterTest("PoolTestInit04", PoolTestInit04);
727  UtRegisterTest("PoolTestInit05", PoolTestInit05);
728  UtRegisterTest("PoolTestInit06", PoolTestInit06);
729  UtRegisterTest("PoolTestInit07", PoolTestInit07);
730 
732 #endif /* UNITTESTS */
733 }
734 
735 
736 /**
737  * @}
738  */
len
uint8_t len
Definition: app-layer-dnp3.h:2
Pool_::pb_buffer
PoolBucket * pb_buffer
Definition: util-pool.h:58
SC_ERR_POOL_INIT
@ SC_ERR_POOL_INIT
Definition: util-error.h:96
Pool_::Free
void(* Free)(void *)
Definition: util-pool.h:64
Pool_::Init
int(* Init)(void *, void *)
Definition: util-pool.h:61
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
POOL_BUCKET_PREALLOCATED
#define POOL_BUCKET_PREALLOCATED
Definition: util-pool.h:33
util-pool-thread.h
PoolRegisterTests
void PoolRegisterTests(void)
Definition: util-pool.c:720
PoolPrintSaturation
void PoolPrintSaturation(Pool *p)
Definition: util-pool.c:373
Pool_::alloc_stack
PoolBucket * alloc_stack
Definition: util-pool.h:51
Pool_
Definition: util-pool.h:43
Pool_::Cleanup
void(* Cleanup)(void *)
Definition: util-pool.h:63
util-unittest.h
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
util-debug.h
Pool_::empty_stack_size
uint32_t empty_stack_size
Definition: util-pool.h:54
PoolBucket_::next
struct PoolBucket_ * next
Definition: util-pool.h:39
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
Pool_::outstanding
uint32_t outstanding
Definition: util-pool.h:67
PoolBucket_::data
void * data
Definition: util-pool.h:37
SCReturn
#define SCReturn
Definition: util-debug.h:302
PoolFree
void PoolFree(Pool *p)
Definition: util-pool.c:220
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:316
PoolBucket_
Definition: util-pool.h:36
PoolReturn
void PoolReturn(Pool *p, void *data)
Definition: util-pool.c:333
Pool_::max_buckets
uint32_t max_buckets
Definition: util-pool.h:44
PoolThreadRegisterTests
void PoolThreadRegisterTests(void)
Definition: util-pool-thread.c:375
suricata-common.h
Pool_::Alloc
void *(* Alloc)(void)
Definition: util-pool.h:60
Pool_::preallocated
uint32_t preallocated
Definition: util-pool.h:45
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
Pool_::allocated
uint32_t allocated
Definition: util-pool.h:46
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
str
#define str(s)
Definition: suricata-common.h:272
PoolGet
void * PoolGet(Pool *p)
Definition: util-pool.c:275
Pool_::data_buffer_size
int data_buffer_size
Definition: util-pool.h:56
Pool_::empty_stack
PoolBucket * empty_stack
Definition: util-pool.h:53
SCFree
#define SCFree(p)
Definition: util-mem.h:61
PoolBucket_::flags
uint8_t flags
Definition: util-pool.h:38
Pool_::elt_size
uint32_t elt_size
Definition: util-pool.h:66
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
util-pool.h
PoolInit
Pool * PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void *(*Alloc)(void), int(*Init)(void *, void *), void *InitData, void(*Cleanup)(void *), void(*Free)(void *))
Init a Pool.
Definition: util-pool.c:84
Pool_::InitData
void * InitData
Definition: util-pool.h:62
Pool_::alloc_stack_size
uint32_t alloc_stack_size
Definition: util-pool.h:49
Pool_::data_buffer
void * data_buffer
Definition: util-pool.h:57
PoolPrint
void PoolPrint(Pool *p)
Definition: util-pool.c:268