fixed atomic counter to be seq_cst and added compile time checking of T to be integral
This commit is contained in:
parent
e28d15c272
commit
0c65f14043
@ -2,16 +2,23 @@
|
||||
#define MEMGRAPH_UTILS_COUNTERS_ATOMIC_COUNTER_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
template <class T,
|
||||
typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
|
||||
class AtomicCounter
|
||||
{
|
||||
public:
|
||||
AtomicCounter(T initial) : counter(initial) {}
|
||||
AtomicCounter(T initial = 0) : counter(initial) {}
|
||||
|
||||
T next()
|
||||
T next(std::memory_order order = std::memory_order_seq_cst)
|
||||
{
|
||||
return counter.fetch_add(1);
|
||||
return counter.fetch_add(1, order);
|
||||
}
|
||||
|
||||
T operator++()
|
||||
{
|
||||
return next();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user