OSDN Git Service

* doc/install.texi (xtensa-*-elf): New target.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tarest.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 . R E S T R I C T E D . 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 ------------------------------------------------------------------------------
36
37 --  This is a simplified version of the System.Tasking.Stages package,
38 --  intended to be used in a restricted run time.
39
40 --  This package represents the high level tasking interface used by the
41 --  compiler to expand Ada 95 tasking constructs into simpler run time calls
42 --  (aka GNARLI, GNU Ada Run-time Library Interface)
43
44 --  Note: the compiler generates direct calls to this interface, via Rtsfind.
45 --  Any changes to this interface may require corresponding compiler changes
46 --  in exp_ch9.adb and possibly exp_ch7.adb
47
48 --  The restricted GNARLI is also composed of System.Protected_Objects and
49 --  System.Protected_Objects.Single_Entry
50
51 with System.Task_Info;
52 --  used for Task_Info_Type
53
54 with System.Parameters;
55 --  used for Size_Type
56
57 package System.Tasking.Restricted.Stages is
58    pragma Elaborate_Body;
59
60    ---------------------------------
61    -- Compiler Interface (GNARLI) --
62    ---------------------------------
63
64    --  The compiler will expand in the GNAT tree the following construct:
65    --
66    --   task type T (Discr : Integer);
67    --
68    --   task body T is
69    --      ...declarations, possibly some controlled...
70    --   begin
71    --      ...B...;
72    --   end T;
73    --
74    --   T1 : T (1);
75    --
76    --  as follows:
77    --
78    --   task type t (discr : integer);
79    --   tE : aliased boolean := false;
80    --   tZ : size_type := unspecified_size;
81    --   type tV (discr : integer) is limited record
82    --      _task_id : task_id;
83    --   end record;
84    --   procedure tB (_task : access tV);
85    --   freeze tV [
86    --      procedure _init_proc (_init : in out tV; _master : master_id;
87    --        _chain : in out activation_chain; _task_id : in task_image_type;
88    --        discr : integer) is
89    --      begin
90    --         _init.discr := discr;
91    --         _init._task_id := null;
92    --         create_restricted_task (unspecified_priority, tZ,
93    --           unspecified_task_info, task_procedure_access!(tB'address),
94    --           _init'address, tE'unchecked_access, _chain, _task_id, _init.
95    --           _task_id);
96    --         return;
97    --      end _init_proc;
98    --   ]
99    --
100    --   _chain : aliased activation_chain;
101    --   _init_proc (_chain);
102    --
103    --   procedure tB (_task : access tV) is
104    --      discr : integer renames _task.discr;
105    --
106    --      procedure _clean is
107    --      begin
108    --         complete_restricted_task;
109    --         finalize_list (F14b);
110    --         return;
111    --      end _clean;
112    --   begin
113    --      ...declarations...
114    --      complete_restricted_activation;
115    --      ...B...;
116    --      return;
117    --   at end
118    --      _clean;
119    --   end tB;
120    --
121    --   tE := true;
122    --   t1 : t (1);
123    --   t1I : task_image_type := new string'"t1";
124    --   _init_proc (t1, 3, _chain, t1I, 1);
125    --
126    --   activate_restricted_tasks (_chain'unchecked_access);
127
128    procedure Create_Restricted_Task
129      (Priority      : Integer;
130       Size          : System.Parameters.Size_Type;
131       Task_Info     : System.Task_Info.Task_Info_Type;
132       State         : Task_Procedure_Access;
133       Discriminants : System.Address;
134       Elaborated    : Access_Boolean;
135       Chain         : in out Activation_Chain;
136       Task_Image    : System.Task_Info.Task_Image_Type;
137       Created_Task  : out Task_ID);
138    --  Compiler interface only. Do not call from within the RTS.
139    --  This must be called to create a new task.
140    --
141    --  Priority is the task's priority (assumed to be in the
142    --   System.Any_Priority'Range)
143    --  Size is the stack size of the task to create
144    --  Task_Info is the task info associated with the created task, or
145    --   Unspecified_Task_Info if none.
146    --  State is the compiler generated task's procedure body
147    --  Discriminants is a pointer to a limited record whose discriminants
148    --   are those of the task to create. This parameter should be passed as
149    --   the single argument to State.
150    --  Elaborated is a pointer to a Boolean that must be set to true on exit
151    --   if the task could be successfully elaborated.
152    --  Chain is a linked list of task that needs to be created. On exit,
153    --   Created_Task.Activation_Link will be Chain.T_ID, and Chain.T_ID
154    --   will be Created_Task (e.g the created task will be linked at the front
155    --   of Chain).
156    --  Task_Image is a pointer to a string created by the compiler that the
157    --   run time can store to ease the debugging and the
158    --   Ada.Task_Identification facility.
159    --  Created_Task is the resulting task.
160    --
161    --  This procedure can raise Storage_Error if the task creation failed.
162
163    procedure Activate_Restricted_Tasks
164      (Chain_Access : Activation_Chain_Access);
165    --  Compiler interface only. Do not call from within the RTS.
166    --  This must be called by the creator of a chain of one or more new tasks,
167    --  to activate them. The chain is a linked list that up to this point is
168    --  only known to the task that created them, though the individual tasks
169    --  are already in the All_Tasks_List.
170    --
171    --  The compiler builds the chain in LIFO order (as a stack). Another
172    --  version of this procedure had code to reverse the chain, so as to
173    --  activate the tasks in the order of declaration. This might be nice, but
174    --  it is not needed if priority-based scheduling is supported, since all
175    --  the activated tasks synchronize on the activators lock before they
176    --  start activating and so they should start activating in priority order.
177
178    procedure Complete_Restricted_Activation;
179    --  Compiler interface only. Do not call from within the RTS.
180    --  This should be called from the task body at the end of
181    --  the elaboration code for its declarative part.
182    --  Decrement the count of tasks to be activated by the activator and
183    --  wake it up so it can check to see if all tasks have been activated.
184    --  Except for the environment task, which should never call this procedure,
185    --  T.Activator should only be null iff T has completed activation.
186
187    procedure Complete_Restricted_Task;
188    --  Compiler interface only. Do not call from within the RTS.
189    --  This should be called from an implicit at-end handler
190    --  associated with the task body, when it completes.
191    --  From this point, the current task will become not callable.
192    --  If the current task have not completed activation, this should be done
193    --  now in order to wake up the activator (the environment task).
194
195    function Restricted_Terminated (T : Task_ID) return Boolean;
196    --  Compiler interface only. Do not call from within the RTS.
197    --  This is called by the compiler to implement the 'Terminated attribute.
198    --
199    --  source code:
200    --     T1'Terminated
201    --
202    --  code expansion:
203    --     restricted_terminated (t1._task_id)
204
205    procedure Finalize_Global_Tasks;
206    --  This is needed to support the compiler interface; it will only be called
207    --  by the Environment task in the binder generated file (by adafinal).
208    --  Instead, it will cause the Environment to block forever, since none of
209    --  the dependent tasks are expected to terminate
210
211 end System.Tasking.Restricted.Stages;