Unit System.Atomic_Counters 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-atocou__builtin.adb (Decrement, Increment): Switch
from __sync to __atomic builtins; use 'Address to be consistent
with System.Atomic_Primitives.
diff --git a/gcc/ada/libgnat/s-atocou__builtin.adb b/gcc/ada/libgnat/s-atocou__builtin.adb
--- 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;
----------------