public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Rodgers <rodgertq@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-5977] libstdc++: Add missing free functions for atomic_flag [PR103934] Date: Tue, 14 Feb 2023 01:47:28 +0000 (GMT) [thread overview] Message-ID: <20230214014728.C35973858280@sourceware.org> (raw) 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; }
reply other threads:[~2023-02-14 1:47 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230214014728.C35973858280@sourceware.org \ --to=rodgertq@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).