提交 a42ed8f8 authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Mike Jerris

add flags to disable auto assert and auto memset

上级 a0e3c93b
...@@ -34,8 +34,9 @@ KS_BEGIN_EXTERN_C ...@@ -34,8 +34,9 @@ KS_BEGIN_EXTERN_C
typedef enum { typedef enum {
KS_POOL_FLAG_DEFAULT = 0, KS_POOL_FLAG_DEFAULT = 0,
KS_POOL_FLAG_BEST_FIT = (1 << 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 * Choose a best fit algorithm not first fit. This takes more CPU
* time but will result in a tighter heap. * time but will result in a tighter heap.
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 1996 by Gray Watson. * 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 * Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the * 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 ...@@ -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); 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; return addr;
} }
...@@ -1554,6 +1560,12 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n, ...@@ -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); 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; return addr;
} }
...@@ -1785,6 +1797,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi ...@@ -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_mutex_unlock(mp_p->mutex);
ks_assert(new_addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT));
return new_addr; return new_addr;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论