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.
This commit is contained in:
Thomas Rodgers 2021-12-09 15:35:25 -08:00
parent 35a4fe8091
commit 38c60e5075
3 changed files with 24 additions and 5 deletions

View File

@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cpp_lib_atomic_wait #if __cpp_lib_atomic_wait
_GLIBCXX_ALWAYS_INLINE void _GLIBCXX_ALWAYS_INLINE void
wait(__pointer_type __old, 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, std::__atomic_wait_address_v(&_M_p, __old,
[__m, this] [__m, this]

View File

@ -648,7 +648,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cpp_lib_atomic_wait #if __cpp_lib_atomic_wait
void 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); } { _M_b.wait(__old, __m); }
// TODO add const volatile overload // TODO add const volatile overload
@ -1434,12 +1434,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp> template<typename _Tp>
inline void inline void
atomic_notify_one(atomic<_Tp>* __a) noexcept atomic_notify_one(const atomic<_Tp>* __a) noexcept
{ __a->notify_one(); } { __a->notify_one(); }
template<typename _Tp> template<typename _Tp>
inline void inline void
atomic_notify_all(atomic<_Tp>* __a) noexcept atomic_notify_all(const atomic<_Tp>* __a) noexcept
{ __a->notify_all(); } { __a->notify_all(); }
#endif // __cpp_lib_atomic_wait #endif // __cpp_lib_atomic_wait

View File

@ -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);
}