From 62fa72c0e168f73e7caaf4a772877fe505e87759 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 Oct 2016 12:03:28 -0400 Subject: [PATCH] mempool: force per-type factories to register with the pool We want these to get their debug flag adjusted when it is turned on and off. (In contrast, we accept that STL containers will only be debugged if mempool debug was on when they are constructed.) Signed-off-by: Sage Weil --- src/include/mempool.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/include/mempool.h b/src/include/mempool.h index b69c09d5435..9988b5b3f4a 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -272,19 +272,19 @@ public: typedef pool_allocator other; }; - void init() { + void init(bool force_register) { pool = &get_pool(pool_ix); - if (pool) { + if (pool->debug || force_register) { type = pool->get_type(typeid(T), sizeof(T)); } } - pool_allocator() { - init(); + pool_allocator(bool force_register=false) { + init(force_register); } template pool_allocator(const pool_allocator&) { - init(); + init(false); } T* allocate(size_t n, void *p = nullptr) { @@ -393,7 +393,8 @@ DEFINE_MEMORY_POOLS_HELPER(P) // Use this for any type that is contained by a container (unless it // is a class you defined; see below). #define MEMPOOL_DEFINE_FACTORY(obj, factoryname, pool) \ - pool::pool_allocator _factory_##pool##factoryname##_alloc = {}; + pool::pool_allocator \ + _factory_##pool##factoryname##_alloc = {true}; // Use this for each class that belongs to a mempool. For example, // -- 2.39.5