memgraph/utils/counters/atomic_counter.hpp
2015-07-31 12:35:14 +02:00

22 lines
361 B
C++

#ifndef MEMGRAPH_UTILS_COUNTERS_ATOMIC_COUNTER_HPP
#define MEMGRAPH_UTILS_COUNTERS_ATOMIC_COUNTER_HPP
#include <atomic>
template <class T>
class AtomicCounter
{
public:
AtomicCounter(T initial) : counter(initial) {}
T next()
{
return counter.fetch_add(1, std::memory_order_relaxed);
}
private:
std::atomic<T> counter;
};
#endif