* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / s-tataat.adb
blobd417da50e76579bff9ff1f89c34615b92256e7e9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA 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) 1995-2001 Florida State University --
10 -- --
11 -- GNARL 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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. It is --
30 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
31 -- --
32 ------------------------------------------------------------------------------
34 with System.Storage_Elements;
35 -- used for To_Address
37 with System.Task_Primitives.Operations;
38 -- used for Write_Lock
39 -- Unlock
40 -- Lock/Unlock_RTS
42 with System.Tasking.Initialization;
43 -- used for Defer_Abort
44 -- Undefer_Abort
46 with Unchecked_Conversion;
48 package body System.Tasking.Task_Attributes is
50 use Task_Primitives.Operations;
51 use Tasking.Initialization;
53 function To_Access_Node is new Unchecked_Conversion
54 (Access_Address, Access_Node);
55 -- Tetch pointer to indirect attribute list
57 function To_Access_Address is new Unchecked_Conversion
58 (Access_Node, Access_Address);
59 -- Store pointer to indirect attribute list
61 --------------
62 -- Finalize --
63 --------------
65 procedure Finalize (X : in out Instance) is
66 Q, To_Be_Freed : Access_Node;
68 begin
69 Defer_Abortion;
70 Lock_RTS;
72 -- Remove this instantiation from the list of all instantiations.
74 declare
75 P : Access_Instance;
76 Q : Access_Instance := All_Attributes;
78 begin
79 while Q /= null and then Q /= X'Unchecked_Access loop
80 P := Q; Q := Q.Next;
81 end loop;
83 pragma Assert (Q /= null);
85 if P = null then
86 All_Attributes := Q.Next;
87 else
88 P.Next := Q.Next;
89 end if;
90 end;
92 if X.Index /= 0 then
93 -- Free location of this attribute, for reuse.
95 In_Use := In_Use and not (2**Natural (X.Index));
97 -- There is no need for finalization in this case,
98 -- since controlled types are too big to fit in the TCB.
100 else
101 -- Remove nodes for this attribute from the lists of
102 -- all tasks, and deallocate the nodes.
103 -- Deallocation does finalization, if necessary.
105 declare
106 C : System.Tasking.Task_ID := All_Tasks_List;
107 P : Access_Node;
109 begin
110 while C /= null loop
111 Write_Lock (C);
113 Q := To_Access_Node (C.Indirect_Attributes);
114 while Q /= null
115 and then Q.Instance /= X'Unchecked_Access
116 loop
117 P := Q;
118 Q := Q.Next;
119 end loop;
121 if Q /= null then
122 if P = null then
123 C.Indirect_Attributes := To_Access_Address (Q.Next);
124 else
125 P.Next := Q.Next;
126 end if;
128 -- Can't Deallocate now since we are holding RTS_Lock.
130 Q.Next := To_Be_Freed;
131 To_Be_Freed := Q;
132 end if;
134 Unlock (C);
135 C := C.Common.All_Tasks_Link;
136 end loop;
137 end;
138 end if;
140 Unlock_RTS;
142 while To_Be_Freed /= null loop
143 Q := To_Be_Freed;
144 To_Be_Freed := To_Be_Freed.Next;
145 X.Deallocate.all (Q);
146 end loop;
148 Undefer_Abortion;
150 exception
151 when others => null;
152 pragma Assert (False,
153 "Exception in task attribute instance finalization");
154 end Finalize;
156 -------------------------
157 -- Finalize Attributes --
158 -------------------------
160 -- This is to be called just before the ATCB is deallocated.
161 -- It relies on the caller holding T.L write-lock on entry.
163 procedure Finalize_Attributes (T : Task_ID) is
164 P : Access_Node;
165 Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
167 begin
168 -- Deallocate all the indirect attributes of this task.
170 while Q /= null loop
171 P := Q;
172 Q := Q.Next; P.Instance.Deallocate.all (P);
173 end loop;
175 T.Indirect_Attributes := null;
177 exception
178 when others => null;
179 pragma Assert (False,
180 "Exception in per-task attributes finalization");
181 end Finalize_Attributes;
183 ---------------------------
184 -- Initialize Attributes --
185 ---------------------------
187 -- This is to be called by System.Tasking.Stages.Create_Task.
188 -- It relies on their being no concurrent access to this TCB,
189 -- so it does not defer abortion nor lock T.L.
191 procedure Initialize_Attributes (T : Task_ID) is
192 P : Access_Instance;
193 begin
194 Lock_RTS;
196 -- Initialize all the direct-access attributes of this task.
198 P := All_Attributes;
200 while P /= null loop
201 if P.Index /= 0 then
202 T.Direct_Attributes (P.Index) :=
203 System.Storage_Elements.To_Address (P.Initial_Value);
204 end if;
206 P := P.Next;
207 end loop;
209 Unlock_RTS;
211 exception
212 when others => null;
213 pragma Assert (False);
214 end Initialize_Attributes;
216 end System.Tasking.Task_Attributes;