update debugging information in readme file
[satcheck.git] / benchmarks / checkfence / seqlock / seqlock.c.in
1 #include "lsl_protos.h"
2
3 int _seq;
4 int _data;
5
6 void seqlock_init() {
7         _seq=0;
8         _data=0;
9 }
10
11 int seqlock_read() {
12         int old_seq = _seq;
13         
14         int c0 = (old_seq % 2 == 1);
15         if (!c0) {
16                 int res = _data;
17                 int seq = _seq;
18                 
19                 int c1;
20                 c1 = seq == old_seq;
21                 if (c1) { // relaxed
22                         return res;
23                 }
24         }
25         return -1;
26 }
27
28
29 int seqlock_write(int new_data) {
30         int old_seq = _seq;
31         int c2 = (old_seq % 2 == 1);
32         if (!c2) {
33                 int new_seq = old_seq + 1;
34                 if (lsl_cas_32(&_seq, old_seq, new_seq)) {
35                         _data = new_data;
36                         lsl_add_32(&_seq, 1);
37                         return 1;
38                 }
39         }
40         return 0;
41 }
42
43 void a() {
44         for(int i=0;i<PROBLEMSIZE;i++)
45                 seqlock_write(3);
46 }
47
48 void b() {
49         for(int i=0;i<PROBLEMSIZE;i++) {
50                 int r1 = seqlock_read();
51         }
52 }
53
54 void c() {
55         for(int i=0;i<PROBLEMSIZE;i++) {
56                 int r1 = seqlock_read();
57         }
58 }
59
60 static void i() {
61         seqlock_init();
62 }