1 ------------------------------------------------------------------------------
3 -- GNAT 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-2010, AdaCore --
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. --
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. --
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/>. --
28 -- GNARL was developed by the GNARL team at Florida State University. --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
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
51 procedure Finalize (X : in out Instance) is
52 Q, To_Be_Freed : Access_Node;
53 Self_Id : constant Task_Id := Self;
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
61 Defer_Abort_Nestable (Self_Id);
64 -- Remove this instantiation from the list of all instantiations
68 Q : Access_Instance := All_Attributes;
71 while Q /= null and then Q /= X'Unchecked_Access loop
75 pragma Assert (Q /= null);
78 All_Attributes := Q.Next;
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.
94 -- Remove nodes for this attribute from the lists of all tasks,
95 -- and deallocate the nodes. Deallocation does finalization, if
99 C : System.Tasking.Task_Id := All_Tasks_List;
106 Q := To_Access_Node (C.Indirect_Attributes);
108 and then Q.Instance /= X'Unchecked_Access
116 C.Indirect_Attributes := To_Access_Address (Q.Next);
121 -- Can't Deallocate now since we are holding RTS_Lock
123 Q.Next := To_Be_Freed;
128 C := C.Common.All_Tasks_Link;
135 while To_Be_Freed /= null loop
137 To_Be_Freed := To_Be_Freed.Next;
138 X.Deallocate.all (Q);
141 Undefer_Abort_Nestable (Self_Id);
146 pragma Assert (False,
147 "Exception in task attribute instance finalization");
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
159 Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
162 -- Deallocate all the indirect attributes of this task
166 Q := Q.Next; P.Instance.Deallocate.all (P);
169 T.Indirect_Attributes := 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
186 Self_Id : constant Task_Id := Self;
189 Defer_Abort (Self_Id);
192 -- Initialize all the direct-access attributes of this task
198 T.Direct_Attributes (P.Index) :=
199 Direct_Attribute_Element
200 (System.Storage_Elements.To_Address (P.Initial_Value));
207 Undefer_Abort (Self_Id);
212 pragma Assert (False);
213 end Initialize_Attributes;
215 end System.Tasking.Task_Attributes;