aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-12-30 18:07:19 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2022-01-10 09:38:44 +0000
commitad85af8e5a6f2e7c3482b23c2e2153228889635e (patch)
treedaa9614aecc896106cf096ec58bb540208e4e0fc
parent68adddccb139f87ff705fd744eb3771fc2c6497a (diff)
downloadgcc-ad85af8e5a6f2e7c3482b23c2e2153228889635e.zip
gcc-ad85af8e5a6f2e7c3482b23c2e2153228889635e.tar.gz
gcc-ad85af8e5a6f2e7c3482b23c2e2153228889635e.tar.bz2
[Ada] Switch from __sync to __atomic builtins for atomic counters
gcc/ada/ * libgnat/s-atocou__builtin.adb (Decrement, Increment): Switch from __sync to __atomic builtins; use 'Address to be consistent with System.Atomic_Primitives.
-rw-r--r--gcc/ada/libgnat/s-atocou__builtin.adb42
1 files changed, 26 insertions, 16 deletions
diff --git a/gcc/ada/libgnat/s-atocou__builtin.adb b/gcc/ada/libgnat/s-atocou__builtin.adb
index d87f9ad..e17268b 100644
--- a/gcc/ada/libgnat/s-atocou__builtin.adb
+++ b/gcc/ada/libgnat/s-atocou__builtin.adb
@@ -29,21 +29,27 @@
-- --
------------------------------------------------------------------------------
--- This package implements Atomic_Counter and Atomic_Unsigned operations
--- for platforms where GCC supports __sync_add_and_fetch_4 and
--- __sync_sub_and_fetch_4 builtins.
+-- This package implements Atomic_Counter and Atomic_Unsigned operations for
+-- platforms where GCC supports __atomic_add_fetch and __atomic_sub_fetch
+-- builtins.
+
+with System.Atomic_Primitives; use System.Atomic_Primitives;
package body System.Atomic_Counters is
- procedure Sync_Add_And_Fetch
- (Ptr : access Atomic_Unsigned;
- Value : Atomic_Unsigned);
- pragma Import (Intrinsic, Sync_Add_And_Fetch, "__sync_add_and_fetch_4");
+ function Atomic_Add_Fetch
+ (Ptr : System.Address;
+ Val : Atomic_Unsigned;
+ Model : Mem_Model := Seq_Cst)
+ return Atomic_Unsigned;
+ pragma Import (Intrinsic, Atomic_Add_Fetch, "__atomic_add_fetch");
- function Sync_Sub_And_Fetch
- (Ptr : access Atomic_Unsigned;
- Value : Atomic_Unsigned) return Atomic_Unsigned;
- pragma Import (Intrinsic, Sync_Sub_And_Fetch, "__sync_sub_and_fetch_4");
+ function Atomic_Sub_Fetch
+ (Ptr : System.Address;
+ Val : Atomic_Unsigned;
+ Model : Mem_Model := Seq_Cst)
+ return Atomic_Unsigned;
+ pragma Import (Intrinsic, Atomic_Sub_Fetch, "__atomic_sub_fetch");
---------------
-- Decrement --
@@ -51,19 +57,19 @@ package body System.Atomic_Counters is
procedure Decrement (Item : aliased in out Atomic_Unsigned) is
begin
- if Sync_Sub_And_Fetch (Item'Unchecked_Access, 1) = 0 then
+ if Atomic_Sub_Fetch (Item'Address, 1) = 0 then
null;
end if;
end Decrement;
function Decrement (Item : aliased in out Atomic_Unsigned) return Boolean is
begin
- return Sync_Sub_And_Fetch (Item'Unchecked_Access, 1) = 0;
+ return Atomic_Sub_Fetch (Item'Address, 1) = 0;
end Decrement;
function Decrement (Item : in out Atomic_Counter) return Boolean is
begin
- return Sync_Sub_And_Fetch (Item.Value'Unchecked_Access, 1) = 0;
+ return Atomic_Sub_Fetch (Item.Value'Address, 1) = 0;
end Decrement;
---------------
@@ -72,12 +78,16 @@ package body System.Atomic_Counters is
procedure Increment (Item : aliased in out Atomic_Unsigned) is
begin
- Sync_Add_And_Fetch (Item'Unchecked_Access, 1);
+ if Atomic_Add_Fetch (Item'Address, 1) = 0 then
+ null;
+ end if;
end Increment;
procedure Increment (Item : in out Atomic_Counter) is
begin
- Sync_Add_And_Fetch (Item.Value'Unchecked_Access, 1);
+ if Atomic_Add_Fetch (Item.Value'Address, 1) = 0 then
+ null;
+ end if;
end Increment;
----------------