1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
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 --
9 -- Copyright (C) 1991-1994, Florida State University --
10 -- Copyright (C) 1995-2003, Ada Core Technologies --
12 -- GNARL 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 2, or (at your option) any later ver- --
15 -- sion. GNARL 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. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
33 ------------------------------------------------------------------------------
35 with System.Storage_Elements;
36 -- used for To_Address
38 with System.Task_Primitives.Operations;
39 -- used for Write_Lock
43 with System.Tasking.Initialization;
44 -- used for Defer_Abort
47 with Unchecked_Conversion;
49 package body System.Tasking.Task_Attributes is
51 use Task_Primitives.Operations;
52 use Tasking.Initialization;
54 function To_Access_Node is new Unchecked_Conversion
55 (Access_Address, Access_Node);
56 -- Tetch pointer to indirect attribute list
58 function To_Access_Address is new Unchecked_Conversion
59 (Access_Node, Access_Address);
60 -- Store pointer to indirect attribute list
66 procedure Finalize (X : in out Instance) is
67 Q, To_Be_Freed : Access_Node;
73 -- Remove this instantiation from the list of all instantiations.
77 Q : Access_Instance := All_Attributes;
80 while Q /= null and then Q /= X'Unchecked_Access loop
84 pragma Assert (Q /= null);
87 All_Attributes := Q.Next;
94 -- Free location of this attribute, for reuse.
96 In_Use := In_Use and not (2**Natural (X.Index));
98 -- There is no need for finalization in this case,
99 -- since controlled types are too big to fit in the TCB.
102 -- Remove nodes for this attribute from the lists of
103 -- all tasks, and deallocate the nodes.
104 -- Deallocation does finalization, if necessary.
107 C : System.Tasking.Task_ID := All_Tasks_List;
114 Q := To_Access_Node (C.Indirect_Attributes);
116 and then Q.Instance /= X'Unchecked_Access
124 C.Indirect_Attributes := To_Access_Address (Q.Next);
129 -- Can't Deallocate now since we are holding RTS_Lock.
131 Q.Next := To_Be_Freed;
136 C := C.Common.All_Tasks_Link;
143 while To_Be_Freed /= null loop
145 To_Be_Freed := To_Be_Freed.Next;
146 X.Deallocate.all (Q);
154 pragma Assert (False,
155 "Exception in task attribute instance finalization");
158 -------------------------
159 -- Finalize Attributes --
160 -------------------------
162 -- This is to be called just before the ATCB is deallocated.
163 -- It relies on the caller holding T.L write-lock on entry.
165 procedure Finalize_Attributes (T : Task_ID) is
167 Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
170 -- Deallocate all the indirect attributes of this task.
174 Q := Q.Next; P.Instance.Deallocate.all (P);
177 T.Indirect_Attributes := null;
182 pragma Assert (False,
183 "Exception in per-task attributes finalization");
184 end Finalize_Attributes;
186 ---------------------------
187 -- Initialize Attributes --
188 ---------------------------
190 -- This is to be called by System.Tasking.Stages.Create_Task.
192 procedure Initialize_Attributes (T : Task_ID) is
198 -- Initialize all the direct-access attributes of this task.
204 T.Direct_Attributes (P.Index) :=
205 Direct_Attribute_Element
206 (System.Storage_Elements.To_Address (P.Initial_Value));
218 pragma Assert (False);
219 end Initialize_Attributes;
221 end System.Tasking.Task_Attributes;