]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
pool: small code cleanups
authorVictor Julien <victor@inliniac.net>
Thu, 25 Oct 2018 09:44:15 +0000 (11:44 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 30 Oct 2018 09:21:34 +0000 (10:21 +0100)
src/util-pool.c
src/util-pool.h

index 3d411298b8f3f6d507ea438520cd606fa75b4510..3b5792e798550d7955ee64723cbe14333ff21298 100644 (file)
@@ -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");
 }
 
index 5e566893c8880fefbf29e7c9aacc7d2aa32760d7..cb82ff6da0763899e7af95ac480cb217f4842291 100644 (file)
@@ -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 */