Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537]
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Nov 2021 14:54:01 +0000 (06:54 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 12 Nov 2021 18:31:31 +0000 (10:31 -0800)
Replace boolean CAS with value CAS to avoid the extra load.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
nptl/pthread_mutex_timedlock.c

index 57f3f28..f763cfc 100644 (file)
@@ -233,12 +233,12 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
             meantime.  */
          if ((oldval & FUTEX_WAITERS) == 0)
            {
-             if (atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock,
-                                                       oldval | FUTEX_WAITERS,
-                                                       oldval)
-                 != 0)
+             int val;
+             if ((val = atomic_compare_and_exchange_val_acq
+                  (&mutex->__data.__lock, oldval | FUTEX_WAITERS,
+                   oldval)) != oldval)
                {
-                 oldval = mutex->__data.__lock;
+                 oldval = val;
                  continue;
                }
              oldval |= FUTEX_WAITERS;