public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5977] libstdc++: Add missing free functions for atomic_flag [PR103934]
@ 2023-02-14  1:47 Thomas Rodgers
  0 siblings, 0 replies; only message in thread
From: Thomas Rodgers @ 2023-02-14  1:47 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:56cf9372c0596c4df4003c72dc4665a306fbfe31

commit r13-5977-g56cf9372c0596c4df4003c72dc4665a306fbfe31
Author: Thomas W Rodgers <rodgert@twrodgers.com>
Date:   Fri Feb 10 10:09:06 2023 -0800

    libstdc++: Add missing free functions for atomic_flag [PR103934]
    
    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.

Diff:
---
 libstdc++-v3/include/std/atomic                    | 19 ++++++++++++++++
 .../29_atomics/atomic_flag/wait_notify/1.cc        | 26 ++++++++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 1edd3ae16fa..96e87ded864 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -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
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
index 240fb4259f7..777fa915ea1 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
@@ -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;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-14  1:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14  1:47 [gcc r13-5977] libstdc++: Add missing free functions for atomic_flag [PR103934] Thomas Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).