suricata
Pool

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(*Cleanup)(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 (const uint32_t size, const uint32_t prealloc_size, const uint32_t elt_size, void *(*Alloc)(void), int(*Init)(void *), void(*Cleanup)(void *))
 Init a Pool. More...
 
void PoolFree (Pool *p)
 
void * PoolGet (Pool *p)
 
void PoolReturn (Pool *p, void *data)
 
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

◆ PoolFree()

void PoolFree ( Pool *  p)

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

References PoolBucket_::data, PoolBucket_::next, and p.

Referenced by PoolThreadFree().

Here is the caller graph for this function:

◆ PoolGet()

void* PoolGet ( Pool *  p)

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

References PoolBucket_::next, p, SCEnter, SCLogDebug, and SCMalloc.

Referenced by PoolThreadGetById().

Here is the caller graph for this function:

◆ PoolInit()

Pool* PoolInit ( const uint32_t  size,
const uint32_t  prealloc_size,
const uint32_t  elt_size,
void *(*)(void)  Alloc,
int(*)(void *)  Init,
void(*)(void *)  Cleanup 
)

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
Cleanupa free function or NULL if no special treatment is needed
Return values
theallocated Pool

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

Referenced by PoolThreadExpand().

Here is the caller graph for this function:

◆ PoolRegisterTests()

void PoolRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

◆ PoolReturn()

void PoolReturn ( Pool *  p,
void *  data 
)

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

References p, SCEnter, and SCLogDebug.

Referenced by PoolThreadReturn(), and PoolThreadReturnRaw().

Here is the caller graph for this function:

◆ PoolThreadExpand()

int PoolThreadExpand ( PoolThread *  pt)

expand pool by one for a new thread

grow a thread pool by one

Return values
-1or pool thread id

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

References Pool_::Alloc, PoolThread_::array, Pool_::Cleanup, Pool_::elt_size, Pool_::Init, PoolThreadElement_::lock, Pool_::max_buckets, PoolThreadElement_::pool, PoolInit(), Pool_::preallocated, SCFree, SCLogDebug, SCLogError, SCMutexInit, SCMutexLock, SCMutexUnlock, SCRealloc, and PoolThread_::size.

Here is the call graph for this function:

◆ PoolThreadFree()

void PoolThreadFree ( PoolThread *  pt)

destroy the thread pool

Note
wrapper around PoolFree()
Parameters
ptthread pool

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

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

Here is the call graph for this function:

◆ PoolThreadGetById()

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 169 of file util-pool-thread.c.

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

Referenced by StreamTcpGetSegment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PoolThreadInit()

PoolThread* PoolThreadInit ( int  threads,
uint32_t  size,
uint32_t  prealloc_size,
uint32_t  elt_size,
void *(*)(void)  Alloc,
int(*)(void *)  Init,
void(*)(void *)  Cleanup 
)

per thread Pool, initialization function

initialize a thread pool

Parameters
threadnumber 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.

◆ PoolThreadLock()

void PoolThreadLock ( PoolThread *  pt,
PoolThreadId  id 
)

◆ PoolThreadRegisterTests()

void PoolThreadRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

◆ PoolThreadReturn()

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 188 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PoolThreadReturnRaw()

void PoolThreadReturnRaw ( PoolThread *  pt,
PoolThreadId  id,
void *  data 
)

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

References PoolThread_::array, DEBUG_VALIDATE_BUG_ON, PoolThreadElement_::pool, PoolReturn(), and PoolThread_::size.

Here is the call graph for this function:

◆ PoolThreadSize()

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 144 of file util-pool-thread.c.

References PoolThread_::size.

◆ PoolThreadUnlock()

void PoolThreadUnlock ( PoolThread *  pt,
PoolThreadId  id 
)