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