nodestack: bugfix - rewrite 'may-read-from' and 'future values' as the same set
[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 mutex::mutex() {
10         state.islocked=false;
11         thread_id_t tid=thread_current()->get_id();
12         state.alloc_tid=tid;
13         state.alloc_clock=model->get_cv(tid)->getClock(tid);
14 }
15         
16 void mutex::lock() {
17   model->switch_to_master(new ModelAction(ATOMIC_LOCK, std::memory_order_seq_cst, this));
18 }
19         
20 bool mutex::try_lock() {
21   return model->switch_to_master(new ModelAction(ATOMIC_TRYLOCK, std::memory_order_seq_cst, this));
22 }
23
24 void mutex::unlock() {
25   model->switch_to_master(new ModelAction(ATOMIC_UNLOCK, std::memory_order_seq_cst, this));
26 }
27
28 }