Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use thread-safe cache in thread_local_caching_allocator #6539

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#include <hpx/config.hpp>
#include <hpx/allocator_support/config/defines.hpp>
#include <hpx/concurrency/stack.hpp>

#include <cstddef>
#include <memory>
#include <new>
#include <stack>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -56,6 +56,7 @@ namespace hpx::util {
explicit allocated_cache(Allocator const& a) noexcept(
noexcept(std::is_nothrow_copy_constructible_v<Allocator>))
: alloc(a)
, data(0)
{
}

Expand All @@ -82,8 +83,9 @@ namespace hpx::util {
}
else
{
p = data.top().first;
data.pop();
std::pair<T*, size_type> pair;
data.pop(pair);
hkaiser marked this conversation as resolved.
Show resolved Hide resolved
p = pair.first;
}

++allocated;
Expand All @@ -104,16 +106,15 @@ namespace hpx::util {
private:
void clear_cache() noexcept
{
while (!data.empty())
std::pair<T*, size_type> 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<std::pair<T*, size_type>> data;
hpx::lockfree::stack<std::pair<T*, size_type>> data;
std::size_t allocated = 0;
std::size_t deallocated = 0;
};
Expand Down
Loading