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) 1995-2001 Florida State University --
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. --
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. --
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). --
32 ------------------------------------------------------------------------------
34 with System
.Storage_Elements
;
35 -- used for To_Address
37 with System
.Task_Primitives
.Operations
;
38 -- used for Write_Lock
42 with System
.Tasking
.Initialization
;
43 -- used for Defer_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
65 procedure Finalize
(X
: in out Instance
) is
66 Q
, To_Be_Freed
: Access_Node
;
72 -- Remove this instantiation from the list of all instantiations.
76 Q
: Access_Instance
:= All_Attributes
;
79 while Q
/= null and then Q
/= X
'Unchecked_Access loop
83 pragma Assert
(Q
/= null);
86 All_Attributes
:= Q
.Next
;
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.
101 -- Remove nodes for this attribute from the lists of
102 -- all tasks, and deallocate the nodes.
103 -- Deallocation does finalization, if necessary.
106 C
: System
.Tasking
.Task_ID
:= All_Tasks_List
;
113 Q
:= To_Access_Node
(C
.Indirect_Attributes
);
115 and then Q
.Instance
/= X
'Unchecked_Access
123 C
.Indirect_Attributes
:= To_Access_Address
(Q
.Next
);
128 -- Can't Deallocate now since we are holding RTS_Lock.
130 Q
.Next
:= To_Be_Freed
;
135 C
:= C
.Common
.All_Tasks_Link
;
142 while To_Be_Freed
/= null loop
144 To_Be_Freed
:= To_Be_Freed
.Next
;
145 X
.Deallocate
.all (Q
);
152 pragma Assert
(False,
153 "Exception in task attribute instance finalization");
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
165 Q
: Access_Node
:= To_Access_Node
(T
.Indirect_Attributes
);
168 -- Deallocate all the indirect attributes of this task.
172 Q
:= Q
.Next
; P
.Instance
.Deallocate
.all (P
);
175 T
.Indirect_Attributes
:= 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
196 -- Initialize all the direct-access attributes of this task.
202 T
.Direct_Attributes
(P
.Index
) :=
203 System
.Storage_Elements
.To_Address
(P
.Initial_Value
);
213 pragma Assert
(False);
214 end Initialize_Attributes
;
216 end System
.Tasking
.Task_Attributes
;