FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / s-tassta.ads
blobc8bd2872bf5bf67b98d455fd98448a02f38a2163
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 . S T A G E S --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1992-1999, Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
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. --
29 -- --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This package represents the high level tasking interface used by the
36 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
37 -- (aka GNARLI, GNU Ada Run-time Library Interface)
39 -- Note: Only the compiler is allowed to use this interface, by generating
40 -- direct calls to it, via Rtsfind.
41 -- Any changes to this interface may require corresponding compiler changes
42 -- in exp_ch9.adb and possibly exp_ch7.adb
44 with System.Task_Info;
45 -- used for Task_Info_Type
47 with System.Parameters;
48 -- used for Size_Type
50 package System.Tasking.Stages is
51 pragma Elaborate_Body;
53 -- The compiler will expand in the GNAT tree the following construct:
55 -- task type T (Discr : Integer);
57 -- task body T is
58 -- ...declarations, possibly some controlled...
59 -- begin
60 -- ...B...;
61 -- end T;
63 -- T1 : T (1);
65 -- as follows:
67 -- enter_master.all;
69 -- _chain : aliased activation_chain;
70 -- _init_proc (_chain);
72 -- task type t (discr : integer);
73 -- tE : aliased boolean := false;
74 -- tZ : size_type := unspecified_size;
75 -- type tV (discr : integer) is limited record
76 -- _task_id : task_id;
77 -- end record;
78 -- procedure tB (_task : access tV);
79 -- freeze tV [
80 -- procedure _init_proc (_init : in out tV; _master : master_id;
81 -- _chain : in out activation_chain; _task_id : in task_image_type;
82 -- discr : integer) is
83 -- begin
84 -- _init.discr := discr;
85 -- _init._task_id := null;
86 -- create_task (unspecified_priority, tZ,
87 -- unspecified_task_info, 0, _master,
88 -- task_procedure_access!(tB'address),
89 -- _init'address, tE'unchecked_access, _chain, _task_id, _init.
90 -- _task_id);
91 -- return;
92 -- end _init_proc;
93 -- ]
95 -- procedure tB (_task : access tV) is
96 -- discr : integer renames _task.discr;
98 -- procedure _clean is
99 -- begin
100 -- abort_defer.all;
101 -- complete_task;
102 -- finalize_list (F14b);
103 -- abort_undefer.all;
104 -- return;
105 -- end _clean;
106 -- begin
107 -- abort_undefer.all;
108 -- ...declarations...
109 -- complete_activation;
110 -- ...B...;
111 -- return;
112 -- at end
113 -- _clean;
114 -- end tB;
116 -- tE := true;
117 -- t1 : t (1);
118 -- master : constant master_id := current_master.all;
119 -- t1I : task_image_type := new string'"t1";
120 -- _init_proc (t1, _master, _chain, t1I, 1);
122 -- activate_tasks (_chain'unchecked_access);
124 procedure Abort_Tasks (Tasks : Task_List);
125 -- Compiler interface only. Do not call from within the RTS.
126 -- Initiate abortion, however, the actual abortion is done by abortee by
127 -- means of Abort_Handler and Abort_Undefer
129 -- source code:
130 -- Abort T1, T2;
131 -- code expansion:
132 -- abort_tasks (task_list'(t1._task_id, t2._task_id));
134 procedure Activate_Tasks (Chain_Access : Activation_Chain_Access);
135 -- Compiler interface only. Do not call from within the RTS.
136 -- This must be called by the creator of a chain of one or more new tasks,
137 -- to activate them. The chain is a linked list that up to this point is
138 -- only known to the task that created them, though the individual tasks
139 -- are already in the All_Tasks_List.
141 -- The compiler builds the chain in LIFO order (as a stack). Another
142 -- version of this procedure had code to reverse the chain, so as to
143 -- activate the tasks in the order of declaration. This might be nice, but
144 -- it is not needed if priority-based scheduling is supported, since all
145 -- the activated tasks synchronize on the activators lock before they
146 -- start activating and so they should start activating in priority order.
148 procedure Complete_Activation;
149 -- Compiler interface only. Do not call from within the RTS.
150 -- This should be called from the task body at the end of
151 -- the elaboration code for its declarative part.
152 -- Decrement the count of tasks to be activated by the activator and
153 -- wake it up so it can check to see if all tasks have been activated.
154 -- Except for the environment task, which should never call this procedure,
155 -- T.Activator should only be null iff T has completed activation.
157 procedure Complete_Master;
158 -- Compiler interface only. Do not call from within the RTS. This must
159 -- be called on exit from any master where Enter_Master was called.
160 -- Assume abort is deferred at this point.
162 procedure Complete_Task;
163 -- Compiler interface only. Do not call from within the RTS.
164 -- This should be called from an implicit at-end handler
165 -- associated with the task body, when it completes.
166 -- From this point, the current task will become not callable.
167 -- If the current task have not completed activation, this should be done
168 -- now in order to wake up the activator (the environment task).
170 procedure Create_Task
171 (Priority : Integer;
172 Size : System.Parameters.Size_Type;
173 Task_Info : System.Task_Info.Task_Info_Type;
174 Num_Entries : Task_Entry_Index;
175 Master : Master_Level;
176 State : Task_Procedure_Access;
177 Discriminants : System.Address;
178 Elaborated : Access_Boolean;
179 Chain : in out Activation_Chain;
180 Task_Image : System.Task_Info.Task_Image_Type;
181 Created_Task : out Task_ID);
182 -- Compiler interface only. Do not call from within the RTS.
183 -- This must be called to create a new task.
185 -- Priority is the task's priority (assumed to be in the
186 -- System.Any_Priority'Range)
187 -- Size is the stack size of the task to create
188 -- Task_Info is the task info associated with the created task, or
189 -- Unspecified_Task_Info if none.
190 -- State is the compiler generated task's procedure body
191 -- Discriminants is a pointer to a limited record whose discriminants
192 -- are those of the task to create. This parameter should be passed as
193 -- the single argument to State.
194 -- Elaborated is a pointer to a Boolean that must be set to true on exit
195 -- if the task could be successfully elaborated.
196 -- Chain is a linked list of task that needs to be created. On exit,
197 -- Created_Task.Activation_Link will be Chain.T_ID, and Chain.T_ID
198 -- will be Created_Task (e.g the created task will be linked at the front
199 -- of Chain).
200 -- Task_Image is a pointer to a string created by the compiler that the
201 -- run time can store to ease the debugging and the
202 -- Ada.Task_Identification facility.
203 -- Created_Task is the resulting task.
205 -- This procedure can raise Storage_Error if the task creation failed.
207 function Current_Master return Master_Level;
208 -- Compiler interface only.
209 -- This is called to obtain the current master nesting level.
211 procedure Enter_Master;
212 -- Compiler interface only. Do not call from within the RTS.
213 -- This must be called on entry to any "master" where a task,
214 -- or access type designating objects containing tasks, may be
215 -- declared.
217 procedure Expunge_Unactivated_Tasks (Chain : in out Activation_Chain);
218 -- Compiler interface only. Do not call from within the RTS.
219 -- This must be called by the compiler-generated code for an allocator if
220 -- the allocated object contains tasks, if the allocator exits without
221 -- calling Activate_Tasks for a given activation chains, as can happen if
222 -- an exception occurs during initialization of the object.
224 -- This should be called ONLY for tasks created via an allocator. Recovery
225 -- of storage for unactivated local task declarations is done by
226 -- Complete_Master and Complete_Task.
228 -- We remove each task from Chain and All_Tasks_List before we free the
229 -- storage of its ATCB.
231 -- In other places where we recover the storage of unactivated tasks, we
232 -- need to clean out the entry queues, but here that should not be
233 -- necessary, since these tasks should not have been visible to any other
234 -- tasks, and so no task should be able to queue a call on their entries.
236 -- Just in case somebody misuses this subprogram, there is a check to
237 -- verify this condition.
239 procedure Finalize_Global_Tasks;
240 -- This should be called to complete the execution of the environment task
241 -- and shut down the tasking runtime system. It is the equivalent of
242 -- Complete_Task, but for the environment task.
244 -- The environment task must first call Complete_Master, to wait for user
245 -- tasks that depend on library-level packages to terminate. It then calls
246 -- Abort_Dependents to abort the "independent" library-level server tasks
247 -- that are created implicitly by the RTS packages (signal and timer server
248 -- tasks), and then waits for them to terminate. Then, it calls
249 -- Vulnerable_Complete_Task.
251 -- It currently also executes the global finalization list, and then resets
252 -- the "soft links".
254 procedure Free_Task (T : Task_ID);
255 -- Recover all runtime system storage associated with the task T, but only
256 -- if T has terminated. Do nothing in the other case. It is called from
257 -- Unchecked_Deallocation, for objects that are or contain tasks.
259 function Terminated (T : Task_ID) return Boolean;
260 -- This is called by the compiler to implement the 'Terminated attribute.
261 -- Though is not required to be so by the ARM, we choose to synchronize
262 -- with the task's ATCB, so that this is more useful for polling the state
263 -- of a task, and so that it becomes an abort completion point for the
264 -- calling task (via Undefer_Abort).
266 -- source code:
267 -- T1'Terminated
269 -- code expansion:
270 -- terminated (t1._task_id)
272 end System.Tasking.Stages;