1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . C O N T A I N E R S . H E L P E R S --
9 -- Copyright (C) 2015, 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/>. --
26 ------------------------------------------------------------------------------
28 package body Ada
.Containers
.Helpers
is
30 package body Generic_Implementation
is
32 use type SAC
.Atomic_Unsigned
;
38 procedure Adjust
(Control
: in out Reference_Control_Type
) is
39 pragma Warnings
(Off
);
40 -- GNAT warns here if checks are turned off, but assertions on
41 pragma Assert
(T_Check
); -- not called if check suppressed
44 if Control
.T_Counts
/= null then
45 Lock
(Control
.T_Counts
.all);
53 procedure Busy
(T_Counts
: in out Tamper_Counts
) is
56 SAC
.Increment
(T_Counts
.Busy
);
64 procedure Finalize
(Control
: in out Reference_Control_Type
) is
65 pragma Warnings
(Off
);
66 pragma Assert
(T_Check
); -- not called if check suppressed
69 if Control
.T_Counts
/= null then
70 Unlock
(Control
.T_Counts
.all);
71 Control
.T_Counts
:= null;
75 -- No need to protect against double Finalize here, because these types
78 procedure Finalize
(Busy
: in out With_Busy
) is
79 pragma Warnings
(Off
);
80 pragma Assert
(T_Check
); -- not called if check suppressed
83 Unbusy
(Busy
.T_Counts
.all);
86 procedure Finalize
(Lock
: in out With_Lock
) is
87 pragma Warnings
(Off
);
88 pragma Assert
(T_Check
); -- not called if check suppressed
91 Unlock
(Lock
.T_Counts
.all);
98 procedure Initialize
(Busy
: in out With_Busy
) is
99 pragma Warnings
(Off
);
100 pragma Assert
(T_Check
); -- not called if check suppressed
101 pragma Warnings
(On
);
103 Generic_Implementation
.Busy
(Busy
.T_Counts
.all);
106 procedure Initialize
(Lock
: in out With_Lock
) is
107 pragma Warnings
(Off
);
108 pragma Assert
(T_Check
); -- not called if check suppressed
109 pragma Warnings
(On
);
111 Generic_Implementation
.Lock
(Lock
.T_Counts
.all);
118 procedure Lock
(T_Counts
: in out Tamper_Counts
) is
121 SAC
.Increment
(T_Counts
.Lock
);
122 SAC
.Increment
(T_Counts
.Busy
);
130 procedure TC_Check
(T_Counts
: Tamper_Counts
) is
132 if T_Check
and then T_Counts
.Busy
> 0 then
133 raise Program_Error
with
134 "attempt to tamper with cursors";
137 -- The lock status (which monitors "element tampering") always
138 -- implies that the busy status (which monitors "cursor tampering")
139 -- is set too; this is a representation invariant. Thus if the busy
140 -- bit is not set, then the lock bit must not be set either.
142 pragma Assert
(T_Counts
.Lock
= 0);
149 procedure TE_Check
(T_Counts
: Tamper_Counts
) is
151 if T_Check
and then T_Counts
.Lock
> 0 then
152 raise Program_Error
with
153 "attempt to tamper with elements";
161 procedure Unbusy
(T_Counts
: in out Tamper_Counts
) is
164 SAC
.Decrement
(T_Counts
.Busy
);
172 procedure Unlock
(T_Counts
: in out Tamper_Counts
) is
175 SAC
.Decrement
(T_Counts
.Lock
);
176 SAC
.Decrement
(T_Counts
.Busy
);
184 procedure Zero_Counts
(T_Counts
: out Tamper_Counts
) is
187 T_Counts
:= (others => <>);
191 end Generic_Implementation
;
193 end Ada
.Containers
.Helpers
;