changes to seqlock
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 13 Feb 2015 02:26:01 +0000 (18:26 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 13 Feb 2015 02:26:01 +0000 (18:26 -0800)
Makefile
seqlock/seqlock-wildcard.h
seqlock/seqlock.c
seqlock/seqlock.h
seqlock/testcase1.c

index 835f7d12a72297163e67d5db567058d989a97a79..b681de1b5689cbc2e04542cd06f5217793916c53 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 DIRS := barrier mcs-lock mpmc-queue spsc-queue spsc-bugfix linuxrwlocks \
        dekker-fences chase-lev-deque ms-queue chase-lev-deque-bugfix \
-       concurrent-hashmap
+       concurrent-hashmap seqlock
 
 .PHONY: $(DIRS)
 
index 85686eaf9ebe60af0e3e1c4ae26bddfda4370aaa..62b7583954bd446a4c224030117712321d5ff369 100644 (file)
@@ -27,9 +27,8 @@ typedef struct seqlock {
        }
        
        void write(int new_data) {
+               int old_seq = _seq.load(wildcard(4)); // acquire
                while (true) {
-                       // This might be a relaxed too
-                       int old_seq = _seq.load(wildcard(4)); // acquire
                        if (old_seq % 2 == 1)
                                continue; // Retry
 
index d2e33b896c848c054d5d1f44614af8c42c9bddaf..146239f960f0ada2536989233f8c9b4302e9f636 100644 (file)
@@ -22,11 +22,11 @@ int user_main(int argc, char **argv) {
        lock = new seqlock_t();
 
        thrd_create(&t1, (thrd_start_t)&a, NULL);
-       thrd_create(&t2, (thrd_start_t)&b, NULL);
+       //thrd_create(&t2, (thrd_start_t)&b, NULL);
        thrd_create(&t3, (thrd_start_t)&c, NULL);
 
        thrd_join(t1);
-       thrd_join(t2);
+       //thrd_join(t2);
        thrd_join(t3);
        return 0;
 }
index f263bec082614274e56a4d584b73505b25fc4112..c5a965cb8243bbb191ebe0620a72bdc50c0e4105 100644 (file)
@@ -17,7 +17,7 @@ typedef struct seqlock {
                        int old_seq = _seq.load(memory_order_acquire); // acquire
                        if (old_seq % 2 == 1) continue;
 
-                       int res = _data.load(memory_order_acquire); // acquire
+                       int res = _data.load(memory_order_acquire); 
                        if (_seq.load(memory_order_relaxed) == old_seq) { // relaxed
                                return res;
                        }
@@ -25,20 +25,19 @@ typedef struct seqlock {
        }
        
        void write(int new_data) {
+               int old_seq = _seq.load(memory_order_acquire); // acquire
                while (true) {
                        // This might be a relaxed too
-                       int old_seq = _seq.load(memory_order_acquire); // acquire
                        if (old_seq % 2 == 1)
                                continue; // Retry
 
-                       // Should be relaxed!!! 
                        if (_seq.compare_exchange_strong(old_seq, old_seq + 1,
-                               memory_order_relaxed, memory_order_relaxed)) // relaxed 
+                               memory_order_acq_rel, memory_order_acquire)) 
                                break;
                }
 
                // Update the data
-               _data.store(new_data, memory_order_release); // release
+               _data.store(new_data, memory_order_release); // Can be relaxed
 
                _seq.fetch_add(1, memory_order_release); // release
        }
index 6417db312db5f1b91077cf091356ab13b64f98c6..8441972702762d0ab33aef89f5ca9c435331fae8 100644 (file)
@@ -14,6 +14,7 @@ static void b(void *obj) {
 }
 
 static void c(void *obj) {
+       lock->write(2);
        int r1 = lock->read();
 }
 
@@ -22,11 +23,11 @@ int user_main(int argc, char **argv) {
        lock = new seqlock_t();
 
        thrd_create(&t1, (thrd_start_t)&a, NULL);
-       thrd_create(&t2, (thrd_start_t)&b, NULL);
+       //thrd_create(&t2, (thrd_start_t)&b, NULL);
        thrd_create(&t3, (thrd_start_t)&c, NULL);
 
        thrd_join(t1);
-       thrd_join(t2);
+       //thrd_join(t2);
        thrd_join(t3);
        return 0;
 }