45 uint32_t elt_size,
void *(*Alloc)(
void),
int (*Init)(
void *,
void *),
46 void *InitData,
void (*Cleanup)(
void *),
void (*Free)(
void *))
65 if (pt->
array == NULL) {
72 for (
int i = 0; i < threads; i++) {
80 e->
pool =
PoolInit(size, prealloc_size, elt_size, Alloc, Init, InitData, Cleanup, Free);
82 if (e->
pool == NULL) {
100 if (pt == NULL || pt->
array == NULL || pt->
size == 0) {
105 size_t newsize = pt->
size + 1;
106 SCLogDebug(
"newsize %"PRIuMAX, (uintmax_t)newsize);
120 memset(&settings, 0x0,
sizeof(settings));
133 e = &pt->
array[newsize - 1];
134 memset(e, 0x00,
sizeof(*e));
141 if (e->
pool == NULL) {
146 return (
int)(newsize - 1);
153 return (
int)pt->
size;
161 if (pt->
array != NULL) {
162 for (
int i = 0; i < (int)pt->
size; i++) {
178 if (pt == NULL ||
id >= pt->
size)
197 if (pt == NULL || *
id >= pt->
size)
235static void *PoolThreadTestAlloc(
void)
242int PoolThreadTestInit(
void *data,
void *allocdata)
247 memset(data,0x00,
sizeof(allocdata));
249 pdata->
abc = *(
int *)allocdata;
254void PoolThreadTestFree(
void *data)
258static int PoolThreadTestInit01(
void)
261 10, 5, 10, PoolThreadTestAlloc,
262 NULL, NULL, NULL, NULL);
268static int PoolThreadTestInit02(
void)
274 PoolThreadTestAlloc, PoolThreadTestInit,
275 &i, PoolThreadTestFree, NULL);
281static int PoolThreadTestGet01(
void)
284 10, 5, 10, PoolThreadTestAlloc,
285 NULL, NULL, NULL, NULL);
298static int PoolThreadTestGet02(
void)
303 10, 5, 10, PoolThreadTestAlloc,
304 PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
319static int PoolThreadTestReturn01(
void)
324 10, 5, 10, PoolThreadTestAlloc,
325 PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
346static int PoolThreadTestGrow01(
void)
349 10, 5, 10, PoolThreadTestAlloc,
350 NULL, NULL, NULL, NULL);
358static int PoolThreadTestGrow02(
void)
363 10, 5, 10, PoolThreadTestAlloc,
364 PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
372static int PoolThreadTestGrow03(
void)
377 10, 5, 10, PoolThreadTestAlloc,
378 PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
void PoolThreadUnlock(PoolThread *pt, PoolThreadId id)
void PoolThreadFree(PoolThread *pt)
destroy the thread pool
int PoolThreadExpand(PoolThread *pt)
expand pool by one for a new thread
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.
void PoolReturn(Pool *p, void *data)
void PoolThreadRegisterTests(void)
void * PoolThreadGetById(PoolThread *pt, uint16_t id)
get data from thread pool by thread id
void PoolThreadReturn(PoolThread *pt, void *data)
return data to thread pool
int PoolThreadSize(PoolThread *pt)
get size of PoolThread (number of 'threads', so array elements)
void PoolThreadReturnRaw(PoolThread *pt, PoolThreadId id, void *data)
void PoolThreadLock(PoolThread *pt, PoolThreadId id)
PoolThread * PoolThreadInit(int threads, 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 *))
per thread Pool, initialization function
PoolThreadElement * array
int(* Init)(void *, void *)
#define SCMutexUnlock(mut)
#define SCMutexInit(mut, mutattrs)
#define SCLogError(...)
Macro used to log ERROR messages.
thread_local SCError sc_errno
#define SCRealloc(ptr, sz)
#define DEBUG_VALIDATE_BUG_ON(exp)