public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Make atomic notify_one and notify_all non-const
@ 2022-02-11 17:39 Thomas Rodgers
  2022-02-11 20:22 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Rodgers @ 2022-02-11 17:39 UTC (permalink / raw)
  To: libstdc++; +Cc: gcc Patches

[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]

<recording this here for future reference>
PR102994 "atomics: std::atomic<ptr>::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<bool>::notify_one, notify_all):
        Likewise.
        (atomic::notify_one, notify_all): Likewise.
        (atomic<T*>::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.

[-- Attachment #2: 0001-libstdc-Make-atomic-notify_one-and-notify_all-non-co.patch --]
[-- Type: text/x-patch, Size: 5528 bytes --]

From 7ed6dfae5a0a7a9e56291d780e44f99d644847e0 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers <rodgert@appliantology.com>
Date: Thu, 10 Feb 2022 18:55:16 -0800
Subject: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const

<recording this here for future reference>
PR102994 "atomics: std::atomic<ptr>::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<bool>::notify_one, notify_all):
	Likewise.
	(atomic::notify_one, notify_all): Likewise.
	(atomic<T*>::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<typename _Tp>
     inline void
-    atomic_notify_one(const atomic<_Tp>* __a) noexcept
+    atomic_notify_one(atomic<_Tp>* __a) noexcept
     { __a->notify_one(); }
 
   template<typename _Tp>
     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 <atomic>
 
 void
-test1(const std::atomic<char*>& a, char* p)
+test1(std::atomic<char*>& a, char* p)
 {
   a.wait(p);
 }
 
 void
-test2(const std::atomic<int>* a, int v)
+test2(std::atomic<int>* a, int v)
 {
   std::atomic_wait(a, v);
   std::atomic_notify_one(a);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const
  2022-02-11 17:39 [PATCH] libstdc++: Make atomic notify_one and notify_all non-const Thomas Rodgers
@ 2022-02-11 20:22 ` Jonathan Wakely
  2022-04-22 22:55   ` Thomas Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2022-02-11 20:22 UTC (permalink / raw)
  To: Thomas Rodgers; +Cc: libstdc++, gcc Patches

On Fri, 11 Feb 2022 at 17:40, Thomas Rodgers via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> <recording this here for future reference>
> PR102994 "atomics: std::atomic<ptr>::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:

Might as well add a "PR libstdc++/102994" here to the bug gets updated
automatically.

OK for trunk with that change.

>         * 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<bool>::notify_one, notify_all):
>         Likewise.
>         (atomic::notify_one, notify_all): Likewise.
>         (atomic<T*>::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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const
  2022-02-11 20:22 ` Jonathan Wakely
@ 2022-04-22 22:55   ` Thomas Rodgers
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Rodgers @ 2022-04-22 22:55 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc Patches

Committed to trunk, backported to releases/gcc-11.

On Fri, Feb 11, 2022 at 12:22 PM Jonathan Wakely <jwakely@redhat.com> wrote:

> On Fri, 11 Feb 2022 at 17:40, Thomas Rodgers via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > <recording this here for future reference>
> > PR102994 "atomics: std::atomic<ptr>::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:
>
> Might as well add a "PR libstdc++/102994" here to the bug gets updated
> automatically.
>
> OK for trunk with that change.
>
> >         * 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<bool>::notify_one, notify_all):
> >         Likewise.
> >         (atomic::notify_one, notify_all): Likewise.
> >         (atomic<T*>::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.
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-22 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 17:39 [PATCH] libstdc++: Make atomic notify_one and notify_all non-const Thomas Rodgers
2022-02-11 20:22 ` Jonathan Wakely
2022-04-22 22:55   ` Thomas Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).