From 7ce1ebe0d3a91c1b78c50aacea16f3faacb29435 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 25 Oct 2018 11:44:15 +0200 Subject: [PATCH] pool: small code cleanups --- src/util-pool.c | 15 ++++++++------- src/util-pool.h | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/util-pool.c b/src/util-pool.c index 3d411298b8..3b5792e798 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -81,7 +81,9 @@ static int PoolDataPreAllocated(Pool *p, void *data) * \param Free free func * \retval the allocated Pool */ -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 *)) +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 *)) { Pool *p = NULL; @@ -129,8 +131,8 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; } - p->pb_buffer = pb; memset(pb, 0, size * sizeof(PoolBucket)); + p->pb_buffer = pb; for (u32 = 0; u32 < size; u32++) { /* populate pool */ pb->next = p->empty_stack; @@ -139,9 +141,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * p->empty_stack_size++; pb++; } - } - if (size > 0) { p->data_buffer = SCCalloc(prealloc_size, elt_size); /* FIXME better goto */ if (p->data_buffer == NULL) { @@ -157,7 +157,6 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; } - memset(pb, 0, sizeof(PoolBucket)); if (p->Alloc) { @@ -221,7 +220,6 @@ error: return NULL; } - void PoolFree(Pool *p) { if (p == NULL) @@ -314,10 +312,11 @@ void *PoolGet(Pool *p) } p->allocated++; - p->outstanding++; +#ifdef DEBUG if (p->outstanding > p->max_outstanding) p->max_outstanding = p->outstanding; +#endif } SCReturnPtr(pitem, "void"); @@ -329,8 +328,10 @@ void *PoolGet(Pool *p) void *ptr = pb->data; pb->data = NULL; p->outstanding++; +#ifdef DEBUG if (p->outstanding > p->max_outstanding) p->max_outstanding = p->outstanding; +#endif SCReturnPtr(ptr,"void"); } diff --git a/src/util-pool.h b/src/util-pool.h index 5e566893c8..cb82ff6da0 100644 --- a/src/util-pool.h +++ b/src/util-pool.h @@ -66,7 +66,9 @@ typedef struct Pool_ { uint32_t elt_size; uint32_t outstanding; /**< counter of data items 'in use'. Pretty much * the diff between PoolGet and PoolReturn */ +#ifdef DEBUG uint32_t max_outstanding; /**< max value of outstanding we saw */ +#endif } Pool; /* prototypes */