|
|
|
|
@ -42,7 +42,7 @@
|
|
|
|
|
* Other params are as for PoolInit()
|
|
|
|
|
*/
|
|
|
|
|
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 *(*Alloc)(void), int (*Init)(void *, void *), void (*Cleanup)(void *))
|
|
|
|
|
{
|
|
|
|
|
sc_errno = SC_OK;
|
|
|
|
|
|
|
|
|
|
@ -76,7 +76,7 @@ PoolThread *PoolThreadInit(int threads, uint32_t size, uint32_t prealloc_size, u
|
|
|
|
|
// SCLogDebug("size %u prealloc_size %u elt_size %u Alloc %p Init %p InitData %p Cleanup %p Free %p",
|
|
|
|
|
// size, prealloc_size, elt_size,
|
|
|
|
|
// Alloc, Init, InitData, Cleanup, Free);
|
|
|
|
|
e->pool = PoolInit(size, prealloc_size, elt_size, Alloc, Init, InitData, Cleanup);
|
|
|
|
|
e->pool = PoolInit(size, prealloc_size, elt_size, Alloc, Init, NULL, Cleanup);
|
|
|
|
|
SCMutexUnlock(&e->lock);
|
|
|
|
|
if (e->pool == NULL) {
|
|
|
|
|
SCLogDebug("error");
|
|
|
|
|
@ -241,9 +241,7 @@ int PoolThreadTestInit(void *data, void *allocdata)
|
|
|
|
|
if (!data)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
memset(data,0x00,sizeof(allocdata));
|
|
|
|
|
struct PoolThreadTestData *pdata = data;
|
|
|
|
|
pdata->abc = *(int *)allocdata;
|
|
|
|
|
memset(data, 0x00, sizeof(allocdata));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -255,7 +253,7 @@ void PoolThreadTestFree(void *data)
|
|
|
|
|
static int PoolThreadTestInit01(void)
|
|
|
|
|
{
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL);
|
|
|
|
|
FAIL_IF(pt == NULL);
|
|
|
|
|
PoolThreadFree(pt);
|
|
|
|
|
PASS;
|
|
|
|
|
@ -263,10 +261,8 @@ static int PoolThreadTestInit01(void)
|
|
|
|
|
|
|
|
|
|
static int PoolThreadTestInit02(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 123;
|
|
|
|
|
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, PoolThreadTestFree);
|
|
|
|
|
FAIL_IF(pt == NULL);
|
|
|
|
|
PoolThreadFree(pt);
|
|
|
|
|
PASS;
|
|
|
|
|
@ -275,7 +271,7 @@ static int PoolThreadTestInit02(void)
|
|
|
|
|
static int PoolThreadTestGet01(void)
|
|
|
|
|
{
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL);
|
|
|
|
|
FAIL_IF(pt == NULL);
|
|
|
|
|
|
|
|
|
|
void *data = PoolThreadGetById(pt, 3);
|
|
|
|
|
@ -290,10 +286,8 @@ static int PoolThreadTestGet01(void)
|
|
|
|
|
|
|
|
|
|
static int PoolThreadTestGet02(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 123;
|
|
|
|
|
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, PoolThreadTestFree);
|
|
|
|
|
FAIL_IF_NULL(pt);
|
|
|
|
|
|
|
|
|
|
void *data = PoolThreadGetById(pt, 3);
|
|
|
|
|
@ -302,18 +296,14 @@ static int PoolThreadTestGet02(void)
|
|
|
|
|
struct PoolThreadTestData *pdata = data;
|
|
|
|
|
FAIL_IF_NOT (pdata->res == 3);
|
|
|
|
|
|
|
|
|
|
FAIL_IF_NOT (pdata->abc == 123);
|
|
|
|
|
|
|
|
|
|
PoolThreadFree(pt);
|
|
|
|
|
PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int PoolThreadTestReturn01(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 123;
|
|
|
|
|
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, PoolThreadTestFree);
|
|
|
|
|
FAIL_IF_NULL(pt);
|
|
|
|
|
|
|
|
|
|
void *data = PoolThreadGetById(pt, 3);
|
|
|
|
|
@ -322,8 +312,6 @@ static int PoolThreadTestReturn01(void)
|
|
|
|
|
struct PoolThreadTestData *pdata = data;
|
|
|
|
|
FAIL_IF_NOT (pdata->res == 3);
|
|
|
|
|
|
|
|
|
|
FAIL_IF_NOT (pdata->abc == 123);
|
|
|
|
|
|
|
|
|
|
FAIL_IF_NOT (pt->array[3].pool->outstanding == 1);
|
|
|
|
|
|
|
|
|
|
PoolThreadReturn(pt, data);
|
|
|
|
|
@ -337,7 +325,7 @@ static int PoolThreadTestReturn01(void)
|
|
|
|
|
static int PoolThreadTestGrow01(void)
|
|
|
|
|
{
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, NULL, NULL);
|
|
|
|
|
FAIL_IF_NULL(pt);
|
|
|
|
|
FAIL_IF(PoolThreadExpand(pt) < 0);
|
|
|
|
|
|
|
|
|
|
@ -347,10 +335,8 @@ static int PoolThreadTestGrow01(void)
|
|
|
|
|
|
|
|
|
|
static int PoolThreadTestGrow02(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 123;
|
|
|
|
|
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, PoolThreadTestFree);
|
|
|
|
|
FAIL_IF_NULL(pt);
|
|
|
|
|
FAIL_IF(PoolThreadExpand(pt) < 0);
|
|
|
|
|
|
|
|
|
|
@ -360,10 +346,8 @@ static int PoolThreadTestGrow02(void)
|
|
|
|
|
|
|
|
|
|
static int PoolThreadTestGrow03(void)
|
|
|
|
|
{
|
|
|
|
|
int i = 123;
|
|
|
|
|
|
|
|
|
|
PoolThread *pt = PoolThreadInit(4, /* threads */
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree);
|
|
|
|
|
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, PoolThreadTestFree);
|
|
|
|
|
FAIL_IF_NULL(pt);
|
|
|
|
|
FAIL_IF(PoolThreadExpand(pt) < 0);
|
|
|
|
|
|
|
|
|
|
@ -373,8 +357,6 @@ static int PoolThreadTestGrow03(void)
|
|
|
|
|
struct PoolThreadTestData *pdata = data;
|
|
|
|
|
FAIL_IF_NOT(pdata->res == 4);
|
|
|
|
|
|
|
|
|
|
FAIL_IF_NOT(pdata->abc == 123);
|
|
|
|
|
|
|
|
|
|
FAIL_IF_NOT(pt->array[4].pool->outstanding == 1);
|
|
|
|
|
|
|
|
|
|
PoolThreadReturn(pt, data);
|
|
|
|
|
|