public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: Thomas Rodgers <trodgers@redhat.com>
Subject: [committed] libstdc++: Relax memory ordering for default memory resource object
Date: Tue, 17 May 2022 20:56:34 +0100	[thread overview]
Message-ID: <20220517195634.164341-1-jwakely@redhat.com> (raw)

Tested powerpc64le-linux, pushed to trunk.

-- >8 --

Currently pmr::set_default_resource and pmr::get_default_resource both
use sequentially consistent memory ordering. This is overkill. The
standard only requires that a call to set_default_resource synchronizes
with subsequent calls to set_default_resource and get_default_resource.

Using acquire-release for the setter and acquire for the getter is
sufficient to meet the requirement.

Reviewed-by: Thomas Rodgers  <trodgers@redhat.com>

libstdc++-v3/ChangeLog:

	* src/c++17/memory_resource.cc (set_default_resource): Use
	memory_order_acq_rel.
	(get_default_resource): Use memory_order_acquire.
---
 libstdc++-v3/src/c++17/memory_resource.cc | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc
index bb6334c9694..8bc55a69f1f 100644
--- a/libstdc++-v3/src/c++17/memory_resource.cc
+++ b/libstdc++-v3/src/c++17/memory_resource.cc
@@ -112,13 +112,13 @@ namespace pmr
       mutex mx;
       memory_resource* val;
 
-      memory_resource* load()
+      memory_resource* load(std::memory_order)
       {
 	lock_guard<mutex> lock(mx);
 	return val;
       }
 
-      memory_resource* exchange(memory_resource* r)
+      memory_resource* exchange(memory_resource* r, std::memory_order)
       {
 	lock_guard<mutex> lock(mx);
 	return std::__exchange(val, r);
@@ -134,12 +134,12 @@ namespace pmr
 
       memory_resource* val;
 
-      memory_resource* load() const
+      memory_resource* load(std::memory_order) const
       {
 	return val;
       }
 
-      memory_resource* exchange(memory_resource* r)
+      memory_resource* exchange(memory_resource* r, std::memory_order)
       {
 	return std::__exchange(val, r);
       }
@@ -166,12 +166,12 @@ namespace pmr
   {
     if (r == nullptr)
       r = new_delete_resource();
-    return default_res.obj.exchange(r);
+    return default_res.obj.exchange(r, std::memory_order_acq_rel);
   }
 
   memory_resource*
   get_default_resource() noexcept
-  { return default_res.obj.load(); }
+  { return default_res.obj.load(std::memory_order_acquire); }
 
   // Member functions for std::pmr::monotonic_buffer_resource
 
-- 
2.34.3


                 reply	other threads:[~2022-05-17 19:56 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=20220517195634.164341-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=trodgers@redhat.com \
    /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).