Debian Codegraph @

gcc/ada/libgnat/s-atocou.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . A T O M I C _ C O U N T E R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2011-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This package provides atomic counters routines
33
34 -- This package support the following platforms:
35 -- - all Alpha platforms
36 -- - all AARCH64 platforms
37 -- - all ARM platforms
38 -- - all ia64 platforms
39 -- - all PowerPC platforms
40 -- - all SPARC V9 platforms
41 -- - all x86 platforms
42 -- - all x86_64 platforms
43
44 package System.Atomic_Counters is
45
46 pragma Pure;
47 pragma Preelaborate;
48
49 type Atomic_Counter is limited private;
50 -- Type for atomic counter objects. Note, initial value of the counter is
51 -- one. This allows using an atomic counter as member of record types when
52 -- object of these types are created at library level in preelaborable
53 -- compilation units.
54 --
55 -- Atomic_Counter is declared as private limited type to provide highest
56 -- level of protection from unexpected use. All available operations are
57 -- declared below, and this set should be as small as possible.
58 -- Increment/Decrement operations for this type raise Program_Error on
59 -- platforms not supporting the atomic primitives.
60
61 procedure Increment (Item : in out Atomic_Counter);
62 pragma Inline_Always (Increment);
63 -- Increments value of atomic counter.
64
65 function Decrement (Item : in out Atomic_Counter) return Boolean;
66 pragma Inline_Always (Decrement);
67 -- Decrements value of atomic counter, returns True when value reach zero
68
69 function Is_One (Item : Atomic_Counter) return Boolean;
70 pragma Inline_Always (Is_One);
71 -- Returns True when value of the atomic counter is one
72
73 procedure Initialize (Item : out Atomic_Counter);
74 pragma Inline_Always (Initialize);
75 -- Initialize counter by setting its value to one. This subprogram is
76 -- intended to be used in special cases when the counter object cannot be
77 -- initialized in standard way.
78
79 type Atomic_Unsigned is mod 2 ** 32 with Default_Value => 0, Atomic;
80 -- Modular compatible atomic unsigned type.
81 -- Increment/Decrement operations for this type are atomic only on
82 -- supported platforms. See top of the file.
83
84 procedure Increment
85 (Item : aliased in out Atomic_Unsigned) with Inline_Always;
86 -- Increments value of atomic counter
87
88 function Decrement
89 (Item : aliased in out Atomic_Unsigned) return Boolean with Inline_Always;
90
91 procedure Decrement
92 (Item : aliased in out Atomic_Unsigned) with Inline_Always;
93 -- Decrements value of atomic counter
94
95 -- The "+" and "-" abstract routine provided below to disable BT := BT + 1
96 -- constructions.
97
98 function "+"
99 (Left, Right : Atomic_Unsigned) return Atomic_Unsigned is abstract;
100
101 function "-"
102 (Left, Right : Atomic_Unsigned) return Atomic_Unsigned is abstract;
103
104 private
105
106 type Atomic_Counter is record
107 Value : aliased Atomic_Unsigned := 1;
108 end record;
109
110 end System.Atomic_Counters;