f5894952282be7024867a8880793383f82b8e5f7
[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
12 namespace cdsc {
13 struct mutex_state {
14         void *locked;   /* Thread holding the lock */
15         thread_id_t alloc_tid;
16         modelclock_t alloc_clock;
17 };
18
19 class mutex {
20 public:
21         mutex();
22         ~mutex() {}
23         void lock();
24         bool try_lock();
25         void unlock();
26         struct mutex_state * get_state() {return &state;}
27
28 private:
29         struct mutex_state state;
30 };
31
32 class snapmutex : public mutex {
33 public:
34         snapmutex() : mutex()
35         { }
36         SNAPSHOTALLOC
37 };
38 }
39 #endif  /* __CXX_MUTEX__ */