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-2019, 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
40 if Control.T_Counts /= null then
41 Busy (Control.T_Counts.all);
49 procedure Busy (T_Counts : in out Tamper_Counts) is
52 SAC.Increment (T_Counts.Busy);
60 procedure Finalize (Control : in out Reference_Control_Type) is
62 if Control.T_Counts /= null then
63 Unbusy (Control.T_Counts.all);
64 Control.T_Counts := null;
68 -- No need to protect against double Finalize here, because these types
71 procedure Finalize (Busy : in out With_Busy) is
72 pragma Warnings (Off);
73 pragma Assert (T_Check); -- not called if check suppressed
76 Unbusy (Busy.T_Counts.all);
79 procedure Finalize (Lock : in out With_Lock) is
80 pragma Warnings (Off);
81 pragma Assert (T_Check); -- not called if check suppressed
84 Unlock (Lock.T_Counts.all);
91 procedure Initialize (Busy : in out With_Busy) is
92 pragma Warnings (Off);
93 pragma Assert (T_Check); -- not called if check suppressed
96 Generic_Implementation.Busy (Busy.T_Counts.all);
99 procedure Initialize (Lock : in out With_Lock) is
100 pragma Warnings (Off);
101 pragma Assert (T_Check); -- not called if check suppressed
102 pragma Warnings (On);
104 Generic_Implementation.Lock (Lock.T_Counts.all);
111 procedure Lock (T_Counts : in out Tamper_Counts) is
114 SAC.Increment (T_Counts.Lock);
115 SAC.Increment (T_Counts.Busy);
123 procedure TC_Check (T_Counts : Tamper_Counts) is
125 if T_Check and then T_Counts.Busy > 0 then
126 raise Program_Error with
127 "attempt to tamper with cursors";
130 -- The lock status (which monitors "element tampering") always
131 -- implies that the busy status (which monitors "cursor tampering")
132 -- is set too; this is a representation invariant. Thus if the busy
133 -- bit is not set, then the lock bit must not be set either.
135 pragma Assert (T_Counts.Lock = 0);
142 procedure TE_Check (T_Counts : Tamper_Counts) is
144 if T_Check and then T_Counts.Lock > 0 then
145 raise Program_Error with
146 "attempt to tamper with elements";
154 procedure Unbusy (T_Counts : in out Tamper_Counts) is
157 SAC.Decrement (T_Counts.Busy);
165 procedure Unlock (T_Counts : in out Tamper_Counts) is
168 SAC.Decrement (T_Counts.Lock);
169 SAC.Decrement (T_Counts.Busy);
177 procedure Zero_Counts (T_Counts : out Tamper_Counts) is
180 T_Counts := (others => <>);
184 end Generic_Implementation;
186 end Ada.Containers.Helpers;