Move assignment out of the CAS condition

Update

commit 49302b8fdf
Author: H.J. Lu <hjl.tools@gmail.com>
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 0b82747dc4
Author: H.J. Lu <hjl.tools@gmail.com>
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 120ac6d238)
This commit is contained in:
H.J. Lu 2021-11-12 11:47:42 -08:00 committed by Sunil K Pandey
parent a6b81f605d
commit 6bcfbee727
2 changed files with 6 additions and 8 deletions

View File

@ -305,10 +305,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
meantime. */ meantime. */
if ((oldval & FUTEX_WAITERS) == 0) if ((oldval & FUTEX_WAITERS) == 0)
{ {
int val; int val = atomic_compare_and_exchange_val_acq
if ((val = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval);
(&mutex->__data.__lock, oldval | FUTEX_WAITERS, if (val != oldval)
oldval)) != oldval)
{ {
oldval = val; oldval = val;
continue; continue;

View File

@ -234,10 +234,9 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
meantime. */ meantime. */
if ((oldval & FUTEX_WAITERS) == 0) if ((oldval & FUTEX_WAITERS) == 0)
{ {
int val; int val = atomic_compare_and_exchange_val_acq
if ((val = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval);
(&mutex->__data.__lock, oldval | FUTEX_WAITERS, if (val != oldval)
oldval)) != oldval)
{ {
oldval = val; oldval = val;
continue; continue;