From patchwork Fri Feb 11 17:39:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Rodgers X-Patchwork-Id: 51053 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E58B3858025 for ; Fri, 11 Feb 2022 17:40:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E58B3858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644601223; bh=+cP1pDykW/nvXL4nhbujp8aOi7TcdRR5w2et9T/yGtM=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=EKVZkOiMJshbgN72pr9L7aDFILqiupsPOQDqsuuB3vFMhK8+U4QzBpKYXjkludGlW qv1hrTS1aNrCHYIj1/s13+RWxgv9EnSRF2xyen3FJOF8voRLp8/huJO2lJKswrI94K iVajJfWZnDLWdsoXuDFWQDusRxtgtC0uUrbFj1R8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 00964385841B for ; Fri, 11 Feb 2022 17:39:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00964385841B Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-pliuhkF8NPS1iB_5VudTtA-1; Fri, 11 Feb 2022 12:39:20 -0500 X-MC-Unique: pliuhkF8NPS1iB_5VudTtA-1 Received: by mail-oi1-f199.google.com with SMTP id f16-20020a05680814d000b002cfed37e01fso2555484oiw.17 for ; Fri, 11 Feb 2022 09:39:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=KdSK3VAhZ1c5FZd4FI0sL2GxIBzY3PL8kcahUrxqWCo=; b=XlvVYGNSLPl1GcNupi7l8kM7l/VrOJv/4AvGZTWmxplbePt7D7O5PMGzSA/vTXTA3O qGAyjOK9JzFVkPfGCYbqzGNeoh+vvG8O52aIC4bBZzWBJzj8ujWZgM8dGsPeFsWnXLmJ QS1f2GqkWQsTwK/cUqFy7mcMCHUDbm1Ra2+O36AZr+4ldeDDYVbGrJgx2JIsN7Qvq9Hy Dfvj8ejLnwS+3uniB81PzHYqEQwDQCaBqg6wAx0QHfpNgW/Gb77sa3E3CcuEOqEtOdDf Ly/9UqRGpuBW9EwqonPYNf2jHN6BLR/3hI/45vFhVgqzznsCxudIC/HEHu2H9esylZmV /8qg== X-Gm-Message-State: AOAM5314tZcffyU5C4OSRAI9qQxmC7EuK2J3XAplw/UQW8QWpC2XuwTK cKhimqjVyEo4SF/XAZvgv3nrbwtsKpjcxBMcuVRfWOuXHnwVYOl9bGv+Ev5On88HShaD5KS3NNJ B8l7B1nbZCfdQk4ey4jnOv7hGOjxLcqaSUA== X-Received: by 2002:a9d:4e03:: with SMTP id p3mr1006282otf.299.1644601159083; Fri, 11 Feb 2022 09:39:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2s/6Wr9xOteZKuJ1VuBsj1+5sbRigie4td/t0ErUK9RFOScjDyRWcxCc8nHMN2OoR/nzU+nbuPhaMTs8Dkto= X-Received: by 2002:a9d:4e03:: with SMTP id p3mr1006267otf.299.1644601158814; Fri, 11 Feb 2022 09:39:18 -0800 (PST) MIME-Version: 1.0 Date: Fri, 11 Feb 2022 09:39:08 -0800 Message-ID: Subject: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const To: "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URI_HEX autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , X-Patchwork-Original-From: Thomas Rodgers via Gcc-patches From: Thomas Rodgers Reply-To: Thomas Rodgers Cc: gcc Patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" PR102994 "atomics: std::atomic::wait is not marked const" raises the issue that the current libstdc++ implementation marks the notify members const, the implementation strategy used by libstdc++, as well as libc++ and the Microsoft STL, do not require the atomic to be mutable (it is hard to conceive of a desirable implementation approach that would require it). The original paper proposing the wait/notify functionality for atomics (p1185) also had these members marked const for the first three revisions, but that was changed without explanation in r3 and subsequent revisions of the paper. After raising the issue to the authors of p1185 and the author of the libc++ implementation, the consensus seems to be "meh, it's harmless" so there seems little appetite for an LWG issue to revisit the subject. This patch changes the libstdc++ implementation to be in agreement with the standard by removing const from those notify_one/notify_all members. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (atomic_flag::notify_one, notify_all): Remove const qualification. (__atomic_base::notify_one, notify_all): Likewise. * include/std/atomic (atomic::notify_one, notify_all): Likewise. (atomic::notify_one, notify_all): Likewise. (atomic::notify_one, notify_all): Likewise. (atomic_notify_one, atomic_notify_all): Likewise. * testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test to account for change in notify_one/notify_all signature. Tested x86_64-pc-linux-gnu. From 7ed6dfae5a0a7a9e56291d780e44f99d644847e0 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Thu, 10 Feb 2022 18:55:16 -0800 Subject: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const PR102994 "atomics: std::atomic::wait is not marked const" raises the issue that the current libstdc++ implementation marks the notify members const, the implementation strategy used by libstdc++, as well as libc++ and the Microsoft STL, do not require the atomic to be mutable (it is hard to conceive of a desirable implementation approach that would require it). The original paper proposing the wait/notify functionality for atomics (p1185) also had these members marked const for the first three revisions, but that was changed without explanation in r3 and subsequent revisions of the paper. After raising the issue to the authors of p1185 and the author of the libc++ implementation, the consensus seems to be "meh, it's harmless" so there seems little appetite for an LWG issue to revisit the subject. This patch changes the libstdc++ implementation to be in agreement with the standard by removing const from those notify_one/notify_all members. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (atomic_flag::notify_one, notify_all): Remove const qualification. (__atomic_base::notify_one, notify_all): Likewise. * include/std/atomic (atomic::notify_one, notify_all): Likewise. (atomic::notify_one, notify_all): Likewise. (atomic::notify_one, notify_all): Likewise. (atomic_notify_one, atomic_notify_all): Likewise. * testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test to account for change in notify_one/notify_all signature. --- libstdc++-v3/include/bits/atomic_base.h | 8 ++++---- libstdc++-v3/include/std/atomic | 16 ++++++++-------- .../29_atomics/atomic/wait_notify/102994.cc | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index d86766cf39b..adfd9fa3027 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -252,13 +252,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO add const volatile overload _GLIBCXX_ALWAYS_INLINE void - notify_one() const noexcept + notify_one() noexcept { std::__atomic_notify_address(&_M_i, false); } // TODO add const volatile overload _GLIBCXX_ALWAYS_INLINE void - notify_all() const noexcept + notify_all() noexcept { std::__atomic_notify_address(&_M_i, true); } // TODO add const volatile overload @@ -600,13 +600,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO add const volatile overload _GLIBCXX_ALWAYS_INLINE void - notify_one() const noexcept + notify_one() noexcept { std::__atomic_notify_address(&_M_i, false); } // TODO add const volatile overload _GLIBCXX_ALWAYS_INLINE void - notify_all() const noexcept + notify_all() noexcept { std::__atomic_notify_address(&_M_i, true); } // TODO add const volatile overload diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index bc57659b6e7..d819b6bf41e 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -172,11 +172,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO add const volatile overload void - notify_one() const noexcept + notify_one() noexcept { _M_base.notify_one(); } void - notify_all() const noexcept + notify_all() noexcept { _M_base.notify_all(); } #endif // __cpp_lib_atomic_wait }; @@ -399,11 +399,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO add const volatile overload void - notify_one() const noexcept + notify_one() noexcept { std::__atomic_notify_address(&_M_i, false); } void - notify_all() const noexcept + notify_all() noexcept { std::__atomic_notify_address(&_M_i, true); } #endif // __cpp_lib_atomic_wait @@ -654,11 +654,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO add const volatile overload void - notify_one() const noexcept + notify_one() noexcept { _M_b.notify_one(); } void - notify_all() const noexcept + notify_all() noexcept { _M_b.notify_all(); } #endif // __cpp_lib_atomic_wait @@ -1434,12 +1434,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline void - atomic_notify_one(const atomic<_Tp>* __a) noexcept + atomic_notify_one(atomic<_Tp>* __a) noexcept { __a->notify_one(); } template inline void - atomic_notify_all(const atomic<_Tp>* __a) noexcept + atomic_notify_all(atomic<_Tp>* __a) noexcept { __a->notify_all(); } #endif // __cpp_lib_atomic_wait diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc index 9d92ff954f1..f572ce7ef11 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc @@ -5,13 +5,13 @@ #include void -test1(const std::atomic& a, char* p) +test1(std::atomic& a, char* p) { a.wait(p); } void -test2(const std::atomic* a, int v) +test2(std::atomic* a, int v) { std::atomic_wait(a, v); std::atomic_notify_one(a); -- 2.34.1