-
Notifications
You must be signed in to change notification settings - Fork 0
/
impatomic.cc
40 lines (32 loc) · 1.19 KB
/
impatomic.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
40
#include "impatomic.h"
#include "common.h"
#include "model.h"
#include "threads-model.h"
#include "action.h"
namespace std {
bool atomic_flag_test_and_set_explicit ( volatile atomic_flag * __a__, memory_order __x__ ) {
volatile bool * __p__ = &((__a__)->__f__);
bool result = (bool) model->switch_thread(new ModelAction(ATOMIC_RMWR, __x__, (void *) __p__));
model->switch_thread(new ModelAction(ATOMIC_RMW, __x__, (void *) __p__, true));
return result;
}
bool atomic_flag_test_and_set( volatile atomic_flag* __a__ )
{ return atomic_flag_test_and_set_explicit( __a__, memory_order_seq_cst ); }
void atomic_flag_clear_explicit
( volatile atomic_flag* __a__, memory_order __x__ )
{
volatile bool * __p__ = &((__a__)->__f__);
model->switch_thread(new ModelAction(ATOMIC_WRITE, __x__, (void *) __p__, false));
}
void atomic_flag_clear( volatile atomic_flag* __a__ )
{ atomic_flag_clear_explicit( __a__, memory_order_seq_cst ); }
void __atomic_flag_wait__( volatile atomic_flag* __a__ ) {
while ( atomic_flag_test_and_set( __a__ ) )
;
}
void __atomic_flag_wait_explicit__( volatile atomic_flag* __a__,
memory_order __x__ ) {
while ( atomic_flag_test_and_set_explicit( __a__, __x__ ))
;
}
}