Bites
A small library of miscellaneous C++ codes.
 All Classes Namespaces Functions Friends Pages
MutexedCounter.hpp
1 #ifndef BITES_MUTEXEDCOUNTER_HPP_INCLUDED
2 #define BITES_MUTEXEDCOUNTER_HPP_INCLUDED
3 
4 #include <mutex>
5 
6 namespace bites {
7 
34 template <typename T>
36 {
37 protected:
41  static int incrCount ()
42  {
43  std::lock_guard <std::mutex> locker (m_lock);
44  return ++m_count;
45  }
46 
50  static int decrCount ()
51  {
52  std::lock_guard <std::mutex> locker (m_lock);
53  return --m_count;
54  }
55 
56 private:
60  static std::mutex m_lock;
61 
65  static int m_count;
66 };
67 
68 template <typename T> std::mutex MutexedCounter<T>::m_lock;
69 template <typename T> int MutexedCounter<T>::m_count (0);
70 
71 } // namespace bites.
72 
73 #endif // BITES_MUTEXEDCOUNTER_HPP_INCLUDED
static int incrCount()
Definition: MutexedCounter.hpp:41
Definition: MutexedCounter.hpp:35
static int decrCount()
Definition: MutexedCounter.hpp:50