Skip to content

Commit

Permalink
Merge c008395 into f4ff6e8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pansysk75 authored Sep 9, 2024
2 parents f4ff6e8 + c008395 commit ed89bf1
Showing 1 changed file with 12 additions and 12 deletions.
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 @@ -72,19 +73,19 @@ namespace hpx::util {
pointer allocate(size_type n)
{
pointer p;
if (data.empty())
std::pair<T*, size_type> pair;
if (data.pop(pair))
{
p = pair.first;
}
else
{
p = traits::allocate(alloc, n);
if (p == nullptr)
{
throw std::bad_alloc();
}
}
else
{
p = data.top().first;
data.pop();
}

++allocated;
return p;
Expand All @@ -104,16 +105,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

0 comments on commit ed89bf1

Please sign in to comment.