modeltypes: move small typedefs to own header
[c11tester.git] / mutex.cc
1 #include "mutex.h"
2 #include "model.h"
3 #include "threads.h"
4 #include "clockvector.h"
5
6 namespace std {
7 mutex::mutex() {
8         state.islocked=false;
9         thread_id_t tid=thread_current()->get_id();
10         state.alloc_tid=tid;
11         state.alloc_clock=model->get_cv(tid)->getClock(tid);
12 }
13         
14 void mutex::lock() {
15   model->switch_to_master(new ModelAction(ATOMIC_LOCK, std::memory_order_seq_cst, this));
16 }
17         
18 bool mutex::try_lock() {
19   model->switch_to_master(new ModelAction(ATOMIC_TRYLOCK, std::memory_order_seq_cst, this));
20   return thread_current()->get_return_value();
21 }
22
23 void mutex::unlock() {
24   model->switch_to_master(new ModelAction(ATOMIC_UNLOCK, std::memory_order_seq_cst, this));
25 }
26
27 }