From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 40C1C3857C42; Fri, 19 Nov 2021 21:02:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40C1C3857C42 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/relr] Avoid extra load with CAS in __pthread_mutex_lock_full [BZ #28537] X-Act-Checkin: glibc X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/maskray/relr X-Git-Oldrev: 6c1e3c0fd09a9653f562db69e77281e358451163 X-Git-Newrev: 0b82747dc48d5bf0871bdc6da8cb6eec1256355f Message-Id: <20211119210220.40C1C3857C42@sourceware.org> Date: Fri, 19 Nov 2021 21:02:20 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Nov 2021 21:02:20 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0b82747dc48d5bf0871bdc6da8cb6eec1256355f commit 0b82747dc48d5bf0871bdc6da8cb6eec1256355f Author: H.J. Lu 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. Reviewed-by: Szabolcs Nagy Diff: --- nptl/pthread_mutex_lock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 2bd41767e0..59a28cff1a 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -297,12 +297,12 @@ __pthread_mutex_lock_full (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;