Руководство по Ada (Ada 2022)
C.6.5 Пакет System.Atomic_Operations.Modular_Arithmetic
Определяемый языком обобщённый пакет System.Atomic_Operations.Modular_Arithmetic предоставляет операции для выполнения арифметических операций атомарно над объектами модулярных типов.
Статическая семантика
Обобщённый библиотечный пакет System.Atomic_Operations.Modular_Arithmetic имеет следующее объявление:
generic
type Atomic_Type is mod <> with Atomic;
package System.Atomic_Operations.Modular_Arithmetic
with Pure, Nonblocking is
type Atomic_Type is mod <> with Atomic;
package System.Atomic_Operations.Modular_Arithmetic
with Pure, Nonblocking is
procedure Atomic_Add (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
Value : Atomic_Type)
with Convention => Intrinsic;
procedure Atomic_Subtract (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
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;
(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;
(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;
with Convention => Intrinsic;
end System.Atomic_Operations.Modular_Arithmetic;
Операции этого пакета определены следующим образом:
procedure Atomic_Add (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
Value : Atomic_Type)
with Convention => Intrinsic;
Атомарно выполняет: Item := Item + Value;
procedure Atomic_Subtract (Item : aliased in out Atomic_Type;
Value : Atomic_Type)
with Convention => Intrinsic;
Value : Atomic_Type)
with Convention => Intrinsic;
Атомарно выполняет: Item := Item - Value;
function Atomic_Fetch_And_Add
(Item : aliased in out Atomic_Type;
Value : Atomic_Type) return Atomic_Type
with Convention => Intrinsic;
(Item : aliased in out Atomic_Type;
Value : Atomic_Type) return Atomic_Type
with Convention => Intrinsic;
Атомарно выполняет: 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;
(Item : aliased in out Atomic_Type;
Value : Atomic_Type) return Atomic_Type
with Convention => Intrinsic;
Атомарно выполняет: Tmp := Item; Item := Item - Value; return Tmp;