suricata
|
Pool are an effective way to maintain a set of ready to use structures. More...
Files | |
file | util-pool-thread.c |
file | util-pool-thread.h |
file | util-pool.c |
file | util-pool.h |
Data Structures | |
struct | PoolThreadTestData |
Functions | |
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 More... | |
int | PoolThreadExpand (PoolThread *pt) |
expand pool by one for a new thread More... | |
int | PoolThreadSize (PoolThread *pt) |
get size of PoolThread (number of 'threads', so array elements) More... | |
void | PoolThreadFree (PoolThread *pt) |
destroy the thread pool More... | |
void * | PoolThreadGetById (PoolThread *pt, uint16_t id) |
get data from thread pool by thread id More... | |
void | PoolThreadReturn (PoolThread *pt, void *data) |
return data to thread pool More... | |
void | PoolThreadLock (PoolThread *pt, PoolThreadId id) |
void | PoolThreadReturnRaw (PoolThread *pt, PoolThreadId id, void *data) |
void | PoolThreadUnlock (PoolThread *pt, PoolThreadId id) |
void | PoolThreadRegisterTests (void) |
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. More... | |
void | PoolFree (Pool *p) |
void * | PoolGet (Pool *p) |
void | PoolReturn (Pool *p, void *data) |
void | PoolRegisterTests (void) |
Pool are an effective way to maintain a set of ready to use structures.
To create a Pool, you need to use PoolInit(). You can get an item from the Pool by using PoolGet(). When you're done with it call PoolReturn(). To destroy the Pool, call PoolFree(), it will free all used memory.
void PoolFree | ( | Pool * | p | ) |
Definition at line 223 of file util-pool.c.
References Pool_::alloc_stack, Pool_::Cleanup, PoolBucket_::data, and PoolBucket_::next.
Referenced by PoolThreadFree().
void* PoolGet | ( | Pool * | p | ) |
Definition at line 271 of file util-pool.c.
References Pool_::Alloc, Pool_::alloc_stack, Pool_::alloc_stack_size, Pool_::allocated, PoolBucket_::data, Pool_::elt_size, Pool_::empty_stack, Pool_::empty_stack_size, Pool_::Free, Pool_::Init, Pool_::InitData, Pool_::max_buckets, PoolBucket_::next, Pool_::outstanding, SCEnter, SCFree, SCLogDebug, SCMalloc, and SCReturnPtr.
Referenced by PoolThreadGetById().
Pool* PoolInit | ( | uint32_t | size, |
uint32_t | prealloc_size, | ||
uint32_t | elt_size, | ||
void *(*)(void) | Alloc, | ||
int(*)(void *, void *) | Init, | ||
void * | InitData, | ||
void(*)(void *) | Cleanup, | ||
void(*)(void *) | Free | ||
) |
Init a Pool.
PoolInit() creates a Pool. The Alloc function must only do allocation stuff. The Cleanup function must not try to free the PoolBucket::data. This is done by the Pool management system.
size | |
prealloc_size | |
elt_size | Memory size of an element |
Alloc | An allocation function or NULL to use a standard SCMalloc |
Init | An init function or NULL to use a standard memset to 0 |
InitData | Init data |
Cleanup | a free function or NULL if no special treatment is needed |
Free | free func |
the | allocated Pool |
Definition at line 84 of file util-pool.c.
Referenced by PoolThreadExpand().
void PoolRegisterTests | ( | void | ) |
Definition at line 705 of file util-pool.c.
References UtRegisterTest().
void PoolReturn | ( | Pool * | p, |
void * | data | ||
) |
Definition at line 329 of file util-pool.c.
References Pool_::allocated, Pool_::Cleanup, Pool_::empty_stack, Pool_::outstanding, SCEnter, and SCLogDebug.
Referenced by PoolThreadReturn(), and PoolThreadReturnRaw().
int PoolThreadExpand | ( | PoolThread * | pt | ) |
expand pool by one for a new thread
grow a thread pool by one
-1 | or pool thread id |
Definition at line 97 of file util-pool-thread.c.
References Pool_::Alloc, PoolThread_::array, Pool_::Cleanup, Pool_::elt_size, Pool_::Free, Pool_::Init, Pool_::InitData, PoolThreadElement_::lock, Pool_::max_buckets, PoolThreadElement_::pool, PoolInit(), Pool_::preallocated, SCFree, SCLogDebug, SCLogError, SCMutexInit, SCMutexLock, SCMutexUnlock, SCRealloc, and PoolThread_::size.
void PoolThreadFree | ( | PoolThread * | pt | ) |
destroy the thread pool
pt | thread pool |
Definition at line 155 of file util-pool-thread.c.
References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolFree(), SCFree, SCMutexDestroy, SCMutexLock, SCMutexUnlock, and PoolThread_::size.
void* PoolThreadGetById | ( | PoolThread * | pt, |
uint16_t | id | ||
) |
get data from thread pool by thread id
pt | thread pool |
id | thread id |
ptr | data or NULL |
Definition at line 173 of file util-pool-thread.c.
References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolGet(), SCMutexLock, SCMutexUnlock, and PoolThread_::size.
Referenced by StreamTcpGetSegment().
PoolThread* PoolThreadInit | ( | int | threads, |
uint32_t | size, | ||
uint32_t | prealloc_size, | ||
uint32_t | elt_size, | ||
void *(*)(void) | Alloc, | ||
int(*)(void *, void *) | Init, | ||
void * | InitData, | ||
void(*)(void *) | Cleanup, | ||
void(*)(void *) | Free | ||
) |
per thread Pool, initialization function
initialize a thread pool
thread | number of threads this is for. Can start with 1 and be expanded. Other params are as for PoolInit() |
Definition at line 43 of file util-pool-thread.c.
void PoolThreadLock | ( | PoolThread * | pt, |
PoolThreadId | id | ||
) |
Definition at line 207 of file util-pool-thread.c.
References PoolThread_::array, BUG_ON, PoolThreadElement_::lock, SCMutexLock, and PoolThread_::size.
void PoolThreadRegisterTests | ( | void | ) |
Definition at line 401 of file util-pool-thread.c.
References UtRegisterTest().
void PoolThreadReturn | ( | PoolThread * | pt, |
void * | data | ||
) |
return data to thread pool
pt | thread pool |
data | memory block to return, with PoolThreadReserved as it's first member |
Definition at line 192 of file util-pool-thread.c.
References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolReturn(), SCLogDebug, SCMutexLock, SCMutexUnlock, and PoolThread_::size.
Referenced by StreamTcpThreadCacheReturnSegment(), and StreamTcpThreadCacheReturnSession().
void PoolThreadReturnRaw | ( | PoolThread * | pt, |
PoolThreadId | id, | ||
void * | data | ||
) |
Definition at line 214 of file util-pool-thread.c.
References PoolThread_::array, BUG_ON, PoolThreadElement_::pool, PoolReturn(), and PoolThread_::size.
int PoolThreadSize | ( | PoolThread * | pt | ) |
get size of PoolThread (number of 'threads', so array elements)
pt | thread pool |
size | or -1 on error |
Definition at line 148 of file util-pool-thread.c.
References PoolThread_::size.
void PoolThreadUnlock | ( | PoolThread * | pt, |
PoolThreadId | id | ||
) |
Definition at line 221 of file util-pool-thread.c.
References PoolThread_::array, BUG_ON, PoolThreadElement_::lock, SCMutexUnlock, and PoolThread_::size.