return (int)(newsize - 1);
}
-/**
- *
- */
-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 *))
-{
- if (pt == NULL || pt->array == NULL) {
- SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
- return -1;
- }
-
- size_t newsize = pt->size + 1;
- SCLogDebug("newsize %"PRIuMAX, (uintmax_t)newsize);
-
- void *ptmp = SCRealloc(pt->array, (newsize * sizeof(PoolThreadElement)));
- if (ptmp == NULL) {
- SCFree(pt->array);
- pt->array = NULL;
- SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
- return -1;
- }
- pt->array = ptmp;
- pt->size = newsize;
-
- PoolThreadElement *e = &pt->array[newsize - 1];
- memset(e, 0x00, sizeof(*e));
- SCMutexInit(&e->lock, NULL);
- SCMutexLock(&e->lock);
- e->pool = PoolInit(size, prealloc_size, elt_size, Alloc, Init, InitData, Cleanup, Free);
- SCMutexUnlock(&e->lock);
- if (e->pool == NULL) {
- SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
- return -1;
- }
-
- return (int)(newsize - 1);
-}
-
int PoolThreadSize(PoolThread *pt)
{
if (pt == NULL)
if (pt == NULL)
return 0;
- if (PoolThreadGrow(pt,
- 10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL, NULL) < 0) {
+ if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt);
return 0;
}
if (pt == NULL)
return 0;
- if (PoolThreadGrow(pt,
- 10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL) < 0) {
+ if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt);
return 0;
}
if (pt == NULL)
return 0;
- if (PoolThreadGrow(pt,
- 10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL) < 0) {
+ if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt);
return 0;
}
* \retval pt thread pool or NULL on error */
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 *));
-/** \brief grow a thread pool by one
- * \note calls PoolInit so all args but 'pt' are the same
- * \param pt thread pool to grow
- * \retval r id of new entry on succes, -1 on error */
-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 *));
-
/** \brief grow a thread pool by one
* \note copies settings from initial PoolThreadInit() call
* \param pt thread pool to grow