about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-11-11 06:54:01 -0800
committerSunil K Pandey <skpgkp2@gmail.com>2022-09-28 13:47:16 -0700
commit0ec276739a22c0305263941b5213e8c368269ec0 (patch)
tree2c595b4be17e7a9263b36fe27a4afc0dbeb9296d
parentf5a70409db67f3a5f035d9d6082d11efcc74910d (diff)
downloadglibc-0ec276739a22c0305263941b5213e8c368269ec0.tar.gz
glibc-0ec276739a22c0305263941b5213e8c368269ec0.tar.xz
glibc-0ec276739a22c0305263941b5213e8c368269ec0.zip
Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537]
Replace boolean CAS with value CAS to avoid the extra load.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 49302b8fdf9103b6fc0a398678668a22fa19574c)
-rw-r--r--nptl/pthread_mutex_timedlock.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 8428ebca0f..541ec18938 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -247,12 +247,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;