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 --
11 -- Copyright (C) 1995-1999 Florida State University --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 with System.Storage_Elements;
38 -- used for To_Address
40 with System.Task_Primitives.Operations;
41 -- used for Write_Lock
43 -- Lock/Unlock_All_Tasks_List
45 with System.Tasking.Initialization;
46 -- used for Defer_Abort
49 with Unchecked_Conversion;
51 package body System.Tasking.Task_Attributes is
53 use Task_Primitives.Operations,
54 System.Tasking.Initialization;
56 function To_Access_Node is new Unchecked_Conversion
57 (Access_Address, Access_Node);
58 -- Tetch pointer to indirect attribute list
60 function To_Access_Address is new Unchecked_Conversion
61 (Access_Node, Access_Address);
62 -- Store pointer to indirect attribute list
68 procedure Finalize (X : in out Instance) is
69 Q, To_Be_Freed : Access_Node;
73 Write_Lock (All_Attrs_L'Access);
75 -- Remove this instantiation from the list of all instantiations.
79 Q : Access_Instance := All_Attributes;
82 while Q /= null and then Q /= X'Unchecked_Access loop
86 pragma Assert (Q /= null);
89 All_Attributes := Q.Next;
97 -- Free location of this attribute, for reuse.
99 In_Use := In_Use and not (2**Natural (X.Index));
101 -- There is no need for finalization in this case,
102 -- since controlled types are too big to fit in the TCB.
105 -- Remove nodes for this attribute from the lists of
106 -- all tasks, and deallocate the nodes.
107 -- Deallocation does finalization, if necessary.
112 C : System.Tasking.Task_ID := All_Tasks_List;
119 Q := To_Access_Node (C.Indirect_Attributes);
121 and then Q.Instance /= X'Unchecked_Access
129 C.Indirect_Attributes := To_Access_Address (Q.Next);
134 -- Can't Deallocate now since we are holding the All_Tasks_L
137 Q.Next := To_Be_Freed;
142 C := C.Common.All_Tasks_Link;
146 Unlock_All_Tasks_List;
149 Unlock (All_Attrs_L'Access);
151 while To_Be_Freed /= null loop
153 To_Be_Freed := To_Be_Freed.Next;
154 X.Deallocate.all (Q);
161 pragma Assert (False,
162 "Exception in task attribute instance finalization");
165 -------------------------
166 -- Finalize Attributes --
167 -------------------------
169 -- This is to be called just before the ATCB is deallocated.
170 -- It relies on the caller holding T.L write-lock on entry.
172 procedure Finalize_Attributes (T : Task_ID) is
174 Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
177 -- Deallocate all the indirect attributes of this task.
181 Q := Q.Next; P.Instance.Deallocate.all (P);
184 T.Indirect_Attributes := null;
188 pragma Assert (False,
189 "Exception in per-task attributes finalization");
190 end Finalize_Attributes;
192 ---------------------------
193 -- Initialize Attributes --
194 ---------------------------
196 -- This is to be called by System.Task_Stages.Create_Task.
197 -- It relies on their being no concurrent access to this TCB,
198 -- so it does not defer abortion or lock T.L.
200 procedure Initialize_Attributes (T : Task_ID) is
204 Write_Lock (All_Attrs_L'Access);
206 -- Initialize all the direct-access attributes of this task.
211 T.Direct_Attributes (P.Index) :=
212 System.Storage_Elements.To_Address (P.Initial_Value);
218 Unlock (All_Attrs_L'Access);
222 pragma Assert (False);
223 end Initialize_Attributes;
225 end System.Tasking.Task_Attributes;