Update readme
[c11tester.git] / include / mutex.h
1 /**
2  * @file mutex
3  * @brief C++11 mutex interface header
4  */
5
6 #ifndef __CXX_MUTEX__
7 #define __CXX_MUTEX__
8
9 #include "modeltypes.h"
10 #include "mymemory.h"
11 #include "mypthread.h"
12
13 namespace cdsc {
14 struct mutex_state {
15         void *locked;   /* Thread holding the lock */
16         thread_id_t alloc_tid;
17         modelclock_t alloc_clock;
18         int type;
19         int lock_count;
20 };
21
22 class mutex {
23 public:
24         mutex(int type = PTHREAD_MUTEX_DEFAULT);
25         ~mutex() {}
26         void lock();
27         bool try_lock();
28         void unlock();
29         struct mutex_state * get_state() {return &state;}
30
31 private:
32         struct mutex_state state;
33 };
34
35 class snapmutex : public mutex {
36 public:
37         snapmutex(int type = 0) : mutex(type)
38         { }
39         SNAPSHOTALLOC
40 };
41 }
42 #endif  /* __CXX_MUTEX__ */