X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=linuxrwlocks%2Flinuxrwlocks.c;h=be3550e11e3c8f8740b4c1a47458180f57994a3a;hb=9f2a28f12f61001be2bd5adc74964acf5e8e6721;hp=7e317aa9fcf019b91336823985d5054c9b23166d;hpb=2f3d40c4e6a817013804e62e0009cf6247d95321;p=model-checker-benchmarks.git diff --git a/linuxrwlocks/linuxrwlocks.c b/linuxrwlocks/linuxrwlocks.c index 7e317aa..be3550e 100644 --- a/linuxrwlocks/linuxrwlocks.c +++ b/linuxrwlocks/linuxrwlocks.c @@ -29,9 +29,9 @@ static inline void read_lock(rwlock_t *rw) int priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire); while (priorvalue <= 0) { atomic_fetch_add_explicit(&rw->lock, 1, memory_order_relaxed); - do { - priorvalue = atomic_load_explicit(&rw->lock, memory_order_relaxed); - } while (priorvalue <= 0); + while (atomic_load_explicit(&rw->lock, memory_order_relaxed) <= 0) { + thrd_yield(); + } priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire); } } @@ -41,9 +41,9 @@ static inline void write_lock(rwlock_t *rw) int priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire); while (priorvalue != RW_LOCK_BIAS) { atomic_fetch_add_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_relaxed); - do { - priorvalue = atomic_load_explicit(&rw->lock, memory_order_relaxed); - } while (priorvalue != RW_LOCK_BIAS); + while (atomic_load_explicit(&rw->lock, memory_order_relaxed) != RW_LOCK_BIAS) { + thrd_yield(); + } priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire); } }