libstdc++: Add missing free functions for atomic_flag [PR103934]
authorThomas W Rodgers <rodgert@twrodgers.com>
Fri, 10 Feb 2023 18:09:06 +0000 (10:09 -0800)
committerThomas W Rodgers <rodgert@twrodgers.com>
Tue, 14 Feb 2023 01:46:59 +0000 (17:46 -0800)
This patch adds -
  atomic_flag_wait
  atomic_flag_wait_explicit
  atomic_flag_notify
  atomic_flag_notify_explicit

Which were missed when commit 83a1be introduced C++20 atomic wait.

libstdc++-v3/ChangeLog:

PR libstdc++/103934
* include/std/atomic (atomic_flag_wait): Add.
(atomic_flag_wait_explicit): Add.
(atomic_flag_notify): Add.
(atomic_flag_notify_explicit): Add.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc:
Add test case to cover missing atomic_flag free functions.

libstdc++-v3/include/std/atomic
libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc

index 1edd3ae..96e87de 100644 (file)
@@ -1259,6 +1259,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   atomic_flag_clear(volatile atomic_flag* __a) noexcept
   { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
 
+#if __cpp_lib_atomic_wait
+  inline void
+  atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
+  { __a->wait(__old); }
+
+  inline void
+  atomic_flag_wait_explicit(atomic_flag* __a, bool __old,
+                                memory_order __m) noexcept
+  { __a->wait(__old, __m); }
+
+  inline void
+  atomic_flag_notify_one(atomic_flag* __a) noexcept
+  { __a->notify_one(); }
+
+  inline void
+  atomic_flag_notify_all(atomic_flag* __a) noexcept
+  { __a->notify_all(); }
+#endif // __cpp_lib_atomic_wait
+
   /// @cond undocumented
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
index 240fb42..777fa91 100644 (file)
@@ -26,8 +26,8 @@
 
 #include <testsuite_hooks.h>
 
-int
-main()
+void
+test01()
 {
   std::atomic_flag a;
   VERIFY( !a.test() );
@@ -39,5 +39,27 @@ main()
     });
   a.wait(false);
   t.join();
+}
+
+void
+test02()
+{
+  std::atomic_flag a;
+  VERIFY( !std::atomic_flag_test(&a) );
+  std::atomic_flag_wait(&a, true);
+  std::thread t([&]
+    {
+      std::atomic_flag_test_and_set(&a);
+      std::atomic_flag_notify_one(&a);
+    });
+    std::atomic_flag_wait(&a, false);
+    t.join();
+}
+
+int
+main()
+{
+  test01();
+  test02();
   return 0;
 }