* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / gcc / ada / s-tataat.adb
blob0b4210d28ade30e029977dd0e68e06e49b51c4da
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . T A S K I N G . T A S K _ A T T R I B U T E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2010, AdaCore --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
22 -- --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
27 -- --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 -- --
31 ------------------------------------------------------------------------------
33 with Ada.Unchecked_Conversion;
35 with System.Task_Primitives.Operations;
36 with System.Tasking.Initialization;
38 package body System.Tasking.Task_Attributes is
40 use Task_Primitives.Operations;
41 use Tasking.Initialization;
43 function To_Access_Address is new Ada.Unchecked_Conversion
44 (Access_Node, Access_Address);
45 -- Store pointer to indirect attribute list
47 --------------
48 -- Finalize --
49 --------------
51 procedure Finalize (X : in out Instance) is
52 Q, To_Be_Freed : Access_Node;
53 Self_Id : constant Task_Id := Self;
55 begin
56 -- Defer abort. Note that we use the nestable versions of Defer_Abort
57 -- and Undefer_Abort, because abort can already deferred when this is
58 -- called during finalization, which would cause an assert failure
59 -- in Defer_Abort.
61 Defer_Abort_Nestable (Self_Id);
62 Lock_RTS;
64 -- Remove this instantiation from the list of all instantiations
66 declare
67 P : Access_Instance;
68 Q : Access_Instance := All_Attributes;
70 begin
71 while Q /= null and then Q /= X'Unchecked_Access loop
72 P := Q; Q := Q.Next;
73 end loop;
75 pragma Assert (Q /= null);
77 if P = null then
78 All_Attributes := Q.Next;
79 else
80 P.Next := Q.Next;
81 end if;
82 end;
84 if X.Index /= 0 then
86 -- Free location of this attribute, for reuse
88 In_Use := In_Use and not (2**Natural (X.Index));
90 -- There is no need for finalization in this case, since controlled
91 -- types are too big to fit in the TCB.
93 else
94 -- Remove nodes for this attribute from the lists of all tasks,
95 -- and deallocate the nodes. Deallocation does finalization, if
96 -- necessary.
98 declare
99 C : System.Tasking.Task_Id := All_Tasks_List;
100 P : Access_Node;
102 begin
103 while C /= null loop
104 Write_Lock (C);
106 Q := To_Access_Node (C.Indirect_Attributes);
107 while Q /= null
108 and then Q.Instance /= X'Unchecked_Access
109 loop
110 P := Q;
111 Q := Q.Next;
112 end loop;
114 if Q /= null then
115 if P = null then
116 C.Indirect_Attributes := To_Access_Address (Q.Next);
117 else
118 P.Next := Q.Next;
119 end if;
121 -- Can't Deallocate now since we are holding RTS_Lock
123 Q.Next := To_Be_Freed;
124 To_Be_Freed := Q;
125 end if;
127 Unlock (C);
128 C := C.Common.All_Tasks_Link;
129 end loop;
130 end;
131 end if;
133 Unlock_RTS;
135 while To_Be_Freed /= null loop
136 Q := To_Be_Freed;
137 To_Be_Freed := To_Be_Freed.Next;
138 X.Deallocate.all (Q);
139 end loop;
141 Undefer_Abort_Nestable (Self_Id);
143 exception
144 when others =>
145 null;
146 pragma Assert (False,
147 "Exception in task attribute instance finalization");
148 end Finalize;
150 -------------------------
151 -- Finalize Attributes --
152 -------------------------
154 -- This is to be called just before the ATCB is deallocated.
155 -- It relies on the caller holding T.L write-lock on entry.
157 procedure Finalize_Attributes (T : Task_Id) is
158 P : Access_Node;
159 Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
161 begin
162 -- Deallocate all the indirect attributes of this task
164 while Q /= null loop
165 P := Q;
166 Q := Q.Next; P.Instance.Deallocate.all (P);
167 end loop;
169 T.Indirect_Attributes := null;
171 exception
172 when others =>
173 null;
174 pragma Assert (False,
175 "Exception in per-task attributes finalization");
176 end Finalize_Attributes;
178 ---------------------------
179 -- Initialize Attributes --
180 ---------------------------
182 -- This is to be called by System.Tasking.Stages.Create_Task
184 procedure Initialize_Attributes (T : Task_Id) is
185 P : Access_Instance;
186 Self_Id : constant Task_Id := Self;
188 begin
189 Defer_Abort (Self_Id);
190 Lock_RTS;
192 -- Initialize all the direct-access attributes of this task
194 P := All_Attributes;
196 while P /= null loop
197 if P.Index /= 0 then
198 T.Direct_Attributes (P.Index) :=
199 Direct_Attribute_Element
200 (System.Storage_Elements.To_Address (P.Initial_Value));
201 end if;
203 P := P.Next;
204 end loop;
206 Unlock_RTS;
207 Undefer_Abort (Self_Id);
209 exception
210 when others =>
211 null;
212 pragma Assert (False);
213 end Initialize_Attributes;
215 end System.Tasking.Task_Attributes;