summaryrefslogtreecommitdiffstats
path: root/src/chunk_dss.c
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-02-11 04:22:09 (GMT)
committerJason Evans <je@fb.com>2012-02-11 04:22:09 (GMT)
commit7372b15a31c63ac5cb9ed8aeabc2a0a3c005e8bf (patch)
tree9b0f1156e6aa61f50a01c90b72fdaefeabe414a8 /src/chunk_dss.c
parentb3bd885090230cc28add77c399b4ed440b760ca3 (diff)
downloadjemalloc-7372b15a31c63ac5cb9ed8aeabc2a0a3c005e8bf.zip
jemalloc-7372b15a31c63ac5cb9ed8aeabc2a0a3c005e8bf.tar.gz
jemalloc-7372b15a31c63ac5cb9ed8aeabc2a0a3c005e8bf.tar.bz2
Reduce cpp conditional logic complexity.
Convert configuration-related cpp conditional logic to use static constant variables, e.g.: #ifdef JEMALLOC_DEBUG [...] #endif becomes: if (config_debug) { [...] } The advantage is clearer, more concise code. The main disadvantage is that data structures no longer have conditionally defined fields, so they pay the cost of all fields regardless of whether they are used. In practice, this is only a minor concern; config_stats will go away in an upcoming change, and config_prof is the only other major feature that depends on more than a few special-purpose fields.
Diffstat (limited to 'src/chunk_dss.c')
-rw-r--r--src/chunk_dss.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/chunk_dss.c b/src/chunk_dss.c
index 5c0e290..c25baea 100644
--- a/src/chunk_dss.c
+++ b/src/chunk_dss.c
@@ -1,6 +1,5 @@
#define JEMALLOC_CHUNK_DSS_C_
#include "jemalloc/internal/jemalloc_internal.h"
-#ifdef JEMALLOC_DSS
/******************************************************************************/
/* Data. */
@@ -35,6 +34,8 @@ chunk_recycle_dss(size_t size, bool *zero)
{
extent_node_t *node, key;
+ cassert(config_dss);
+
key.addr = NULL;
key.size = size;
malloc_mutex_lock(&dss_mtx);
@@ -74,6 +75,8 @@ chunk_alloc_dss(size_t size, bool *zero)
{
void *ret;
+ cassert(config_dss);
+
ret = chunk_recycle_dss(size, zero);
if (ret != NULL)
return (ret);
@@ -131,6 +134,8 @@ chunk_dealloc_dss_record(void *chunk, size_t size)
{
extent_node_t *xnode, *node, *prev, key;
+ cassert(config_dss);
+
xnode = NULL;
while (true) {
key.addr = (void *)((uintptr_t)chunk + size);
@@ -204,6 +209,8 @@ chunk_in_dss(void *chunk)
{
bool ret;
+ cassert(config_dss);
+
malloc_mutex_lock(&dss_mtx);
if ((uintptr_t)chunk >= (uintptr_t)dss_base
&& (uintptr_t)chunk < (uintptr_t)dss_max)
@@ -220,6 +227,8 @@ chunk_dealloc_dss(void *chunk, size_t size)
{
bool ret;
+ cassert(config_dss);
+
malloc_mutex_lock(&dss_mtx);
if ((uintptr_t)chunk >= (uintptr_t)dss_base
&& (uintptr_t)chunk < (uintptr_t)dss_max) {
@@ -269,6 +278,8 @@ bool
chunk_dss_boot(void)
{
+ cassert(config_dss);
+
if (malloc_mutex_init(&dss_mtx))
return (true);
dss_base = sbrk(0);
@@ -281,4 +292,3 @@ chunk_dss_boot(void)
}
/******************************************************************************/
-#endif /* JEMALLOC_DSS */