public inbox for gcc-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 r14-9371] libstdc++: Do not define lock-free atomic aliases if not fully lock-free [PR114103]
Date: Thu,  7 Mar 2024 21:00:15 +0000 (GMT)	[thread overview]
Message-ID: <20240307210015.F1042385C424@sourceware.org> (raw)

https://gcc.gnu.org/g:e162b2ff52c5e20f6624ff6b66845fe573cef183

commit r14-9371-ge162b2ff52c5e20f6624ff6b66845fe573cef183
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Feb 26 13:17:32 2024 +0000

    libstdc++: Do not define lock-free atomic aliases if not fully lock-free [PR114103]
    
    The whole point of these typedefs is to guarantee lock-freedom, so if
    the target has no such types, we shouldn't defined the typedefs at all.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/114103
            * include/bits/version.def (atomic_lock_free_type_aliases): Add
            extra_cond to check for at least one always-lock-free type.
            * include/bits/version.h: Regenerate.
            * include/std/atomic (atomic_signed_lock_free)
            (atomic_unsigned_lock_free): Only use always-lock-free types.
            * src/c++20/tzdb.cc (time_zone::_Impl::RulesCounter): Don't use
            atomic counter if lock-free aliases aren't available.
            * testsuite/29_atomics/atomic/lock_free_aliases.cc: XFAIL for
            targets without lock-free word-size compare_exchange.

Diff:
---
 libstdc++-v3/include/bits/version.def                         | 1 +
 libstdc++-v3/include/bits/version.h                           | 2 +-
 libstdc++-v3/include/std/atomic                               | 6 +++---
 libstdc++-v3/src/c++20/tzdb.cc                                | 7 ++++++-
 libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc | 1 +
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
index 502961eb269..d298420121b 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -739,6 +739,7 @@ ftms = {
   values = {
     v = 201907;
     cxxmin = 20;
+    extra_cond = "(__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2";
   };
 };
 
diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
index 7a6fbd35e2e..9107b45a484 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -819,7 +819,7 @@
 #undef __glibcxx_want_atomic_float
 
 #if !defined(__cpp_lib_atomic_lock_free_type_aliases)
-# if (__cplusplus >= 202002L)
+# if (__cplusplus >= 202002L) && ((__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2)
 #  define __glibcxx_atomic_lock_free_type_aliases 201907L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_lock_free_type_aliases)
 #   define __cpp_lib_atomic_lock_free_type_aliases 201907L
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 559f8370459..1462cf5ec23 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -1774,13 +1774,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     = 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)
+# elif ATOMIC_INT_LOCK_FREE == 2
   using atomic_signed_lock_free = atomic<signed int>;
   using atomic_unsigned_lock_free = atomic<unsigned int>;
-# elif ATOMIC_LONG_LOCK_FREE
+# elif ATOMIC_LONG_LOCK_FREE == 2
   using atomic_signed_lock_free = atomic<signed long>;
   using atomic_unsigned_lock_free = atomic<unsigned long>;
-# elif ATOMIC_CHAR_LOCK_FREE
+# elif ATOMIC_CHAR_LOCK_FREE == 2
   using atomic_signed_lock_free = atomic<signed char>;
   using atomic_unsigned_lock_free = atomic<unsigned char>;
 # else
diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index e03f4a5c32a..890a4c53e2d 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -651,7 +651,7 @@ namespace std::chrono
     template<typename _Tp> requires _Tp::is_always_lock_free
       struct RulesCounter<_Tp>
       {
-	atomic_signed_lock_free counter{0};
+	_Tp counter{0};
 
 	void
 	increment()
@@ -703,7 +703,12 @@ namespace std::chrono
       };
 #endif // __GTHREADS && __cpp_lib_atomic_wait
 
+#if __cpp_lib_atomic_lock_free_type_aliases
     RulesCounter<atomic_signed_lock_free> rules_counter;
+#else
+    RulesCounter<void> rules_counter;
+#endif
+
 #else // TZDB_DISABLED
     _Impl(weak_ptr<tzdb_list::_Node>) { }
     struct {
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc
index 372a63129ff..489d181d136 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc
@@ -1,5 +1,6 @@
 // { dg-do compile { target c++20 } }
 // { dg-add-options no_pch }
+// { dg-require-atomic-cmpxchg-word "PR libstdc++/114103" }
 
 #include <atomic>

                 reply	other threads:[~2024-03-07 21: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=20240307210015.F1042385C424@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).