common: make model_print() use OS file descriptor, not C library FILE*
[model-checker.git] / mutex.cc
1 #include <mutex>
2
3 #include "model.h"
4 #include "threads-model.h"
5 #include "clockvector.h"
6 #include "action.h"
7
8 namespace std {
9
10 mutex::mutex()
11 {
12         state.locked = NULL;
13         thread_id_t tid = thread_current()->get_id();
14         state.alloc_tid = tid;
15         state.alloc_clock = model->get_cv(tid)->getClock(tid);
16 }
17         
18 void mutex::lock()
19 {
20         model->switch_to_master(new ModelAction(ATOMIC_LOCK, std::memory_order_seq_cst, this));
21 }
22         
23 bool mutex::try_lock()
24 {
25         return model->switch_to_master(new ModelAction(ATOMIC_TRYLOCK, std::memory_order_seq_cst, this));
26 }
27
28 void mutex::unlock()
29 {
30         model->switch_to_master(new ModelAction(ATOMIC_UNLOCK, std::memory_order_seq_cst, this));
31 }
32
33 }