public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Define atomic lock-free type aliases for C++20 [PR98034]
@ 2022-12-12 14:01 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2022-12-12 14:01 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8--

libstdc++-v3/ChangeLog:

	PR libstdc++/98034
	* include/std/atomic (__cpp_lib_atomic_lock_free_type_aliases):
	Define macro.
	(atomic_signed_lock_free, atomic_unsigned_lock_free): Define
	aliases.
	* include/std/version (__cpp_lib_atomic_lock_free_type_aliases):
	Define macro.
	* testsuite/29_atomics/atomic/lock_free_aliases.cc: New test.
---
 libstdc++-v3/include/std/atomic               | 17 ++++++++++
 libstdc++-v3/include/std/version              |  1 +
 .../29_atomics/atomic/lock_free_aliases.cc    | 34 +++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc

diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 356f1458f44..857f9270049 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -1727,6 +1727,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __atomic_ref<_Tp>::operator=;
     };
 
+#define __cpp_lib_atomic_lock_free_type_aliases 201907L
+#ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
+  using atomic_signed_lock_free
+    = atomic<make_signed_t<__detail::__platform_wait_t>>;
+  using atomic_unsigned_lock_free
+    = atomic<make_unsigned_t<__detail::__platform_wait_t>>;
+#elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE)
+  using atomic_signed_lock_free = atomic<signed int>;
+  using atomic_unsigned_lock_free = atomic<unsigned int>;
+#elif ATOMIC_LONG_LOCK_FREE
+  using atomic_signed_lock_free = atomic<signed long>;
+  using atomic_unsigned_lock_free = atomic<unsigned long>;
+#elif ATOMIC_CHAR_LOCK_FREE
+  using atomic_signed_lock_free = atomic<signed char>;
+  using atomic_unsigned_lock_free = atomic<unsigned char>;
+#endif
+
 #endif // C++2a
 
   /// @} group atomics
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 3c7c440bd80..61718ebad74 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -187,6 +187,7 @@
 #define __cpp_lib_assume_aligned 201811L
 #define __cpp_lib_atomic_flag_test 201907L
 #define __cpp_lib_atomic_float 201711L
+#define __cpp_lib_atomic_lock_free_type_aliases 201907L
 #define __cpp_lib_atomic_ref 201806L
 #define __cpp_lib_atomic_value_initialization 201911L
 #define __cpp_lib_bind_front 201907L
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc
new file mode 100644
index 00000000000..02c4ccc3aa3
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc
@@ -0,0 +1,34 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+#include <atomic>
+
+#ifndef __cpp_lib_atomic_lock_free_type_aliases
+# error "Feature test macro for lock-free type aliases is missing in <atomic>"
+#elif __cpp_lib_atomic_lock_free_type_aliases != 201907L
+# error "Feature test macro for lock-free type aliases has wrong value in <atomic>"
+#endif
+
+template<typename T>
+constexpr bool is_atomic_specialization = false;
+template<typename T>
+constexpr bool is_atomic_specialization<std::atomic<T>> = true;
+
+// The type aliases atomic_signed_lock_free and atomic_unsigned_lock_free
+// name specializations of atomic
+static_assert( is_atomic_specialization<std::atomic_signed_lock_free> );
+static_assert( is_atomic_specialization<std::atomic_unsigned_lock_free> );
+
+#include <type_traits>
+
+// ... whose template arguments are integral types,
+static_assert( std::is_integral_v<std::atomic_signed_lock_free::value_type> );
+static_assert( std::is_integral_v<std::atomic_unsigned_lock_free::value_type> );
+
+// ... respectively signed and unsigned,
+static_assert( std::is_signed_v<std::atomic_signed_lock_free::value_type> );
+static_assert( std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type> );
+
+// and whose is_always_lock_free property is true.
+static_assert( std::atomic_signed_lock_free::is_always_lock_free );
+static_assert( std::atomic_unsigned_lock_free::is_always_lock_free );
-- 
2.38.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-12 14:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 14:01 [committed] libstdc++: Define atomic lock-free type aliases for C++20 [PR98034] Jonathan Wakely

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).