From 69737be7cda5328eb0f67c9725c3b691bcb6cb2f Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Tue, 9 Nov 2021 09:42:49 -0800 Subject: [PATCH] libstdc++: Make atomic::wait() const [PR102994] This was an oversight in the original commit adding wait/notify to atomic. libstdc++-v3/ChangeLog: PR libstdc++/102994 * include/bits/atomic_base.h (__atomic_base<_PTp*>::wait()): Add const qualifier. * include/std/atomic (atomic<_Tp*>::wait()): Likewise. * testsuite/29_atomics/atomic/wait_notify/102994.cc: New test. --- libstdc++-v3/include/bits/atomic_base.h | 2 +- libstdc++-v3/include/std/atomic | 4 ++-- .../testsuite/29_atomics/atomic/wait_notify/102994.cc | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc 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..c971b712ef6 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 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..bc814a708aa --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc @@ -0,0 +1,11 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// { dg-require-gthreads "" } + +#include + +void +test_it(const std::atomic &a, char*p) +{ + a.wait(p); +} -- 2.31.1