mn_atomic_counter.hpp
Go to the documentation of this file.
1 
20 #ifndef __MINLIB_ATOMIC_COUNTER_H__
21 #define __MINLIB_ATOMIC_COUNTER_H__
22 
23 #include "mn_config.hpp"
24 
25 #include "mn_atomic.hpp"
26 #include "mn_copyable.hpp"
27 
28 namespace mn {
29 
35  public:
36  using value_type = int;
51  atomic_counter(const atomic_counter& other);
52 
56  inline operator value_type () const { return m_atomicCount.load(); }
61  inline value_type value() const { return m_atomicCount.load(); }
62 
67  inline value_type operator ++ () { return ++m_atomicCount; }
72  inline value_type operator -- () { return --m_atomicCount; }
73 
78  inline value_type operator ++ (int) { return m_atomicCount++; }
83  inline value_type operator -- (int) { return m_atomicCount--; }
88  inline bool operator ! () const { return m_atomicCount.load() == 0; }
98  private:
100  };
101 }
102 #endif // __MINLIB_ATOMIC_COUNTER_H__
This class implements a simple counter, whit atomic operations for use in a multithreaded environment...
Definition: mn_atomic_counter.hpp:34
atomic_counter()
Construct a new atomic_counter and initializes it to zero.
Definition: mn_atomic_counter.cpp:24
value_type value() const
Get the value of the counter.
Definition: mn_atomic_counter.hpp:61
int value_type
Definition: mn_atomic_counter.hpp:36
_atomic< value_type > m_atomicCount
Definition: mn_atomic_counter.hpp:99
value_type operator--()
Decrements the counter.
Definition: mn_atomic_counter.hpp:72
bool operator!() const
If the counter zero?
Definition: mn_atomic_counter.hpp:88
value_type operator++()
Increments the counter.
Definition: mn_atomic_counter.hpp:67
atomic_counter & operator=(const atomic_counter &other)
Assigns the value of another atomic_counter.
Definition: mn_atomic_counter.cpp:34
Basic atomics types This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/Mini...
Definition: mn_allocator_typetraits.hpp:25