6#include <bond/core/config.h>
8#include "capped_allocator_fwd.h"
9#include "detail/counter_base.h"
11#include <boost/assert.hpp>
16namespace bond {
namespace ext
25 using is_thread_safe = std::true_type;
29 bool try_add(T n) BOND_NOEXCEPT
31 if (n <= this->max_value())
33 const auto max_val = this->max_value() - n;
35 for (
auto val = _value.load(std::memory_order::memory_order_acquire); val <= max_val; )
37 if (_value.compare_exchange_weak(
40 std::memory_order::memory_order_release,
41 std::memory_order::memory_order_acquire))
51 void subtract(T n) BOND_NOEXCEPT
53 BOOST_ASSERT(
value() >= n);
54 _value.fetch_sub(n, std::memory_order::memory_order_relaxed);
60 return _value.load(std::memory_order::memory_order_relaxed);
64 std::atomic<T> _value{};
Helper base class for counters.
Definition: counter_base.h:17
Multi-threaded counter to be used with capped_allocator.
Definition: multi_threaded_counter.h:23
T value() const BOND_NOEXCEPT
Definition: multi_threaded_counter.h:58
namespace bond
Definition: apply.h:17