From 491ba663e05887c0353edf571be36e8f04183df3 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 12 May 2020 07:37:09 +0200 Subject: [PATCH] Implent C++20 std::atomic_flag::test * include/bits/atomic_base.h (atomic_flag): Implement test member function. * include/std/version: Define __cpp_lib_atomic_flag_test. * testsuite/29_atomics/atomic_flag/test/explicit.cc: New file. * testsuite/29_atomics/atomic_flag/test/implicit.cc: New file. --- libstdc++-v3/ChangeLog | 8 ++++++++ libstdc++-v3/include/bits/atomic_base.h | 20 ++++++++++++++++++++ libstdc++-v3/include/std/version | 1 + 3 files changed, 29 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a2ff49d9e51..3264fd4c481 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2020-05-08 Ulrich Drepper + + * include/bits/atomic_base.h (atomic_flag): Implement test member + function. + * include/std/version: Define __cpp_lib_atomic_flag_test. + * testsuite/29_atomics/atomic_flag/test/explicit.cc: New file. + * testsuite/29_atomics/atomic_flag/test/implicit.cc: New file. + 2020-05-07 Jonathan Wakely PR libstdc++/94971 (partial) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index 87fe0bd6000..3b66b040976 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -208,6 +208,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __atomic_test_and_set (&_M_i, int(__m)); } +#if __cplusplus > 201703L +#define __cpp_lib_atomic_flag_test 201907L + + _GLIBCXX_ALWAYS_INLINE bool + test(memory_order __m = memory_order_seq_cst) noexcept + { + __atomic_flag_data_type __v; + __atomic_load(&_M_i, &__v, int(__m)); + return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL; + } + + _GLIBCXX_ALWAYS_INLINE bool + test(memory_order __m = memory_order_seq_cst) volatile noexcept + { + __atomic_flag_data_type __v; + __atomic_load(&_M_i, &__v, int(__m)); + return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL; + } +#endif // C++20 + _GLIBCXX_ALWAYS_INLINE void clear(memory_order __m = memory_order_seq_cst) noexcept { diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index c3a5bd26e63..c6bde2cfbda 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -164,6 +164,7 @@ #if __cplusplus > 201703L // c++2a +#define __cpp_lib_atomic_flag_test 201907L #define __cpp_lib_atomic_float 201711L #define __cpp_lib_atomic_ref 201806L #define __cpp_lib_atomic_value_initialization 201911L -- 2.30.2