OSDN Git Service

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