-- --
------------------------------------------------------------------------------
--- 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 --
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;
---------------
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;
----------------