public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Rodgers <rodgertq@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-5886] libstdc++: Make atomic<T*>::wait() const [PR102994]
Date: Fri, 10 Dec 2021 01:57:37 +0000 (GMT)	[thread overview]
Message-ID: <20211210015737.2746E3858403@sourceware.org> (raw)

https://gcc.gnu.org/g:38c60e5075f89265a560eab166d43247624a7535

commit r12-5886-g38c60e5075f89265a560eab166d43247624a7535
Author: Thomas Rodgers <rodgert@twrodgers.com>
Date:   Thu Dec 9 15:35:25 2021 -0800

    libstdc++: Make atomic<T*>::wait() const [PR102994]
    
    This was an oversight in the original commit adding wait/notify
    to atomic<T>.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/102994
            * include/bits/atomic_base.h (__atomic_base<_PTp*>::wait()):
            Add const qualifier.
            * include/std/atomic (atomic<_Tp*>::wait(), atomic_wait()):
            Likewise.
            * testsuite/29_atomics/atomic/wait_notify/102994.cc:
            New test.

Diff:
---
 libstdc++-v3/include/bits/atomic_base.h               |  2 +-
 libstdc++-v3/include/std/atomic                       |  8 ++++----
 .../testsuite/29_atomics/atomic/wait_notify/102994.cc | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 9e18aadadaf..a104adc1a10 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cpp_lib_atomic_wait
       _GLIBCXX_ALWAYS_INLINE void
       wait(__pointer_type __old,
-	   memory_order __m = memory_order_seq_cst) noexcept
+	   memory_order __m = memory_order_seq_cst) const noexcept
       {
 	std::__atomic_wait_address_v(&_M_p, __old,
 				     [__m, this]
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 936dd50ba1c..9b827b425dc 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -646,9 +646,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 					    __cmpexch_failure_order(__m));
       }
 
-#if __cpp_lib_atomic_wait 
+#if __cpp_lib_atomic_wait
     void
-    wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) noexcept
+    wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
     { _M_b.wait(__old, __m); }
 
     // TODO add const volatile overload
@@ -1434,12 +1434,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Tp>
     inline void
-    atomic_notify_one(atomic<_Tp>* __a) noexcept
+    atomic_notify_one(const atomic<_Tp>* __a) noexcept
     { __a->notify_one(); }
 
   template<typename _Tp>
     inline void
-    atomic_notify_all(atomic<_Tp>* __a) noexcept
+    atomic_notify_all(const 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
new file mode 100644
index 00000000000..9d92ff954f1
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc
@@ -0,0 +1,19 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+// { dg-require-gthreads "" }
+
+#include <atomic>
+
+void
+test1(const std::atomic<char*>& a, char* p)
+{
+  a.wait(p);
+}
+
+void
+test2(const std::atomic<int>* a, int v)
+{
+  std::atomic_wait(a, v);
+  std::atomic_notify_one(a);
+  std::atomic_notify_all(a);
+}


                 reply	other threads:[~2021-12-10  1:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211210015737.2746E3858403@sourceware.org \
    --to=rodgertq@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).