From: H.J. Lu Date: Fri, 12 Nov 2021 19:47:42 +0000 (-0800) Subject: Move assignment out of the CAS condition X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60b8295333a076ff853c1093c502c7bf5197ab2e;p=thirdparty%2Fglibc.git Move assignment out of the CAS condition Update commit 49302b8fdf9103b6fc0a398678668a22fa19574c Author: H.J. Lu Date: Thu Nov 11 06:54:01 2021 -0800 Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537] Replace boolean CAS with value CAS to avoid the extra load. and commit 0b82747dc48d5bf0871bdc6da8cb6eec1256355f Author: H.J. Lu Date: Thu Nov 11 06:31:51 2021 -0800 Avoid extra load with CAS in __pthread_mutex_lock_full [BZ #28537] Replace boolean CAS with value CAS to avoid the extra load. by moving assignment out of the CAS condition. (cherry picked from commit 120ac6d238825452e8024e2f627da33b2508dfd3) --- diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index ac8a472c08d..2895926953e 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -296,10 +296,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - int val; - if ((val = atomic_compare_and_exchange_val_acq - (&mutex->__data.__lock, oldval | FUTEX_WAITERS, - oldval)) != oldval) + int val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval); + if (val != oldval) { oldval = val; continue; diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 541ec189384..22174f74c9b 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -247,10 +247,9 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - int val; - if ((val = atomic_compare_and_exchange_val_acq - (&mutex->__data.__lock, oldval | FUTEX_WAITERS, - oldval)) != oldval) + int val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval); + if (val != oldval) { oldval = val; continue;