public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [Ada] Switch from __sync to __atomic builtins for Lock_Free_Try_Write
Date: Mon, 10 Jan 2022 09:41:38 +0000	[thread overview]
Message-ID: <20220110094138.GA586143@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 382 bytes --]

Routine Lock_Free_Try_Write was using deprecated __sync GCC builtins.
Now it uses __atomic builtins, which are recommended for new code.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/s-atopri.ads (Atomic_Compare_Exchange): Replaces
	deprecated Sync_Compare_And_Swap.
	* libgnat/s-atopri.adb (Lock_Free_Try_Write): Switch from __sync
	to __atomic builtins.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2543 bytes --]

diff --git a/gcc/ada/libgnat/s-atopri.adb b/gcc/ada/libgnat/s-atopri.adb
--- a/gcc/ada/libgnat/s-atopri.adb
+++ b/gcc/ada/libgnat/s-atopri.adb
@@ -55,23 +55,16 @@ package body System.Atomic_Primitives is
        Expected : in out Atomic_Type;
        Desired  : Atomic_Type) return Boolean
    is
-      function My_Sync_Compare_And_Swap is
-        new Sync_Compare_And_Swap (Atomic_Type);
-
-      Actual : Atomic_Type;
+      function My_Atomic_Compare_Exchange is
+        new Atomic_Compare_Exchange (Atomic_Type);
 
    begin
       if Expected /= Desired then
          if Atomic_Type'Atomic_Always_Lock_Free then
-            Actual := My_Sync_Compare_And_Swap (Ptr, Expected, Desired);
+            return My_Atomic_Compare_Exchange (Ptr, Expected'Address, Desired);
          else
             raise Program_Error;
          end if;
-
-         if Actual /= Expected then
-            Expected := Actual;
-            return False;
-         end if;
       end if;
 
       return True;


diff --git a/gcc/ada/libgnat/s-atopri.ads b/gcc/ada/libgnat/s-atopri.ads
--- a/gcc/ada/libgnat/s-atopri.ads
+++ b/gcc/ada/libgnat/s-atopri.ads
@@ -80,17 +80,20 @@ package System.Atomic_Primitives is
 
    generic
       type Atomic_Type is mod <>;
-   function Sync_Compare_And_Swap
-     (Ptr      : Address;
-      Expected : Atomic_Type;
-      Desired  : Atomic_Type) return Atomic_Type;
+   function Atomic_Compare_Exchange
+     (Ptr           : Address;
+      Expected      : Address;
+      Desired       : Atomic_Type;
+      Weak          : Boolean   := False;
+      Success_Model : Mem_Model := Seq_Cst;
+      Failure_Model : Mem_Model := Seq_Cst) return Boolean;
    pragma Import
-     (Intrinsic, Sync_Compare_And_Swap, "__sync_val_compare_and_swap");
+     (Intrinsic, Atomic_Compare_Exchange, "__atomic_compare_exchange_n");
 
-   function Sync_Compare_And_Swap_8  is new Sync_Compare_And_Swap (uint8);
-   function Sync_Compare_And_Swap_16 is new Sync_Compare_And_Swap (uint16);
-   function Sync_Compare_And_Swap_32 is new Sync_Compare_And_Swap (uint32);
-   function Sync_Compare_And_Swap_64 is new Sync_Compare_And_Swap (uint64);
+   function Atomic_Compare_Exchange_8  is new Atomic_Compare_Exchange (uint8);
+   function Atomic_Compare_Exchange_16 is new Atomic_Compare_Exchange (uint16);
+   function Atomic_Compare_Exchange_32 is new Atomic_Compare_Exchange (uint32);
+   function Atomic_Compare_Exchange_64 is new Atomic_Compare_Exchange (uint64);
 
    function Atomic_Test_And_Set
      (Ptr   : System.Address;



                 reply	other threads:[~2022-01-10  9:41 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=20220110094138.GA586143@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.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).