From bfeaed64120d4bb443bc6dfed4b2450533f3048e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 Oct 2016 12:01:52 -0400 Subject: [PATCH] mempool: simplify initialization Assume that the array will be zeroed when the process starts, and avoid the possibility that it will be zeroed *again* when the ctors run for this link module (potentially clobbering values that have been filled in by other ctors who ran earlier than ours). Signed-off-by: Sage Weil --- src/global/mempool.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/global/mempool.cc b/src/global/mempool.cc index 209cee0d3e7e6..413353d4a0fc1 100644 --- a/src/global/mempool.cc +++ b/src/global/mempool.cc @@ -21,11 +21,11 @@ static bool debug_mode = false; // -------------------------------------------------------------- -static mempool::pool_t *pools[mempool::num_pools] = { -#define P(x) nullptr, - DEFINE_MEMORY_POOLS_HELPER(P) -#undef P -}; +// We rely on this array of pointers being zeroed when the process +// starts *before* the ctors from *any* linked modules are executed. +// That way, regardless of link order, pool_t's are allocated and +// instantiated on demand. +static mempool::pool_t *pools[mempool::num_pools]; mempool::pool_t& mempool::get_pool(mempool::pool_index_t ix) { -- 2.39.5