]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add missing free functions for atomic_flag [PR103934]
authorThomas W Rodgers <rodgert@twrodgers.com>
Fri, 10 Feb 2023 17:35:11 +0000 (09:35 -0800)
committerThomas W Rodgers <rodgert@twrodgers.com>
Tue, 14 Feb 2023 01:53:37 +0000 (17:53 -0800)
This patch adds -
  atomic_flag_test
  atomic_flag_test_explicit

Which were missed when commit 491ba6 introduced C++20 atomic flag
test.

libstdc++-v3/ChangeLog:

PR libstdc++/103934
* include/std/atomic (atomic_flag_test): Add.
(atomic_flag_test_explicit): Add.
* testsuite/29_atomics/atomic_flag/test/explicit.cc: Add
test case to cover missing atomic_flag free functions.
* testsuite/29_atomics/atomic_flag/test/implicit.cc:
Likewise.

(cherry picked from commit a8d769045b43e8509490362865a85cb31a855ccf)

libstdc++-v3/include/std/atomic
libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc

index cf5d730933468095fdae93168e034d4f7e874b01..9e042d8ce448f53e1ffedcb9b60f77089e46c4db 100644 (file)
@@ -1216,6 +1216,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                                    memory_order __m) noexcept
   { return __a->test_and_set(__m); }
 
+#if __cpp_lib_atomic_flag_test
+  inline bool
+  atomic_flag_test(const atomic_flag* __a) noexcept
+  { return __a->test(); }
+
+  inline bool
+  atomic_flag_test(const volatile atomic_flag* __a) noexcept
+  { return __a->test(); }
+
+  inline bool
+  atomic_flag_test_explicit(const atomic_flag* __a,
+                           memory_order __m) noexcept
+  { return __a->test(__m); }
+
+  inline bool
+  atomic_flag_test_explicit(const volatile atomic_flag* __a,
+                           memory_order __m) noexcept
+  { return __a->test(__m); }
+#endif
+
   inline void
   atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
   { __a->clear(__m); }
index f4a42cce930aabf76726bd1d565c9f88814a5011..6cb2d1bfdf85ceab3e8ea4d907aca51d98767c5e 100644 (file)
@@ -22,7 +22,8 @@
 #include <atomic>
 #include <testsuite_hooks.h>
 
-int main()
+void
+test01()
 {
   using namespace std;
 
@@ -38,3 +39,26 @@ int main()
   VERIFY( ! af.test(memory_order_acquire) );
   VERIFY( ! caf.test(memory_order_acquire) );
 }
+
+void
+test02()
+{
+  using namespace std;
+
+  atomic_flag af{true};
+  const atomic_flag& caf = af;
+
+  VERIFY( atomic_flag_test_explicit(&af, memory_order_acquire) );
+  VERIFY( atomic_flag_test_explicit(&caf, memory_order_acquire) );
+  af.clear(memory_order_release);
+  VERIFY( ! atomic_flag_test_explicit(&af, memory_order_acquire) );
+  VERIFY( ! atomic_flag_test_explicit(&caf, memory_order_acquire) );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  return 0;
+}
index 6dc83d16da7a9d30818869910e59c77798d843ae..9919732bc8aef20a6d3faa7876b084f68dd102e9 100644 (file)
@@ -22,7 +22,8 @@
 #include <atomic>
 #include <testsuite_hooks.h>
 
-int main()
+void
+test01()
 {
   using namespace std;
 
@@ -38,3 +39,26 @@ int main()
   VERIFY( ! af.test() );
   VERIFY( ! caf.test() );
 }
+
+void
+test02()
+{
+  using namespace std;
+
+  atomic_flag af{true};
+  const atomic_flag& caf = af;
+
+  VERIFY( atomic_flag_test(&af) );
+  VERIFY( atomic_flag_test(&caf) );
+  af.clear(memory_order_release);
+  VERIFY( ! atomic_flag_test(&af) );
+  VERIFY( ! atomic_flag_test(&caf) );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  return 0;
+}