From: Brian Norris Date: Wed, 6 Mar 2013 07:05:25 +0000 (-0800) Subject: linuxrwlocksyield: refactor X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6fb7781c41cfed30851527911c4a48dae79cb107;p=c11tester.git linuxrwlocksyield: refactor --- diff --git a/test/linuxrwlocksyield.c b/test/linuxrwlocksyield.c index 9a676b08..be3550e1 100644 --- a/test/linuxrwlocksyield.c +++ b/test/linuxrwlocksyield.c @@ -29,12 +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); - if (priorvalue > 0) - break; + while (atomic_load_explicit(&rw->lock, memory_order_relaxed) <= 0) { thrd_yield(); - } while (true); + } priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire); } } @@ -44,12 +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); - if (priorvalue == RW_LOCK_BIAS) - break; + while (atomic_load_explicit(&rw->lock, memory_order_relaxed) != RW_LOCK_BIAS) { thrd_yield(); - } while (true); + } priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire); } }