-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutex.cc
39 lines (31 loc) · 799 Bytes
/
mutex.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "mutex.h"
#include "model.h"
#include "execution.h"
#include "threads-model.h"
#include "clockvector.h"
#include "action.h"
namespace cdsc {
mutex::mutex(int type)
{
state.locked = NULL;
thread_id_t tid = thread_current_id();
state.alloc_tid = tid;
ClockVector *cv = model->get_execution()->get_cv(tid);
state.alloc_clock = cv == NULL ? 0 : cv->getClock(tid);
// For recursive mutex
state.type = type;
state.lock_count = 0;
}
void mutex::lock()
{
model->switch_thread(new ModelAction(ATOMIC_LOCK, std::memory_order_seq_cst, this));
}
bool mutex::try_lock()
{
return model->switch_thread(new ModelAction(ATOMIC_TRYLOCK, std::memory_order_seq_cst, this));
}
void mutex::unlock()
{
model->switch_thread(new ModelAction(ATOMIC_UNLOCK, std::memory_order_seq_cst, this));
}
}