mn_safecounter.hpp
Go to the documentation of this file.
1 
20 #ifndef _MINLIB_7ea02a66_6557_4465_8a08_05054e5ccea8_H_
21 #define _MINLIB_7ea02a66_6557_4465_8a08_05054e5ccea8_H_
22 
23 #include "mn_config.hpp"
24 
25 #include "mn_autolock.hpp"
26 #include "mn_error.hpp"
27 #include "pointer/mn_lock_ptr.hpp"
28 
29 
30 namespace mn {
31 
35  template <typename T, class TLOCK>
37  public:
38  using value_type = T;
40  using lock_type = TLOCK;
42 
47  : m_iCount(0) { }
48 
55  : m_iCount(start) {}
56 
60  ++(*lock);
61 
62  return *this;
63  }
67  --(*lock);
68 
69  return *this;
70  }
74  return lock->get();
75  }
76  protected:
78  volatile value_type m_iCount;
79  };
80 
99 }
100 
101 #endif
safe counter is a base of thread saftly counter
Definition: mn_safecounter.hpp:36
value_type count()
get the current count
Definition: mn_safecounter.hpp:72
basic_safe_counter(value_type start)
Construct a new basic safe counter object.
Definition: mn_safecounter.hpp:54
self_type & operator++()
thread saftly increment operator
Definition: mn_safecounter.hpp:58
volatile value_type m_iCount
Definition: mn_safecounter.hpp:78
pointer::basic_lock_ptr< T, TLOCK > lock_ptr_type
Definition: mn_safecounter.hpp:41
self_type & operator--()
thread saftly decrement operator
Definition: mn_safecounter.hpp:65
TLOCK lock_type
Definition: mn_safecounter.hpp:40
T value_type
Definition: mn_safecounter.hpp:38
lock_type m_lockObject
Definition: mn_safecounter.hpp:77
basic_safe_counter()
Construct a new basic safe counter object.
Definition: mn_safecounter.hpp:46
auto lock pointer.
Definition: mn_lock_ptr.hpp:36
A list of all error codes in this lib. This file is part of the Mini Thread Library (https://github....
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
int lock(TLOCK &m1, unsigned int timeout)
Definition: mn_autolock.hpp:70