7 #include "libinterface.h"
10 /*atomic_*/ int _data;
19 int old_seq = load_32(&_seq);
21 if (old_seq % 2 == 1) {
23 int res = load_32(&_data);
24 int seq = load_32(&_seq);
26 if (seq == old_seq) { // relaxed
33 void seqlock_write(int new_data) {
35 int old_seq = load_32(&_seq);
36 if (old_seq % 2 == 1) {
38 int new_seq = old_seq + 1;
39 int cas_value = rmw_32(CAS, &_seq, old_seq, new_seq);
40 if (old_seq == cas_value) {
45 store_32(&_data, new_data);
47 rmw_32(ADD, &_seq, /*dummy */0, 1);
50 static void a(void *obj) {
54 static void b(void *obj) {
58 static void c(void *obj) {
59 int r1 = seqlock_read();
62 int user_main(int argc, char **argv) {
66 thrd_create(&t1, (thrd_start_t)&a, NULL);
67 thrd_create(&t2, (thrd_start_t)&b, NULL);
68 thrd_create(&t3, (thrd_start_t)&c, NULL);