]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add flags to disable auto assert and auto memset
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 15 Dec 2016 22:10:33 +0000 (16:10 -0600)
committerMike Jerris <mike@jerris.com>
Wed, 25 Jan 2017 20:59:36 +0000 (14:59 -0600)
libs/libks/src/include/ks_pool.h
libs/libks/src/ks_pool.c

index efa2677e5128fa7f718c2c3b4fa46d5634db60e0..083d152ac8c67f809fa709511857366fd181b6e5 100644 (file)
@@ -34,8 +34,9 @@ KS_BEGIN_EXTERN_C
 
 typedef enum {
        KS_POOL_FLAG_DEFAULT = 0,
-
        KS_POOL_FLAG_BEST_FIT = (1 << 0),
+       KS_POOL_FLAG_NO_ASSERT = (1 << 1),
+       KS_POOL_FLAG_NO_ZERO = (1 << 2),
 /*
  * Choose a best fit algorithm not first fit.  This takes more CPU
  * time but will result in a tighter heap.
index 2a6750e91d3c656cf554824a32898c0473e8120f..92e2d827fefbcb466cfec01afe6c6c9e1616d019 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 1996 by Gray Watson.
  *
- * This file is part of the ks_mpool package.
+ * This file is part of the ks_pool package.
  *
  * Permission to use, copy, modify, and distribute this software for
  * any purpose and without fee is hereby granted, provided that the
@@ -1465,6 +1465,12 @@ KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *mp_p, const unsigned long byte_si
                mp_p->mp_log_func(mp_p, KS_POOL_FUNC_ALLOC, byte_size, 0, addr, NULL, 0);
        }
 
+       ks_assert(addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT));
+
+       if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ZERO)) {
+               memset(addr, 0, byte_size);
+       }
+
        return addr;
 }
 
@@ -1554,6 +1560,12 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n,
                mp_p->mp_log_func(mp_p, KS_POOL_FUNC_CALLOC, ele_size, ele_n, addr, NULL, 0);
        }
 
+       ks_assert(addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT));
+
+       if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ZERO)) {
+               memset(addr, 0, ele_n * ele_size);
+       }
+
        return addr;
 }
 
@@ -1785,6 +1797,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
 
        ks_mutex_unlock(mp_p->mutex);
 
+       ks_assert(new_addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT));
+
        return new_addr;
 }