1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . A T O M I C _ C O U N T E R S --
9 -- Copyright (C) 2011-2014, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package provides atomic counter on platforms where it is supported:
33 -- - all Alpha platforms
34 -- - all ia64 platforms
35 -- - all PowerPC platforms
36 -- - all SPARC V9 platforms
37 -- - all x86 platforms
38 -- - all x86_64 platforms
40 package System
.Atomic_Counters
is
44 type Atomic_Counter
is limited private;
45 -- Type for atomic counter objects. Note, initial value of the counter is
46 -- one. This allows using an atomic counter as member of record types when
47 -- object of these types are created at library level in preelaborable
50 -- Atomic_Counter is declared as private limited type to provide highest
51 -- level of protection from unexpected use. All available operations are
52 -- declared below, and this set should be as small as possible.
54 procedure Increment
(Item
: in out Atomic_Counter
);
55 pragma Inline_Always
(Increment
);
56 -- Increments value of atomic counter.
58 function Decrement
(Item
: in out Atomic_Counter
) return Boolean;
59 pragma Inline_Always
(Decrement
);
60 -- Decrements value of atomic counter, returns True when value reach zero
62 function Is_One
(Item
: Atomic_Counter
) return Boolean;
63 pragma Inline_Always
(Is_One
);
64 -- Returns True when value of the atomic counter is one
66 procedure Initialize
(Item
: out Atomic_Counter
);
67 pragma Inline_Always
(Initialize
);
68 -- Initialize counter by setting its value to one. This subprogram is
69 -- intended to be used in special cases when the counter object cannot be
70 -- initialized in standard way.
73 type Unsigned_32
is mod 2 ** 32;
75 type Atomic_Counter
is limited record
76 Value
: aliased Unsigned_32
:= 1;
77 pragma Atomic
(Value
);
80 end System
.Atomic_Counters
;