10 using std::memory_order_release;
11 using std::memory_order_acquire;
12 using std::memory_order_relaxed;
16 // Sequence for reader consistency check.
18 // It needs to be atomic to avoid data races
23 atomic_init(&seq_, 0);
24 atomic_init(&data_, 0);
30 int old_seq = seq_.load(memory_order_acquire);
31 if (old_seq % 2 == 1) {
36 int res = data_.load(memory_order_acquire);
37 if (seq_.load(memory_order_relaxed) == old_seq) {
43 void write(int new_data) {
46 // This might be a relaxed too
47 int old_seq = seq_.load(memory_order_acquire);
48 if (old_seq % 2 == 1) {
53 // Should be relaxed!!!
54 if (seq_.compare_exchange_strong(old_seq, old_seq + 1,
56 memory_order_relaxed)) {
62 data_.store(new_data, memory_order_release); // release
64 seq_.fetch_add(1, memory_order_release); // release
68 } // namespace cds_others