Implent C++20 std::atomic_flag::test
authorUlrich Drepper <drepper@gmail.com>
Tue, 12 May 2020 05:37:09 +0000 (07:37 +0200)
committerUlrich Drepper <drepper@gmail.com>
Tue, 12 May 2020 05:37:09 +0000 (07:37 +0200)
        * 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
libstdc++-v3/include/bits/atomic_base.h
libstdc++-v3/include/std/version

index a2ff49d9e5118a05b928dc32117320a26f8e21f3..3264fd4c4819838cb62039d6824522ddb6bc55ec 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-08  Ulrich Drepper  <drepper@redhat.com>
+
+       * 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  <jwakely@redhat.com>
 
        PR libstdc++/94971 (partial)
index 87fe0bd6000ea5bb4f6e86ab174c434f1c9c3b3f..3b66b04097627f6366c774b942e39b14df6fc162 100644 (file)
@@ -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
     {
index c3a5bd26e636b1fb12aacc3a7334ba6ac3d245cc..c6bde2cfbda756257621f2a07b1afb66ee9484da 100644 (file)
 
 #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