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)
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); }
#include <atomic>
#include <testsuite_hooks.h>
-int main()
+void
+test01()
{
using namespace std;
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;
+}
#include <atomic>
#include <testsuite_hooks.h>
-int main()
+void
+test01()
{
using namespace std;
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;
+}