public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9238] libstdc++: Add missing free functions for atomic_flag [PR103934]
@ 2023-03-10 2:36 Thomas Rodgers
0 siblings, 0 replies; only message in thread
From: Thomas Rodgers @ 2023-03-10 2:36 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:1784d252cecb0c8f4025ee587af4c29cc0992923
commit r12-9238-g1784d252cecb0c8f4025ee587af4c29cc0992923
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.
(cherry picked from commit 56cf9372c0596c4df4003c72dc4665a306fbfe31)
Diff:
---
libstdc++-v3/include/std/atomic | 24 ++++++++++++++++++--
.../29_atomics/atomic_flag/wait_notify/1.cc | 26 ++++++++++++++++++++--
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 9e042d8ce44..faf7eb95594 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -388,7 +388,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return compare_exchange_strong(__e, __i, __m,
__cmpexch_failure_order(__m)); }
-#if __cpp_lib_atomic_wait
+#if __cpp_lib_atomic_wait
void
wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
{
@@ -405,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
notify_all() noexcept
{ std::__atomic_notify_address(&_M_i, true); }
-#endif // __cpp_lib_atomic_wait
+#endif // __cpp_lib_atomic_wait
};
#undef _GLIBCXX20_INIT
@@ -1261,6 +1261,26 @@ _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
template<typename _Tp>
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 87a104059ff..dbd34609049 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-03-10 2:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 2:36 [gcc r12-9238] 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).