bugs...
[model-checker.git] / impatomic.cc
1 #include "impatomic.h"
2 #include "common.h"
3 #include "model.h"
4
5 namespace std {
6
7 bool atomic_flag_test_and_set_explicit ( volatile atomic_flag * __a__, memory_order __x__ ) {
8         volatile bool * __p__ = &((__a__)->__f__);
9         model->switch_to_master(new ModelAction(ATOMIC_RMWR, __x__, (void *) __p__));
10         bool result = (bool) thread_current()->get_return_value();
11         model->switch_to_master(new ModelAction(ATOMIC_RMW, __x__, (void *) __p__, true));
12         return result;
13 }
14
15 bool atomic_flag_test_and_set( volatile atomic_flag* __a__ )
16 { return atomic_flag_test_and_set_explicit( __a__, memory_order_seq_cst ); }
17
18 void atomic_flag_clear_explicit
19 ( volatile atomic_flag* __a__, memory_order __x__ )
20 {
21         volatile bool * __p__ = &((__a__)->__f__);
22         model->switch_to_master(new ModelAction(ATOMIC_WRITE, __x__, (void *) __p__, false));
23 }
24
25 void atomic_flag_clear( volatile atomic_flag* __a__ )
26 { atomic_flag_clear_explicit( __a__, memory_order_seq_cst ); }
27
28 void atomic_flag_fence( const volatile atomic_flag* __a__, memory_order __x__ )
29 {
30         ASSERT(0);
31 }
32
33 void __atomic_flag_wait__( volatile atomic_flag* __a__ )
34 { while ( atomic_flag_test_and_set( __a__ ) ); }
35
36 void __atomic_flag_wait_explicit__( volatile atomic_flag* __a__,
37                                     memory_order __x__ )
38 { while ( atomic_flag_test_and_set_explicit( __a__, __x__ ) ); }
39
40 }