15 template<
class numeric_type = u
int32_t>
22 std::atomic<numeric_type> m_counter;
26 const numeric_type m_reset_value;
30 const numeric_type m_upper_bound;
34 const numeric_type m_lower_bound;
43 static_assert(std::is_integral<numeric_type>::value,
"Not a integer numeric type");
53 : m_counter(0), m_reset_value(0), m_lower_bound(0),
54 m_upper_bound(std::numeric_limits<numeric_type>::max())
63 : m_counter(0), m_reset_value(0), m_upper_bound(upper_bound), m_lower_bound(lower_bound)
74 : m_counter(0), m_reset_value(reset_value), m_upper_bound(upper_bound), m_lower_bound(lower_bound)
86 numeric_type upper_bound, numeric_type lower_bound)
87 : m_counter(initial_value), m_reset_value(reset_value), m_upper_bound(upper_bound),
88 m_lower_bound(lower_bound)
108 if (m_counter < (m_upper_bound - 1))
return m_counter.fetch_add(1);
110 m_counter.store(m_reset_value);
119 if (m_counter < (m_upper_bound - 1)) ++m_counter;
120 else m_counter.store(m_reset_value);
129 if (m_counter > m_lower_bound)
return m_counter.fetch_sub(1);
131 m_counter.store(m_reset_value);
140 if (m_counter > m_lower_bound) --m_counter;
141 else m_counter.store(m_reset_value);
149 inline explicit operator numeric_type()
const
151 return m_counter.load();
160 m_counter.store(m_reset_value);
Definition concurrent_counter.hpp:17
concurrent_counter(numeric_type initial_value, numeric_type reset_value, numeric_type upper_bound, numeric_type lower_bound)
Construct a new counter object.
Definition concurrent_counter.hpp:85
concurrent_counter()
Construct a new counter object. Initializes the counter with a.
Definition concurrent_counter.hpp:52
numeric_type operator--(int32_t)
overloaded post decrement operator
Definition concurrent_counter.hpp:127
numeric_type operator--()
overloaded pre decrement operator
Definition concurrent_counter.hpp:138
std::atomic< numeric_type > & operator()()
Definition concurrent_counter.hpp:98
numeric_type operator++(int32_t)
overloaded post increment operator
Definition concurrent_counter.hpp:106
numeric_type operator++()
overloaded pre increment operator
Definition concurrent_counter.hpp:117
numeric_type counter_type
Type of the counter.
Definition concurrent_counter.hpp:40
void reset()
Returns the counter to its reset value.
Definition concurrent_counter.hpp:158
concurrent_counter(numeric_type reset_value, numeric_type upper_bound, numeric_type lower_bound)
Construct a new counter object.
Definition concurrent_counter.hpp:73
concurrent_counter(numeric_type upper_bound, numeric_type lower_bound)
Construct a new counter object.
Definition concurrent_counter.hpp:62
virtual ~concurrent_counter()=default
friend std::ostream & operator<<(std::ostream &os, const concurrent_counter &rhs)
overloaded ostream operator for capturing the counter value
Definition concurrent_counter.hpp:169
Definition reader_writer_lock_shim.hpp:7