From 6591e422692d80d066bacdcdafea2f864d8259c6 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Tue, 1 Dec 2020 15:41:08 -0800 Subject: [PATCH] Add feature test macro for atomic::wait Adds __cpp_lib_atomic_wait feature test macro which was overlooked in the initial commit of this feature. Replaces uses of _GLIBCXX_HAVE_ATOMIC_WAIT. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h: Replace usage of _GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait. * include/bits/atomic_timed_wait.h: Likewise. * include/bits/atomic_wait.h: Define __cpp_lib_atomic_wait feature test macro. * include/bits/semaphore_base.h: Replace usage of _GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait. * include/std/atomic: Likewise. * include/std/latch: Likewise. * include/std/semaphore: Likewise. * include/std/version: Define __cpp_lib_atomic wait feature test macro and replace usage of _GLIBCXX_HAVE_ATOMIC_WAIT. * testsuite/29_atomics/atomic/wait_notify/1.cc: New test. * testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise. --- libstdc++-v3/include/bits/atomic_base.h | 36 +++++++++---------- libstdc++-v3/include/bits/atomic_timed_wait.h | 5 +-- libstdc++-v3/include/bits/atomic_wait.h | 3 +- libstdc++-v3/include/bits/semaphore_base.h | 4 +-- libstdc++-v3/include/std/atomic | 16 ++++----- libstdc++-v3/include/std/latch | 4 +-- libstdc++-v3/include/std/semaphore | 4 +-- libstdc++-v3/include/std/version | 7 ++-- .../29_atomics/atomic/wait_notify/1.cc | 29 +++++++++++++++ .../29_atomics/atomic/wait_notify/2.cc | 30 ++++++++++++++++ 10 files changed, 100 insertions(+), 38 deletions(-) create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/1.cc create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/2.cc diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index d0d962d3047..89f66a23ab6 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -230,7 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL; } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(bool __old, memory_order __m = memory_order_seq_cst) const noexcept @@ -253,7 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::__atomic_notify(&_M_i, true); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait #endif // C++20 _GLIBCXX_ALWAYS_INLINE void @@ -604,7 +604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__m)); } -#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(__int_type __old, memory_order __m = memory_order_seq_cst) const noexcept @@ -627,7 +627,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::__atomic_notify(&_M_i, true); } // TODO add const volatile overload -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE __int_type fetch_add(__int_type __i, @@ -898,7 +898,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION int(__m1), int(__m2)); } -#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) noexcept @@ -921,7 +921,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::__atomic_notify(&_M_p, true); } // TODO add const volatile overload -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE __pointer_type fetch_add(ptrdiff_t __d, @@ -1011,7 +1011,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION int(__success), int(__failure)); } -#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait template _GLIBCXX_ALWAYS_INLINE void wait(const _Tp* __ptr, _Val<_Tp> __old, @@ -1036,7 +1036,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::__atomic_notify(__ptr, true); } // TODO add const volatile overload -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait template _GLIBCXX_ALWAYS_INLINE _Tp @@ -1291,7 +1291,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__order)); } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(_Fp __old, memory_order __m = memory_order_seq_cst) const noexcept { __atomic_impl::wait(&_M_fp, __old, __m); } @@ -1309,7 +1309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __atomic_impl::notify_all(&_M_fp); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait value_type fetch_add(value_type __i, @@ -1448,7 +1448,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__order)); } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept { __atomic_impl::wait(_M_ptr, __old, __m); } @@ -1466,7 +1466,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __atomic_impl::notify_all(_M_ptr); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait private: _Tp* _M_ptr; @@ -1563,7 +1563,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__order)); } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept { __atomic_impl::wait(_M_ptr, __old, __m); } @@ -1581,7 +1581,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __atomic_impl::notify_all(_M_ptr); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait value_type fetch_add(value_type __i, @@ -1738,7 +1738,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__order)); } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(_Fp __old, memory_order __m = memory_order_seq_cst) const noexcept { __atomic_impl::wait(_M_ptr, __old, __m); } @@ -1756,7 +1756,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __atomic_impl::notify_all(_M_ptr); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait value_type fetch_add(value_type __i, @@ -1867,7 +1867,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__order)); } -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE void wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept { __atomic_impl::wait(_M_ptr, __old, __m); } @@ -1885,7 +1885,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __atomic_impl::notify_all(_M_ptr); } // TODO add const volatile overload -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait _GLIBCXX_ALWAYS_INLINE value_type fetch_add(difference_type __d, diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h b/libstdc++-v3/include/bits/atomic_timed_wait.h index f3a07a36722..6dd1a145e69 100644 --- a/libstdc++-v3/include/bits/atomic_timed_wait.h +++ b/libstdc++-v3/include/bits/atomic_timed_wait.h @@ -33,7 +33,8 @@ #pragma GCC system_header #include -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT + +#ifdef __cpp_lib_atomic_wait #include #include @@ -292,5 +293,5 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait #endif // _GLIBCXX_ATOMIC_TIMED_WAIT_H diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h index a59ed8cb418..5efd96d22a1 100644 --- a/libstdc++-v3/include/bits/atomic_wait.h +++ b/libstdc++-v3/include/bits/atomic_wait.h @@ -50,8 +50,7 @@ # include // std::mutex, std::__condvar #endif -// Other headers use this to check for the facilities defined in this header. -#define _GLIBCXX_HAVE_ATOMIC_WAIT 1 +#define __cpp_lib_atomic_wait 201907L namespace std _GLIBCXX_VISIBILITY(default) { diff --git a/libstdc++-v3/include/bits/semaphore_base.h b/libstdc++-v3/include/bits/semaphore_base.h index f2984236e03..0ed1f5895af 100644 --- a/libstdc++-v3/include/bits/semaphore_base.h +++ b/libstdc++-v3/include/bits/semaphore_base.h @@ -33,7 +33,7 @@ #pragma GCC system_header #include -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#ifdef __cpp_lib_atomic_wait #include #include @@ -297,5 +297,5 @@ template _GLIBCXX_END_NAMESPACE_VERSION } // namespace std -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait #endif // _GLIBCXX_SEMAPHORE_BASE_H diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 664af023d77..4a9b00182a3 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -164,7 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order __m = memory_order_seq_cst) volatile noexcept { return _M_base.compare_exchange_strong(__i1, __i2, __m); } -#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait void wait(bool __old, memory_order __m = memory_order_seq_cst) const noexcept { _M_base.wait(__old, __m); } @@ -178,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void notify_all() const noexcept { _M_base.notify_all(); } -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait }; #if __cplusplus <= 201703L @@ -380,7 +380,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return compare_exchange_strong(__e, __i, __m, __cmpexch_failure_order(__m)); } -#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait void wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept { @@ -404,7 +404,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void notify_all() const noexcept { std::__atomic_notify(&_M_i, true); } -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait }; #undef _GLIBCXX20_INIT @@ -644,7 +644,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __cmpexch_failure_order(__m)); } -#if __cplusplus > 201703L && _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait void wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) noexcept { _M_b.wait(__old, __m); } @@ -658,7 +658,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void notify_all() const noexcept { _M_b.notify_all(); } -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait __pointer_type fetch_add(ptrdiff_t __d, memory_order __m = memory_order_seq_cst) noexcept @@ -1412,7 +1412,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } -#if __cplusplus > 201703L && _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait template inline void atomic_wait(const atomic<_Tp>* __a, @@ -1435,7 +1435,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void atomic_notify_all(atomic<_Tp>* __a) noexcept { __a->notify_all(); } -#endif // C++20 && HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait // Function templates for atomic_integral and atomic_pointer operations only. // Some operations (and, or, xor) are only available for atomic integrals, diff --git a/libstdc++-v3/include/std/latch b/libstdc++-v3/include/std/latch index 2684b72288f..d4a00c4361c 100644 --- a/libstdc++-v3/include/std/latch +++ b/libstdc++-v3/include/std/latch @@ -36,7 +36,7 @@ #include #include -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -89,6 +89,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; _GLIBCXX_END_NAMESPACE_VERSION } // namespace -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait #endif // __cplusplus > 201703L #endif // _GLIBCXX_LATCH diff --git a/libstdc++-v3/include/std/semaphore b/libstdc++-v3/include/std/semaphore index 184c7c2867c..ff83a56af4b 100644 --- a/libstdc++-v3/include/std/semaphore +++ b/libstdc++-v3/include/std/semaphore @@ -33,7 +33,7 @@ #if __cplusplus > 201703L #include -#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT +#if __cpp_lib_atomic_wait #include namespace std _GLIBCXX_VISIBILITY(default) @@ -90,6 +90,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using binary_semaphore = std::counting_semaphore<1>; _GLIBCXX_END_NAMESPACE_VERSION } // namespace -#endif // HAVE_ATOMIC_WAIT +#endif // __cpp_lib_atomic_wait #endif // C++20 #endif // _GLIBCXX_SEMAPHORE diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 0f2da8a5ddd..4bb45b7805c 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -197,6 +197,9 @@ #if _GLIBCXX_HOSTED #define __cpp_lib_array_constexpr 201811L #define __cpp_lib_assume_aligned 201811L +#if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX +# define __cpp_lib_atomic_wait 201907L +#endif #define __cpp_lib_bind_front 201907L // FIXME: #define __cpp_lib_execution 201902L #define __cpp_lib_integer_comparison_functions 202002L @@ -216,7 +219,7 @@ #ifdef _GLIBCXX_HAS_GTHREADS # define __cpp_lib_jthread 201911L #endif -#if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX +#if __cpp_lib_atomic_wait # define __cpp_lib_latch 201907L #endif #define __cpp_lib_list_remove_return_type 201806L @@ -228,7 +231,7 @@ #if __cpp_lib_concepts # define __cpp_lib_ranges 201911L #endif -#if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX +#if __cpp_lib_atomic_wait # define __cpp_lib_semaphore 201907L #endif #define __cpp_lib_shift 201806L diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/1.cc new file mode 100644 index 00000000000..7b183b271db --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/1.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// { dg-require-effective-target gthreads } + +#include + +#ifndef __cpp_lib_atomic_wait +# error "Feature-test macro for atomic wait missing in " +#elif __cpp_lib_atomic_wait != 201907L +# error "Feature-test macro for atomic wait has wrong value in " +#endif + diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/2.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/2.cc new file mode 100644 index 00000000000..249bf2da9f0 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/2.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// { dg-require-effective-target gthreads } + +#include + +#ifndef __cpp_lib_atomic_wait +# error "Feature-test macro for atomic wait missing in " +#elif __cpp_lib_atomic_wait != 201907L +# error "Feature-test macro for atomic wait has wrong value in " +#endif + + -- 2.30.2