suricata
Pool

Files

file  util-pool-thread.c
 
file  util-pool-thread.h
 
file  util-pool.c
 
file  util-pool.h
 

Data Structures

struct  PoolThreadTestData
 

Functions

PoolThreadPoolThreadInit (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 *))
 initialize a thread pool More...
 
int PoolThreadGrow (PoolThread *pt, 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 *))
 grow a thread pool by one 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 PoolThreadRegisterTests (void)
 
PoolPoolInit (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 PoolPrint (Pool *p)
 
void * PoolGet (Pool *p)
 
void PoolReturn (Pool *p, void *data)
 
void PoolPrintSaturation (Pool *p)
 
void PoolRegisterTests (void)
 

Detailed Description

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.

Function Documentation

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.

Parameters
size
prealloc_size
elt_sizeMemory size of an element
AllocAn allocation function or NULL to use a standard SCMalloc
InitAn init function or NULL to use a standard memset to 0
InitDataInit data
Cleanupa free function or NULL if no special treatment is needed
Freefree func
Return values
theallocated Pool

Definition at line 84 of file util-pool.c.

References Pool_::Alloc, Pool_::alloc_stack, Pool_::alloc_stack_size, Pool_::allocated, Pool_::Cleanup, PoolBucket_::data, Pool_::data_buffer, Pool_::data_buffer_size, Pool_::elt_size, Pool_::empty_stack, Pool_::empty_stack_size, PoolBucket_::flags, Pool_::Free, Pool_::Init, Pool_::InitData, Pool_::max_buckets, PoolBucket_::next, Pool_::pb_buffer, POOL_BUCKET_PREALLOCATED, PoolFree(), Pool_::preallocated, SC_ERR_POOL_INIT, SCCalloc, SCFree, SCLogError, SCMalloc, and unlikely.

Referenced by DefragTrackerFreeFrags(), PoolPrintSaturation(), PoolThreadGrow(), and PoolThreadInit().

Here is the call graph for this function:

Here is the caller graph for this function:

void PoolPrint ( Pool p)

Definition at line 272 of file util-pool.c.

References Pool_::alloc_stack_size, and Pool_::empty_stack_size.

void PoolRegisterTests ( void  )

Definition at line 721 of file util-pool.c.

References PoolThreadRegisterTests(), and UtRegisterTest().

Here is the call graph for this function:

void PoolThreadFree ( PoolThread pt)

destroy the thread pool

Note
wrapper around PoolFree()
Parameters
ptthread pool

Definition at line 133 of file util-pool-thread.c.

References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolFree(), SCFree, SCMutexDestroy, SCMutexLock, SCMutexUnlock, and PoolThread_::size.

Referenced by PoolThreadInit(), StreamTcpFreeConfig(), and StreamTcpReassembleFree().

Here is the call graph for this function:

Here is the caller graph for this function:

void* PoolThreadGetById ( PoolThread pt,
uint16_t  id 
)

get data from thread pool by thread id

Note
wrapper around PoolGet()
Parameters
ptthread pool
idthread id
Return values
ptrdata or NULL

Definition at line 153 of file util-pool-thread.c.

References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolGet(), SCMutexLock, SCMutexUnlock, and PoolThread_::size.

Referenced by StreamTcpFreeConfig(), and StreamTcpGetSegment().

Here is the call graph for this function:

Here is the caller graph for this function:

int PoolThreadGrow ( PoolThread pt,
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 
)

grow a thread pool by one

Note
calls PoolInit so all args but 'pt' are the same
Parameters
ptthread pool to grow
Return values
rid of new entry on succes, -1 on error

Definition at line 88 of file util-pool-thread.c.

References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolInit(), SC_ERR_POOL_INIT, SCFree, SCLogDebug, SCLogError, SCMutexInit, SCMutexLock, SCMutexUnlock, SCRealloc, and PoolThread_::size.

Referenced by StreamTcpReassembleInitThreadCtx(), and StreamTcpThreadInit().

Here is the call graph for this function:

Here is the caller graph for this function:

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 
)

initialize a thread pool

Note
same as PoolInit() except for "threads"
Parameters
threadsnumber of threads to use this
Return values
ptthread pool or NULL on error

Definition at line 38 of file util-pool-thread.c.

References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolInit(), PoolThreadFree(), SCLogDebug, SCMalloc, SCMutexInit, SCMutexLock, SCMutexUnlock, PoolThread_::size, and unlikely.

Referenced by StreamTcpInitConfig(), StreamTcpReassembleInitThreadCtx(), and StreamTcpThreadInit().

Here is the call graph for this function:

Here is the caller graph for this function:

void PoolThreadRegisterTests ( void  )

Definition at line 439 of file util-pool-thread.c.

References UtRegisterTest().

Referenced by PoolRegisterTests().

Here is the call graph for this function:

Here is the caller graph for this function:

void PoolThreadReturn ( PoolThread pt,
void *  data 
)

return data to thread pool

Note
wrapper around PoolReturn()
Parameters
ptthread pool
datamemory block to return, with PoolThreadReserved as it's first member

Definition at line 172 of file util-pool-thread.c.

References PoolThread_::array, PoolThreadElement_::lock, PoolThreadElement_::pool, PoolReturn(), SCLogDebug, SCMutexLock, SCMutexUnlock, and PoolThread_::size.

Referenced by StreamTcpSegmentReturntoPool(), and StreamTcpSessionClear().

Here is the call graph for this function:

Here is the caller graph for this function:

int PoolThreadSize ( PoolThread pt)

get size of PoolThread (number of 'threads', so array elements)

Parameters
ptthread pool
Return values
sizeor -1 on error

Definition at line 126 of file util-pool-thread.c.

References PoolThread_::size.

Referenced by StreamTcpReassembleInitThreadCtx(), and StreamTcpThreadInit().

Here is the caller graph for this function: