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 r12-9172] libstdc++: Add missing free functions for atomic_flag [PR103934] Date: Tue, 14 Feb 2023 01:59:43 +0000 (GMT) [thread overview] Message-ID: <20230214015943.B68093858D33@sourceware.org> (raw) https://gcc.gnu.org/g:dec869c95562c0b1255f770e68e7ea72e7e92681 commit r12-9172-gdec869c95562c0b1255f770e68e7ea72e7e92681 Author: Thomas W Rodgers <rodgert@twrodgers.com> Date: Fri Feb 10 09:35:11 2023 -0800 libstdc++: Add missing free functions for atomic_flag [PR103934] 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) Diff: --- libstdc++-v3/include/std/atomic | 20 +++++++++++++++++ .../29_atomics/atomic_flag/test/explicit.cc | 26 +++++++++++++++++++++- .../29_atomics/atomic_flag/test/implicit.cc | 26 +++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index cf5d7309334..9e042d8ce44 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -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); } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc index f4a42cce930..6cb2d1bfdf8 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc @@ -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; +} diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc index 6dc83d16da7..9919732bc8a 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc @@ -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; +}
reply other threads:[~2023-02-14 1:59 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=20230214015943.B68093858D33@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).