X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=test%2Flinuxrwlocks.c;h=3862ed491474ec452b5fba5cdc410ee9a02c5176;hb=9a89975eb7aa3c818124382fc04cc8e8d51dbaaa;hp=dcf323caed1383d0c973a2801b52e00517b0d21b;hpb=50b95c3747f4fe79b2ab1a1a6fc303224e16e418;p=c11tester.git diff --git a/test/linuxrwlocks.c b/test/linuxrwlocks.c index dcf323ca..3862ed49 100644 --- a/test/linuxrwlocks.c +++ b/test/linuxrwlocks.c @@ -4,14 +4,12 @@ #include "librace.h" #include "stdatomic.h" - #define RW_LOCK_BIAS 0x00100000 #define WRITE_LOCK_CMP RW_LOCK_BIAS /** Example implementation of linux rw lock along with 2 thread test * driver... */ - typedef union { atomic_int lock; } rwlock_t; @@ -55,7 +53,7 @@ static inline int read_trylock(rwlock_t *rw) int priorvalue=atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire); if (priorvalue>0) return 1; - + atomic_fetch_add_explicit(&rw->lock, 1, memory_order_relaxed); return 0; } @@ -65,7 +63,7 @@ static inline int write_trylock(rwlock_t *rw) int priorvalue=atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire); if (priorvalue==RW_LOCK_BIAS) return 1; - + atomic_fetch_add_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_relaxed); return 0; } @@ -106,7 +104,7 @@ void user_main() thrd_create(&t1, (thrd_start_t)&a, NULL); thrd_create(&t2, (thrd_start_t)&a, NULL); - + thrd_join(t1); thrd_join(t2); }