From: Thomas Rodgers Date: Tue, 1 Dec 2020 23:41:08 +0000 (-0800) Subject: Add feature test macro for atomic::wait X-Git-Tag: upstream/12.2.0~11322 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6591e422692d80d066bacdcdafea2f864d8259c6;p=platform%2Fupstream%2Fgcc.git 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. --- diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index d0d962d..89f66a2 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 f3a07a3..6dd1a14 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 a59ed8c..5efd96d 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 f298423..0ed1f58 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 664af02..4a9b001 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 2684b72..d4a00c4 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 184c7c2..ff83a56 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 0f2da8a..4bb45b7 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 0000000..7b183b2 --- /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 0000000..249bf2d --- /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 + +