public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-4612] libstdc++: Define atomic lock-free type aliases for C++20 [PR98034]
Date: Mon, 12 Dec 2022 14:00:55 +0000 (GMT)	[thread overview]
Message-ID: <20221212140055.B13583852C4F@sourceware.org> (raw)

https://gcc.gnu.org/g:320ac807da125e6dc952b3d4abf02daeead88d44

commit r13-4612-g320ac807da125e6dc952b3d4abf02daeead88d44
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Dec 12 12:49:40 2022 +0000

    libstdc++: Define atomic lock-free type aliases for C++20 [PR98034]
    
    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.

Diff:
---
 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(+)

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

                 reply	other threads:[~2022-12-12 14:00 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=20221212140055.B13583852C4F@sourceware.org \
    --to=redi@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: 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).