From: Thomas Rodgers <trodgers@redhat.com>
To: "libstdc++" <libstdc++@gcc.gnu.org>,
gcc Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] libstdc++: Add missing free functions for atomic_flag [PR103934]
Date: Fri, 14 Jan 2022 18:53:30 -0800 [thread overview]
Message-ID: <CAMmuTO-PCj=F4QR8c3zoa9zW+CqLVYXG=JxT_ssYbaL+rzj+RQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0001-libstdc-Add-missing-free-functions-for-atomic_flag-P.patch --]
[-- Type: text/x-patch, Size: 3267 bytes --]
From c2b74fd7cf2668d288f46da42565e5eb954e5e1f Mon Sep 17 00:00:00 2001
From: Thomas Rodgers <rodgert@twrodgers.com>
Date: Fri, 14 Jan 2022 18:30:27 -0800
Subject: [PATCH] libstdc++: Add missing free functions for atomic_flag
[PR103934]
libstdc++-v3/ChangeLog:
PR103934
* include/std/atomic: Add missing free functions.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc:
Add test case to cover missing atomic_flag free functions.
---
libstdc++-v3/include/std/atomic | 39 +++++++++++++++++++
.../29_atomics/atomic_flag/wait_notify/1.cc | 27 +++++++++++--
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 9df17704f7e..92c96a9b047 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); }
@@ -1241,6 +1261,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(const atomic_flag* __a, bool __old) noexcept
+ { __a->wait(__old); }
+
+ inline void
+ atomic_flag_wait_explicit(const atomic_flag* __a, bool __old,
+ std::memory_order __m) noexcept
+ { __a->wait(__old, __m); }
+
+ inline void
+ atomic_flag_notify_one(const atomic_flag* __a) noexcept
+ { __a->notify_one(); }
+
+ inline void
+ atomic_flag_notify_all(const atomic_flag* __a) noexcept
+ { __a->notify_all(); }
+#endif // __cpp_lib_atomic_wait
+
template<typename _Tp>
using __atomic_val_t = typename atomic<_Tp>::value_type;
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..1050b72a1c6 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,26 @@ main()
});
a.wait(false);
t.join();
- return 0;
+}
+
+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();
}
--
2.31.1
next reply other threads:[~2022-01-15 2:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-15 2:53 Thomas Rodgers [this message]
2022-02-02 21:35 ` Jonathan Wakely
2023-02-10 18:25 ` Thomas Rodgers
2023-02-11 0:41 ` Jonathan Wakely
2023-02-14 2:06 ` Thomas Rodgers
2023-03-10 2:39 ` Thomas Rodgers
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='CAMmuTO-PCj=F4QR8c3zoa9zW+CqLVYXG=JxT_ssYbaL+rzj+RQ@mail.gmail.com' \
--to=trodgers@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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: link
Be 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).