cpp-pthread  (v1.7.3)
Simple C++ wrapper to pthread functions.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
lock_guard.hpp
1 //
2 // lock_guard.hpp
3 // lock_guard
4 //
5 // Created by herbert koelman on 18/03/2016.
6 //
7 //
8 
9 #ifndef pthread_lock_guard_H
10 #define pthread_lock_guard_H
11 
12 // must be include as first hearder file of each source code file (see IBM's
13 // recommandation for more info p.285 §8.3.1).
14 #include <pthread.h>
15 
16 #include "pthread/config.h"
17 #include "pthread/mutex.hpp"
18 
19 
20 namespace pthread {
21 
27  //class condition_variable ;
28 
37  template<class MutexType>
38  class lock_guard {
39 
40  friend class condition_variable;
41 
42  public:
50  explicit lock_guard(MutexType &m){ //: _mutex(&m) {
51  _mutex = &m ;
52  _mutex->lock();
53  }
54 
58  _mutex->unlock();
59  }
60 
65  MutexType *internal_mutex() {
66  return _mutex ;
67  }
68 
72  void operator=(lock_guard &) = delete;
73 
74  private:
75  MutexType *_mutex;
76  };
77 
79 } // namespace pthread
80 
81 #endif /* pthread_lock_guard_H */
lock_guard(MutexType &m)
Definition: lock_guard.hpp:50
MutexType * internal_mutex()
Definition: lock_guard.hpp:65
void operator=(lock_guard &)=delete