From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 8DAF13858410 for ; Thu, 11 Nov 2021 16:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8DAF13858410 Received: by mail-pf1-x42c.google.com with SMTP id z6so6026689pfe.7 for ; Thu, 11 Nov 2021 08:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eM1JTI73m1S4orn7BISQT+W55J2z6/YtOfPGOAmCb0c=; b=a0DhYY3bzmn7By/FuPtybWVA9U+OR7DZt3zGApVq3fR8Az2ImJLQJCBqz636J9Px29 CCoHl4Pmhc8GpLzZ3odCqIelvh/izlNrf5k1Z/y9edFcirNGvxjat4D6t2RIXkV4QlwG Ua07lD/HneuhBEiALH2AZQMARlxq7HmMef/oZuIWapitkf6X7DYHkqQjOkMVLCI+LauE lHJ6WyjcM5X2kYhw4IYesCThDrgnKZTEgooHzmAPvAegaylTK/vSSlcd65YwEgtde5qr C5v94NYC4gU4vmrK6vBSiR9jxq1dIgZDt347i/jdoP2v7HNG9V8scvUxONtqmjAzEiq0 IXZQ== X-Gm-Message-State: AOAM531eR51MhrYjF6YEwj+h5pe6gYtSOjCP9oVSiADD0ftcwD7USg7H /DHOMd4nfX5SoGtrRHqf4e0= X-Google-Smtp-Source: ABdhPJz3Pqq7HC9ZLNJfqqhUoGUY0iopTQlj2m8S18iIwbR5QKpsho8q0ER0grWFOQ+MHp2stralmA== X-Received: by 2002:a65:5688:: with SMTP id v8mr5346704pgs.304.1636647870736; Thu, 11 Nov 2021 08:24:30 -0800 (PST) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id c3sm3675005pfm.177.2021.11.11.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 08:24:29 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 101EE1A0EC3; Thu, 11 Nov 2021 08:24:29 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: Florian Weimer , Oleh Derevenko , Arjan van de Ven , Andreas Schwab , "Paul A . Clarke" , Noah Goldstein Subject: [PATCH v6 4/4] Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537] Date: Thu, 11 Nov 2021 08:24:28 -0800 Message-Id: <20211111162428.2286605-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111162428.2286605-1-hjl.tools@gmail.com> References: <20211111162428.2286605-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Nov 2021 16:24:32 -0000 Replace boolean CAS with value CAS to avoid the extra load. --- nptl/pthread_mutex_timedlock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 57f3f28869..f763cfc7fa 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -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; -- 2.33.1