From: Ondřej Surý Date: Thu, 23 Aug 2018 13:30:06 +0000 (+0200) Subject: Directly use return value of atomic_compare_exchange_strong_explicit insteaf of compa... X-Git-Tag: v9.13.3~28^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d5df99a9d9d13c9487969b6fa3818a8b83b4ee2;p=thirdparty%2Fbind9.git Directly use return value of atomic_compare_exchange_strong_explicit insteaf of comparing expected value --- diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index b3151465a15..622cd7d2762 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -308,13 +308,13 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { } while (1) { - int_fast32_t cntflag2 = 0; - atomic_compare_exchange_strong_explicit - (&rwl->cnt_and_flag, &cntflag2, WRITER_ACTIVE, - memory_order_relaxed, memory_order_relaxed); - - if (cntflag2 == 0) + int_fast32_t zero = 0; + if (atomic_compare_exchange_strong_explicit + (&rwl->cnt_and_flag, &zero, WRITER_ACTIVE, + memory_order_relaxed, memory_order_relaxed)) + { break; + } /* Another active reader or writer is working. */ LOCK(&rwl->lock); @@ -409,7 +409,9 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) { if (!atomic_compare_exchange_strong_explicit (&rwl->cnt_and_flag, &zero, WRITER_ACTIVE, memory_order_relaxed, memory_order_relaxed)) + { return (ISC_R_LOCKBUSY); + } /* * XXXJT: jump into the queue, possibly breaking the writer