From 769c61e71645b8e68c6d8a34afd0de88d4496efa Mon Sep 17 00:00:00 2001 From: Istvan Haller Date: Mon, 23 Aug 2021 20:08:27 +0100 Subject: [PATCH] Moved SharedStateHandle to Pool class instead of methods since all of them use it --- src/mem/globalalloc.h | 59 +++++++++++++++++++++++++------------------ src/mem/localalloc.h | 5 ++-- src/mem/pool.h | 10 +++----- src/mem/pooled.h | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/mem/globalalloc.h b/src/mem/globalalloc.h index cc4ecd5..6f5aaad 100644 --- a/src/mem/globalalloc.h +++ b/src/mem/globalalloc.h @@ -11,8 +11,8 @@ namespace snmalloc static_assert( SharedStateHandle::Options.CoreAllocIsPoolAllocated, "Global statistics are available only for pool-allocated configurations"); - auto* alloc = Pool>::template iterate< - SharedStateHandle>(); + auto* alloc = + Pool, SharedStateHandle>::iterate(); while (alloc != nullptr) { @@ -20,8 +20,9 @@ namespace snmalloc if (a != nullptr) stats.add(*a); stats.add(alloc->stats()); - alloc = Pool>::template iterate< - SharedStateHandle>(alloc); + alloc = + Pool, SharedStateHandle>::iterate( + alloc); } } @@ -32,16 +33,17 @@ namespace snmalloc static_assert( SharedStateHandle::Options.CoreAllocIsPoolAllocated, "Global statistics are available only for pool-allocated configurations"); - auto alloc = Pool>::template iterate< - SharedStateHandle>(); + auto alloc = + Pool, SharedStateHandle>::iterate(); while (alloc != nullptr) { auto stats = alloc->stats(); if (stats != nullptr) stats->template print(o, dumpid, alloc->id()); - alloc = Pool>::template iterate< - SharedStateHandle>(alloc); + alloc = + Pool, SharedStateHandle>::iterate( + alloc); } } #else @@ -64,7 +66,8 @@ namespace snmalloc // allocators that are not currently in use by any thread. // One atomic operation to extract the stack, another to restore it. // Handling the message queue for each stack is non-atomic. - auto* first = Pool>::extract(); + auto* first = + Pool, SharedStateHandle>::extract(); auto* alloc = first; decltype(alloc) last; @@ -74,10 +77,13 @@ namespace snmalloc { alloc->flush(); last = alloc; - alloc = Pool>::extract(alloc); + alloc = + Pool, SharedStateHandle>::extract( + alloc); } - Pool>::restore(first, last); + Pool, SharedStateHandle>::restore( + first, last); } #endif } @@ -96,8 +102,8 @@ namespace snmalloc "Global status is available only for pool-allocated configurations"); // This is a debugging function. It checks that all memory from all // allocators has been freed. - auto* alloc = Pool>::template iterate< - SharedStateHandle>(); + auto* alloc = + Pool, SharedStateHandle>::iterate(); # ifdef SNMALLOC_TRACING std::cout << "debug check empty: first " << alloc << std::endl; @@ -111,8 +117,8 @@ namespace snmalloc std::cout << "debug_check_empty: Check all allocators!" << std::endl; # endif done = true; - alloc = Pool>::template iterate< - SharedStateHandle>(); + alloc = + Pool, SharedStateHandle>::iterate(); okay = true; while (alloc != nullptr) @@ -134,8 +140,9 @@ namespace snmalloc # ifdef SNMALLOC_TRACING std::cout << "debug check empty: okay = " << okay << std::endl; # endif - alloc = Pool>::template iterate< - SharedStateHandle>(alloc); + alloc = + Pool, SharedStateHandle>::iterate( + alloc); } } @@ -148,13 +155,14 @@ namespace snmalloc // Redo check so abort is on allocator with allocation left. if (!okay) { - alloc = Pool>::template iterate< - SharedStateHandle>(); + alloc = + Pool, SharedStateHandle>::iterate(); while (alloc != nullptr) { alloc->debug_is_empty(nullptr); - alloc = Pool>::template iterate< - SharedStateHandle>(alloc); + alloc = + Pool, SharedStateHandle>::iterate( + alloc); } } #else @@ -168,8 +176,8 @@ namespace snmalloc static_assert( SharedStateHandle::Options.CoreAllocIsPoolAllocated, "Global status is available only for pool-allocated configurations"); - auto alloc = Pool>::template iterate< - SharedStateHandle>(); + auto alloc = + Pool, SharedStateHandle>::iterate(); while (alloc != nullptr) { if (alloc->debug_is_in_use()) @@ -180,8 +188,9 @@ namespace snmalloc } count--; } - alloc = Pool>::template iterate< - SharedStateHandle>(alloc); + alloc = + Pool, SharedStateHandle>::iterate( + alloc); if (count != 0) { diff --git a/src/mem/localalloc.h b/src/mem/localalloc.h index 7b1c912..96c1e56 100644 --- a/src/mem/localalloc.h +++ b/src/mem/localalloc.h @@ -380,8 +380,7 @@ namespace snmalloc // Initialise the global allocator structures ensure_init(); // Grab an allocator for this thread. - init(Pool::template acquire( - &(this->local_cache))); + init(Pool::acquire(&(this->local_cache))); } // Return all state in the fast allocator and release the underlying @@ -403,7 +402,7 @@ namespace snmalloc // Return underlying allocator to the system. if constexpr (SharedStateHandle::Options.CoreAllocOwnsLocalState) { - Pool::template release(core_alloc); + Pool::release(core_alloc); } // Set up thread local allocator to look like diff --git a/src/mem/pool.h b/src/mem/pool.h index 990c849..184abca 100644 --- a/src/mem/pool.h +++ b/src/mem/pool.h @@ -21,7 +21,7 @@ namespace snmalloc template class PoolState { - template + template friend class Pool; private: @@ -55,11 +55,11 @@ namespace snmalloc } }; - template + template class Pool { public: - template + template static T* acquire(Args&&... args) { PoolState& pool = SharedStateHandle::pool(); @@ -93,7 +93,6 @@ namespace snmalloc * * Do not return objects from `extract`. */ - template static void release(T* p) { // The object's destructor is not run. If the object is "reallocated", it @@ -103,7 +102,6 @@ namespace snmalloc SharedStateHandle::pool().stack.push(p); } - template static T* extract(T* p = nullptr) { // Returns a linked list of all objects in the stack, emptying the stack. @@ -118,7 +116,6 @@ namespace snmalloc * * Do not return objects from `acquire`. */ - template static void restore(T* first, T* last) { // Pushes a linked list of objects onto the stack. Use to put a linked @@ -126,7 +123,6 @@ namespace snmalloc SharedStateHandle::pool().stack.push(first, last); } - template static T* iterate(T* p = nullptr) { if (p == nullptr) diff --git a/src/mem/pooled.h b/src/mem/pooled.h index 93daad9..657ea2d 100644 --- a/src/mem/pooled.h +++ b/src/mem/pooled.h @@ -8,7 +8,7 @@ namespace snmalloc class Pooled { private: - template + template friend class Pool; template friend class MPMCStack;