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