From 8d3622f93953c254087065d070be96b8b53dff17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 9 Oct 2018 15:53:35 +0200 Subject: Move use_pool() to mempool.c and rename to mempool_enabled() The only user is in hashmap.c, but it's a mempool thing. (cherry picked from commit 7c48ea02800782651b7da373c6165abb052f1382) --- src/basic/env-util.h | 1 + src/basic/hashmap.c | 15 +-------------- src/basic/mempool.c | 16 ++++++++++++++-- src/basic/mempool.h | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/basic') diff --git a/src/basic/env-util.h b/src/basic/env-util.h index da76e60ca..486056a10 100644 --- a/src/basic/env-util.h +++ b/src/basic/env-util.h @@ -4,6 +4,7 @@ #include #include #include +//#include #include "macro.h" diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index d89bd83c8..2bee671da 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -6,7 +6,6 @@ #include #include "alloc-util.h" -//#include "env-util.h" #include "fileio.h" //#include "hashmap.h" #include "macro.h" @@ -767,24 +766,12 @@ static void reset_direct_storage(HashmapBase *h) { memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets); } -static bool use_pool(void) { - static int b = -1; - - if (!is_main_thread()) - return false; - - if (b < 0) - b = getenv_bool("SYSTEMD_MEMPOOL") != 0; - - return b; -} - static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) { HashmapBase *h; const struct hashmap_type_info *hi = &hashmap_type_info[type]; bool up; - up = use_pool(); + up = mempool_enabled(); h = up ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size); if (!h) diff --git a/src/basic/mempool.c b/src/basic/mempool.c index a5ec8a102..aaf46ceda 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -3,8 +3,10 @@ #include #include +//#include "env-util.h" #include "macro.h" #include "mempool.h" +//#include "process-util.h" #include "util.h" struct pool { @@ -70,8 +72,19 @@ void mempool_free_tile(struct mempool *mp, void *p) { mp->freelist = p; } -#if VALGRIND +bool mempool_enabled(void) { + static int b = -1; + + if (!is_main_thread()) + return false; + if (b < 0) + b = getenv_bool("SYSTEMD_MEMPOOL") != 0; + + return b; +} + +#if VALGRIND void mempool_drop(struct mempool *mp) { struct pool *p = mp->first_pool; while (p) { @@ -81,5 +94,4 @@ void mempool_drop(struct mempool *mp) { p = n; } } - #endif diff --git a/src/basic/mempool.h b/src/basic/mempool.h index 2a41cb358..e223fc16f 100644 --- a/src/basic/mempool.h +++ b/src/basic/mempool.h @@ -23,6 +23,8 @@ static struct mempool pool_name = { \ .at_least = alloc_at_least, \ } +bool mempool_enabled(void); + #if VALGRIND void mempool_drop(struct mempool *mp); #endif -- cgit v1.2.3