From 5ed299c053f3febb60f68cadda017ce948bd6ab2 Mon Sep 17 00:00:00 2001 From: Panos Sysk Date: Fri, 6 Sep 2024 19:34:48 -0500 Subject: [PATCH] Use thread-safe cache in thread_local_caching_allocator --- .../thread_local_caching_allocator.hpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp b/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp index f389213a8b53..b1c1ed5e24cc 100644 --- a/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp +++ b/libs/core/allocator_support/include/hpx/allocator_support/thread_local_caching_allocator.hpp @@ -8,11 +8,11 @@ #include #include +#include #include #include #include -#include #include #include @@ -56,6 +56,7 @@ namespace hpx::util { explicit allocated_cache(Allocator const& a) noexcept( noexcept(std::is_nothrow_copy_constructible_v)) : alloc(a) + , data(0) { } @@ -82,8 +83,9 @@ namespace hpx::util { } else { - p = data.top().first; - data.pop(); + std::pair pair; + data.pop(pair); + p = pair.first; } ++allocated; @@ -104,16 +106,15 @@ namespace hpx::util { private: void clear_cache() noexcept { - while (!data.empty()) + std::pair p; + while (data.pop(p)) { - traits::deallocate( - alloc, data.top().first, data.top().second); - data.pop(); + traits::deallocate(alloc, p.first, p.second); } } HPX_NO_UNIQUE_ADDRESS Allocator alloc; - std::stack> data; + hpx::lockfree::stack> data; std::size_t allocated = 0; std::size_t deallocated = 0; };