190885
From ca37f880abe1c8e3464fd646fd8b89171d8fca0c Mon Sep 17 00:00:00 2001
190885
From: "H.J. Lu" <hjl.tools@gmail.com>
190885
Date: Thu, 11 Nov 2021 06:31:51 -0800
190885
Subject: [PATCH] Avoid extra load with CAS in __pthread_mutex_lock_full [BZ
190885
 #28537]
190885
190885
Replace boolean CAS with value CAS to avoid the extra load.
190885
190885
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
190885
(cherry picked from commit 0b82747dc48d5bf0871bdc6da8cb6eec1256355f)
190885
---
190885
 nptl/pthread_mutex_lock.c | 10 +++++-----
190885
 1 file changed, 5 insertions(+), 5 deletions(-)
190885
190885
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
190885
index 29cc143e..60ada70d 100644
190885
--- a/nptl/pthread_mutex_lock.c
190885
+++ b/nptl/pthread_mutex_lock.c
190885
@@ -292,12 +292,12 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
190885
 	     meantime.  */
190885
 	  if ((oldval & FUTEX_WAITERS) == 0)
190885
 	    {
190885
-	      if (atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock,
190885
-							oldval | FUTEX_WAITERS,
190885
-							oldval)
190885
-		  != 0)
190885
+	      int val;
190885
+	      if ((val = atomic_compare_and_exchange_val_acq
190885
+		   (&mutex->__data.__lock, oldval | FUTEX_WAITERS,
190885
+		    oldval)) != oldval)
190885
 		{
190885
-		  oldval = mutex->__data.__lock;
190885
+		  oldval = val;
190885
 		  continue;
190885
 		}
190885
 	      oldval |= FUTEX_WAITERS;
190885
-- 
190885
GitLab
190885