C.6.4 The Package System.Atomic_Operations.Integer_Arithmetic
The language-defined generic package System.Atomic_Operations.Integer_Arithmetic
provides operations to perform arithmetic atomically on objects of integer
types.
Static Semantics
The generic library
package System.Atomic_Operations.Integer_Arithmetic has the following
declaration:
generic
type Atomic_Type
is range <>
with Atomic;
package System.Atomic_Operations.Integer_Arithmetic
with Pure, Nonblocking
is
procedure Atomic_Add (Item :
aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
procedure Atomic_Subtract (Item :
aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
function Atomic_Fetch_And_Add
(Item :
aliased in out Atomic_Type;
Value : Atomic_Type)
return Atomic_Type
with Convention => Intrinsic;
function Atomic_Fetch_And_Subtract
(Item :
aliased in out Atomic_Type;
Value : Atomic_Type)
return Atomic_Type
with Convention => Intrinsic;
function Is_Lock_Free (Item :
aliased Atomic_Type)
return Boolean
with Convention => Intrinsic;
end System.Atomic_Operations.Integer_Arithmetic;
The operations of this package are defined as
follows:
procedure Atomic_Add (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
Atomically performs:
Item := Item + Value;
procedure Atomic_Subtract (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
Atomically performs:
Item := Item - Value;
function Atomic_Fetch_And_Add
(Item : aliased in out Atomic_Type;
Value : Atomic_Type) return Atomic_Type
with Convention => Intrinsic;
Atomically performs:
Tmp := Item; Item := Item + Value; return Tmp;
function Atomic_Fetch_And_Subtract
(Item : aliased in out Atomic_Type;
Value : Atomic_Type) return Atomic_Type
with Convention => Intrinsic;
Atomically performs:
Tmp := Item; Item := Item - Value; return Tmp;
Implementation Permissions
An implementation may allow Item to be modified
if the operation defined in an instance of System.Atomic_Operations.Integer_Arithmetic
fails a language-defined check. Additionally, an implementation may check
that predicates are satisfied after the atomic operation.
Usage
The subtype used to instantiate System.Atomic_Operations.Integer_Arithmetic
should not have predicates, as those probably will not be checked atomically,
potentially causing incorrect check failures if another task has modified
the value between the operation and the check. For the best performance,
the subtype should be a base subtype so that no range check need be performed.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe