From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2062) id CC3203858C2C; Fri, 22 Apr 2022 22:54:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC3203858C2C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Thomas Rodgers To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-9931] libstdc++: Make atomic notify_one and notify_all non-const X-Act-Checkin: gcc X-Git-Author: Thomas W Rodgers X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: afec66b054a7603ef394dc712ccbba37ae645fd9 X-Git-Newrev: 977cbabeb1c1a9a28cc45655bdc693e1594642f0 Message-Id: <20220422225444.CC3203858C2C@sourceware.org> Date: Fri, 22 Apr 2022 22:54:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 22:54:44 -0000 https://gcc.gnu.org/g:977cbabeb1c1a9a28cc45655bdc693e1594642f0 commit r11-9931-g977cbabeb1c1a9a28cc45655bdc693e1594642f0 Author: Thomas W Rodgers Date: Fri Apr 22 15:46:19 2022 -0700 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: PR libstdc++/102994 * 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. (cherry picked from commit 7c21556daf385fe9ece37319f574776dd7d8ab1c) Diff: --- libstdc++-v3/include/bits/atomic_base.h | 8 ++++---- libstdc++-v3/include/std/atomic | 16 ++++++++-------- .../testsuite/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 315f5a25e93..2abdc400260 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 e9d906f2485..0d4e3a7396e 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 @@ -653,11 +653,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 __pointer_type @@ -1429,12 +1429,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);