From patchwork Sat Jun 6 21:26:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Rodgers X-Patchwork-Id: 1304624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=appliantology.com Authentication-Results: ozlabs.org; dkim=pass (4096-bit key; secure) header.d=kolabnow.com header.i=@kolabnow.com header.a=rsa-sha256 header.s=dkim20160331 header.b=uyw5PXPO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49fXdR5g03z9sSg for ; Sun, 7 Jun 2020 07:26:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95EBB386F83A; Sat, 6 Jun 2020 21:26:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx.kolabnow.com (mx.kolabnow.com [95.128.36.42]) by sourceware.org (Postfix) with ESMTPS id BA3AB386F023; Sat, 6 Jun 2020 21:26:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA3AB386F023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=appliantology.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=rodgert@appliantology.com Received: from localhost (unknown [127.0.0.1]) by ext-mx-out001.mykolab.com (Postfix) with ESMTP id B3635BBA; Sat, 6 Jun 2020 23:26:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:mime-version:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20160331; t=1591478787; x=1593293188; bh=m/MpYSpTP2gviEMQUfm GYpxIL3aU3Vo/hnZAkeldLZE=; b=uyw5PXPO29k30IcCoI7roks73lzqsAmX6Rp 1A9Oo5cVvFK/SHgHQVeCSjOa3O0RuUnFTrY+IcwXZTEGtBvtpSrm+zHg4hBZ+kx4 n7tdRVurFl4NICghNTjBQrDFqmoZ9prKKQUb1zLuTqXK1gor3I75erlT05JzFCZZ lsQ7+AAZ6EmoPqDIkiZgwyuDeyRANzET52vvp+rK4jn3JYnzI5VstOkxz5GR5epN gmpxi99Gj69tPUN2B8u2fPJ+dsXBegPb2o5KrqJlCNBR9oYKnJ62vyzeRom40Qol 8gTU2F6NERNIg1L+t4IHtu9k+432tHR/d/csVKVNQMN0zdm+DJMNWNlLUBnzWDZn 4ySzapDYvbExOj1mlzeRxIQUMYmrZqlaWoREjxmzAqwNz3UEED7c6dpkfh85AW6Q Y548+SzQrQToRocmiYzKmeF6VwL9gNiAvzWMnsjORS6SgUKyWkbeRkuLHJ4OVkn6 do+kKIC0IHn/dPzep4PdqmjXkttvz0xUYv9tXubutDypfDMkP9cAUKKDex17d4yf 5cNjQDjroVeHDcIWbbaPGDXuo0jDycfomi8Fu2+02/oTjKbSRPawafdHHo9gaNvr CBZEzz8DzbwpQNqN9n4d5YxfuBncEIcOaKmCq/zu/sP0d5zebD/IiCg1hss9rPVi PTEZ0wS4= X-Virus-Scanned: amavisd-new at mykolab.com X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out001.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OfPzXDXDh55P; Sat, 6 Jun 2020 23:26:27 +0200 (CEST) Received: from int-mx001.mykolab.com (unknown [10.9.13.1]) by ext-mx-out001.mykolab.com (Postfix) with ESMTPS id 1EF13AB8; Sat, 6 Jun 2020 23:26:25 +0200 (CEST) Received: from ext-subm003.mykolab.com (unknown [10.9.6.3]) by int-mx001.mykolab.com (Postfix) with ESMTPS id 9DB03561; Sat, 6 Jun 2020 23:26:25 +0200 (CEST) From: Thomas Rodgers To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 3/4] Adjust wait logic to limit spurious eval of wait predicate. Date: Sat, 6 Jun 2020 14:26:21 -0700 Message-Id: <20200606212621.1611106-1-rodgert@appliantology.com> MIME-Version: 1.0 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: trodgers@redhat.com Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" * include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup logic. --- libstdc++-v3/include/bits/atomic_wait.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h index 92c1e2526ed..cce11ae1cf5 100644 --- a/libstdc++-v3/include/bits/atomic_wait.h +++ b/libstdc++-v3/include/bits/atomic_wait.h @@ -138,24 +138,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - _M_do_wait(__platform_wait_t __version) noexcept + _M_do_wait(__platform_wait_t __old) noexcept { + __platform_wait_t __cur; + __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE); + while (__cur == __old) + { #ifdef _GLIBCXX_HAVE_LINUX_FUTEX - __platform_wait(&_M_ver, __version); + __platform_wait(&_M_ver, __cur); #else - __platform_wait_t __cur = 0; - while (__cur <= __version) - { __waiters::__lock_t __l(_M_mtx); auto __e = __gthread_cond_wait(&_M_cv, __l.mutex()->native_handle()); if (__e) std::terminate(); - __platform_wait_t __last = __cur; +#endif __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE); - if (__cur < __last) - break; // break the loop if version overflows } -#endif } __platform_wait_t