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 r12-3319] libstdc++: Implement std::atomic<T*>::compare_exchange_weak
Date: Thu,  2 Sep 2021 17:51:26 +0000 (GMT)	[thread overview]
Message-ID: <20210902175126.AC95138515E5@sourceware.org> (raw)

https://gcc.gnu.org/g:89cf858571c58a58ca51dbbf3975582ebab41e2d

commit r12-3319-g89cf858571c58a58ca51dbbf3975582ebab41e2d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 2 16:47:31 2021 +0100

    libstdc++: Implement std::atomic<T*>::compare_exchange_weak
    
    For some reason r170217 didn't add compare_exchange_weak to the
    __atomic_base<T*> partial specialization, and so weak compare exchange
    operations on pointers use compare_exchange_strong instead.
    
    This adds __atomic_base<T*>::compare_exchange_weak and then uses it in
    std::atomic<T*>::compare_exchange_weak.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/atomic_base.h (__atomic_base<P*>::compare_exchange_weak):
            Add new functions.
            * include/std/atomic (atomic<T*>::compare_exchange_weak): Use
            it.

Diff:
---
 libstdc++-v3/include/bits/atomic_base.h | 22 ++++++++++++++++++++++
 libstdc++-v3/include/std/atomic         |  4 ++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index cbe1da6d125..71e1de078b5 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -846,6 +846,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	return __atomic_exchange_n(&_M_p, __p, int(__m));
       }
 
+      _GLIBCXX_ALWAYS_INLINE bool
+      compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
+			    memory_order __m1,
+			    memory_order __m2) noexcept
+      {
+	__glibcxx_assert(__is_valid_cmpexch_failure_order(__m2));
+
+	return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 1,
+					   int(__m1), int(__m2));
+      }
+
+      _GLIBCXX_ALWAYS_INLINE bool
+      compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
+			    memory_order __m1,
+			    memory_order __m2) volatile noexcept
+      {
+	__glibcxx_assert(__is_valid_cmpexch_failure_order(__m2));
+
+	return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 1,
+					   int(__m1), int(__m2));
+      }
+
       _GLIBCXX_ALWAYS_INLINE bool
       compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
 			      memory_order __m1,
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index bdbbfd5c8f8..936dd50ba1c 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -595,13 +595,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       bool
       compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
 			    memory_order __m1, memory_order __m2) noexcept
-      { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
+      { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
 
       bool
       compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
 			    memory_order __m1,
 			    memory_order __m2) volatile noexcept
-      { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
+      { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
 
       bool
       compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,


                 reply	other threads:[~2021-09-02 17:51 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=20210902175126.AC95138515E5@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).