about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-11-12 11:47:42 -0800
committerSunil K Pandey <skpgkp2@gmail.com>2022-09-28 07:33:49 -0700
commit6bcfbee7277e4faa4b693bd965931f0d1883005d (patch)
tree194b55b2b510c5f3b076cbe125b2d3535907bd82 /nptl
parenta6b81f605dfba8650ea1f80122f41eb8e6c73dc7 (diff)
downloadglibc-6bcfbee7277e4faa4b693bd965931f0d1883005d.tar.gz
glibc-6bcfbee7277e4faa4b693bd965931f0d1883005d.tar.xz
glibc-6bcfbee7277e4faa4b693bd965931f0d1883005d.zip
Move assignment out of the CAS condition
Update

commit 49302b8fdf9103b6fc0a398678668a22fa19574c
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 0b82747dc48d5bf0871bdc6da8cb6eec1256355f
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 120ac6d238825452e8024e2f627da33b2508dfd3)
Diffstat (limited to 'nptl')
-rw-r--r--nptl/pthread_mutex_lock.c7
-rw-r--r--nptl/pthread_mutex_timedlock.c7
2 files changed, 6 insertions, 8 deletions
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index 9f40928cc6..49901ffa0a 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -305,10 +305,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 90cede9446..2e5506db06 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -234,10 +234,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;