annotate gcc/ada/libgnarl/s-tassta.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . T A S K I N G . S T A G E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package represents the high level tasking interface used by the
kono
parents:
diff changeset
33 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
kono
parents:
diff changeset
34 -- (aka GNARLI, GNU Ada Run-time Library Interface)
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- Note: Only the compiler is allowed to use this interface, by generating
kono
parents:
diff changeset
37 -- direct calls to it, via Rtsfind.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- Any changes to this interface may require corresponding compiler changes
kono
parents:
diff changeset
40 -- in exp_ch9.adb and possibly exp_ch7.adb
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with System.Task_Info;
kono
parents:
diff changeset
43 with System.Parameters;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 with Ada.Real_Time;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 package System.Tasking.Stages is
kono
parents:
diff changeset
48 pragma Elaborate_Body;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- The compiler will expand in the GNAT tree the following construct:
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- task type T (Discr : Integer);
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 -- task body T is
kono
parents:
diff changeset
55 -- ...declarations, possibly some controlled...
kono
parents:
diff changeset
56 -- begin
kono
parents:
diff changeset
57 -- ...B...;
kono
parents:
diff changeset
58 -- end T;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 -- T1 : T (1);
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- as follows:
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- enter_master.all;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -- _chain : aliased activation_chain;
kono
parents:
diff changeset
67 -- activation_chainIP (_chain);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- task type t (discr : integer);
kono
parents:
diff changeset
70 -- tE : aliased boolean := false;
kono
parents:
diff changeset
71 -- tZ : size_type := unspecified_size;
kono
parents:
diff changeset
72 -- type tV (discr : integer) is limited record
kono
parents:
diff changeset
73 -- _task_id : task_id;
kono
parents:
diff changeset
74 -- end record;
kono
parents:
diff changeset
75 -- procedure tB (_task : access tV);
kono
parents:
diff changeset
76 -- freeze tV [
kono
parents:
diff changeset
77 -- procedure tVIP (_init : in out tV; _master : master_id;
kono
parents:
diff changeset
78 -- _chain : in out activation_chain; _task_id : in task_image_type;
kono
parents:
diff changeset
79 -- discr : integer) is
kono
parents:
diff changeset
80 -- begin
kono
parents:
diff changeset
81 -- _init.discr := discr;
kono
parents:
diff changeset
82 -- _init._task_id := null;
kono
parents:
diff changeset
83 -- create_task (unspecified_priority, tZ,
kono
parents:
diff changeset
84 -- unspecified_task_info, unspecified_cpu,
kono
parents:
diff changeset
85 -- ada__real_time__time_span_zero, 0, _master,
kono
parents:
diff changeset
86 -- task_procedure_access!(tB'address), _init'address,
kono
parents:
diff changeset
87 -- tE'unchecked_access, _chain, _task_id, _init._task_id);
kono
parents:
diff changeset
88 -- return;
kono
parents:
diff changeset
89 -- end tVIP;
kono
parents:
diff changeset
90 -- ]
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- procedure tB (_task : access tV) is
kono
parents:
diff changeset
93 -- discr : integer renames _task.discr;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- procedure _clean is
kono
parents:
diff changeset
96 -- begin
kono
parents:
diff changeset
97 -- abort_defer.all;
kono
parents:
diff changeset
98 -- complete_task;
kono
parents:
diff changeset
99 -- finalize_list (F14b);
kono
parents:
diff changeset
100 -- abort_undefer.all;
kono
parents:
diff changeset
101 -- return;
kono
parents:
diff changeset
102 -- end _clean;
kono
parents:
diff changeset
103 -- begin
kono
parents:
diff changeset
104 -- abort_undefer.all;
kono
parents:
diff changeset
105 -- ...declarations...
kono
parents:
diff changeset
106 -- complete_activation;
kono
parents:
diff changeset
107 -- ...B...;
kono
parents:
diff changeset
108 -- return;
kono
parents:
diff changeset
109 -- at end
kono
parents:
diff changeset
110 -- _clean;
kono
parents:
diff changeset
111 -- end tB;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- tE := true;
kono
parents:
diff changeset
114 -- t1 : t (1);
kono
parents:
diff changeset
115 -- _master : constant master_id := current_master.all;
kono
parents:
diff changeset
116 -- t1S : task_image_type := new string'"t1";
kono
parents:
diff changeset
117 -- task_image_typeIP (t1, _master, _chain, t1S, 1);
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- activate_tasks (_chain'unchecked_access);
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 procedure Abort_Tasks (Tasks : Task_List);
kono
parents:
diff changeset
122 -- Compiler interface only. Do not call from within the RTS. Initiate
kono
parents:
diff changeset
123 -- abort, however, the actual abort is done by abortee by means of
kono
parents:
diff changeset
124 -- Abort_Handler and Abort_Undefer
kono
parents:
diff changeset
125 --
kono
parents:
diff changeset
126 -- source code:
kono
parents:
diff changeset
127 -- Abort T1, T2;
kono
parents:
diff changeset
128 -- code expansion:
kono
parents:
diff changeset
129 -- abort_tasks (task_list'(t1._task_id, t2._task_id));
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Activate_Tasks (Chain_Access : Activation_Chain_Access);
kono
parents:
diff changeset
132 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
133 -- This must be called by the creator of a chain of one or more new tasks,
kono
parents:
diff changeset
134 -- to activate them. The chain is a linked list that up to this point is
kono
parents:
diff changeset
135 -- only known to the task that created them, though the individual tasks
kono
parents:
diff changeset
136 -- are already in the All_Tasks_List.
kono
parents:
diff changeset
137 --
kono
parents:
diff changeset
138 -- The compiler builds the chain in LIFO order (as a stack). Another
kono
parents:
diff changeset
139 -- version of this procedure had code to reverse the chain, so as to
kono
parents:
diff changeset
140 -- activate the tasks in the order of declaration. This might be nice, but
kono
parents:
diff changeset
141 -- it is not needed if priority-based scheduling is supported, since all
kono
parents:
diff changeset
142 -- the activated tasks synchronize on the activators lock before they
kono
parents:
diff changeset
143 -- start activating and so they should start activating in priority order.
kono
parents:
diff changeset
144 -- ??? Actually, the body of this package DOES reverse the chain, so I
kono
parents:
diff changeset
145 -- don't understand the above comment.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 procedure Complete_Activation;
kono
parents:
diff changeset
148 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
149 -- This should be called from the task body at the end of
kono
parents:
diff changeset
150 -- the elaboration code for its declarative part.
kono
parents:
diff changeset
151 -- Decrement the count of tasks to be activated by the activator and
kono
parents:
diff changeset
152 -- wake it up so it can check to see if all tasks have been activated.
kono
parents:
diff changeset
153 -- Except for the environment task, which should never call this procedure,
kono
parents:
diff changeset
154 -- T.Activator should only be null iff T has completed activation.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 procedure Complete_Master;
kono
parents:
diff changeset
157 -- Compiler interface only. Do not call from within the RTS. This must
kono
parents:
diff changeset
158 -- be called on exit from any master where Enter_Master was called.
kono
parents:
diff changeset
159 -- Assume abort is deferred at this point.
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure Complete_Task;
kono
parents:
diff changeset
162 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
163 -- This should be called from an implicit at-end handler
kono
parents:
diff changeset
164 -- associated with the task body, when it completes.
kono
parents:
diff changeset
165 -- From this point, the current task will become not callable.
kono
parents:
diff changeset
166 -- If the current task have not completed activation, this should be done
kono
parents:
diff changeset
167 -- now in order to wake up the activator (the environment task).
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 procedure Create_Task
kono
parents:
diff changeset
170 (Priority : Integer;
kono
parents:
diff changeset
171 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
172 Secondary_Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
173 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
174 CPU : Integer;
kono
parents:
diff changeset
175 Relative_Deadline : Ada.Real_Time.Time_Span;
kono
parents:
diff changeset
176 Domain : Dispatching_Domain_Access;
kono
parents:
diff changeset
177 Num_Entries : Task_Entry_Index;
kono
parents:
diff changeset
178 Master : Master_Level;
kono
parents:
diff changeset
179 State : Task_Procedure_Access;
kono
parents:
diff changeset
180 Discriminants : System.Address;
kono
parents:
diff changeset
181 Elaborated : Access_Boolean;
kono
parents:
diff changeset
182 Chain : in out Activation_Chain;
kono
parents:
diff changeset
183 Task_Image : String;
kono
parents:
diff changeset
184 Created_Task : out Task_Id);
kono
parents:
diff changeset
185 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
186 -- This must be called to create a new task.
kono
parents:
diff changeset
187 --
kono
parents:
diff changeset
188 -- Priority is the task's priority (assumed to be in range of type
kono
parents:
diff changeset
189 -- System.Any_Priority)
kono
parents:
diff changeset
190 --
kono
parents:
diff changeset
191 -- Stack_Size is the stack size of the task to create
kono
parents:
diff changeset
192 --
kono
parents:
diff changeset
193 -- Secondary_Stack_Size is the size of the secondary stack to be used by
kono
parents:
diff changeset
194 -- the task.
kono
parents:
diff changeset
195 --
kono
parents:
diff changeset
196 -- Task_Info is the task info associated with the created task, or
kono
parents:
diff changeset
197 -- Unspecified_Task_Info if none.
kono
parents:
diff changeset
198 --
kono
parents:
diff changeset
199 -- CPU is the task affinity. Passed as an Integer because the undefined
kono
parents:
diff changeset
200 -- value is not in the range of CPU_Range. Static range checks are
kono
parents:
diff changeset
201 -- performed when analyzing the pragma, and dynamic ones are performed
kono
parents:
diff changeset
202 -- before setting the affinity at run time.
kono
parents:
diff changeset
203 --
kono
parents:
diff changeset
204 -- Relative_Deadline is the relative deadline associated with the created
kono
parents:
diff changeset
205 -- task by means of a pragma Relative_Deadline, or 0.0 if none.
kono
parents:
diff changeset
206 --
kono
parents:
diff changeset
207 -- Domain is the dispatching domain associated with the created task by
kono
parents:
diff changeset
208 -- means of a Dispatching_Domain pragma or aspect, or null if none.
kono
parents:
diff changeset
209 --
kono
parents:
diff changeset
210 -- State is the compiler generated task's procedure body
kono
parents:
diff changeset
211 --
kono
parents:
diff changeset
212 -- Discriminants is a pointer to a limited record whose discriminants
kono
parents:
diff changeset
213 -- are those of the task to create. This parameter should be passed as
kono
parents:
diff changeset
214 -- the single argument to State.
kono
parents:
diff changeset
215 --
kono
parents:
diff changeset
216 -- Elaborated is a pointer to a Boolean that must be set to true on exit
kono
parents:
diff changeset
217 -- if the task could be successfully elaborated.
kono
parents:
diff changeset
218 --
kono
parents:
diff changeset
219 -- Chain is a linked list of task that needs to be created. On exit,
kono
parents:
diff changeset
220 -- Created_Task.Activation_Link will be Chain.T_ID, and Chain.T_ID
kono
parents:
diff changeset
221 -- will be Created_Task (e.g the created task will be linked at the front
kono
parents:
diff changeset
222 -- of Chain).
kono
parents:
diff changeset
223 --
kono
parents:
diff changeset
224 -- Task_Image is a string created by the compiler that the
kono
parents:
diff changeset
225 -- run time can store to ease the debugging and the
kono
parents:
diff changeset
226 -- Ada.Task_Identification facility.
kono
parents:
diff changeset
227 --
kono
parents:
diff changeset
228 -- Created_Task is the resulting task.
kono
parents:
diff changeset
229 --
kono
parents:
diff changeset
230 -- This procedure can raise Storage_Error if the task creation failed.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 function Current_Master return Master_Level;
kono
parents:
diff changeset
233 -- Compiler interface only.
kono
parents:
diff changeset
234 -- This is called to obtain the current master nesting level.
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 procedure Enter_Master;
kono
parents:
diff changeset
237 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
238 -- This must be called on entry to any "master" where a task,
kono
parents:
diff changeset
239 -- or access type designating objects containing tasks, may be
kono
parents:
diff changeset
240 -- declared.
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 procedure Expunge_Unactivated_Tasks (Chain : in out Activation_Chain);
kono
parents:
diff changeset
243 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
244 -- This must be called by the compiler-generated code for an allocator if
kono
parents:
diff changeset
245 -- the allocated object contains tasks, if the allocator exits without
kono
parents:
diff changeset
246 -- calling Activate_Tasks for a given activation chains, as can happen if
kono
parents:
diff changeset
247 -- an exception occurs during initialization of the object.
kono
parents:
diff changeset
248 --
kono
parents:
diff changeset
249 -- This should be called ONLY for tasks created via an allocator. Recovery
kono
parents:
diff changeset
250 -- of storage for unactivated local task declarations is done by
kono
parents:
diff changeset
251 -- Complete_Master and Complete_Task.
kono
parents:
diff changeset
252 --
kono
parents:
diff changeset
253 -- We remove each task from Chain and All_Tasks_List before we free the
kono
parents:
diff changeset
254 -- storage of its ATCB.
kono
parents:
diff changeset
255 --
kono
parents:
diff changeset
256 -- In other places where we recover the storage of unactivated tasks, we
kono
parents:
diff changeset
257 -- need to clean out the entry queues, but here that should not be
kono
parents:
diff changeset
258 -- necessary, since these tasks should not have been visible to any other
kono
parents:
diff changeset
259 -- tasks, and so no task should be able to queue a call on their entries.
kono
parents:
diff changeset
260 --
kono
parents:
diff changeset
261 -- Just in case somebody misuses this subprogram, there is a check to
kono
parents:
diff changeset
262 -- verify this condition.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 procedure Finalize_Global_Tasks;
kono
parents:
diff changeset
265 -- This should be called to complete the execution of the environment task
kono
parents:
diff changeset
266 -- and shut down the tasking runtime system. It is the equivalent of
kono
parents:
diff changeset
267 -- Complete_Task, but for the environment task.
kono
parents:
diff changeset
268 --
kono
parents:
diff changeset
269 -- The environment task must first call Complete_Master, to wait for user
kono
parents:
diff changeset
270 -- tasks that depend on library-level packages to terminate. It then calls
kono
parents:
diff changeset
271 -- Abort_Dependents to abort the "independent" library-level server tasks
kono
parents:
diff changeset
272 -- that are created implicitly by the RTS packages (signal and timer server
kono
parents:
diff changeset
273 -- tasks), and then waits for them to terminate. Then, it calls
kono
parents:
diff changeset
274 -- Vulnerable_Complete_Task.
kono
parents:
diff changeset
275 --
kono
parents:
diff changeset
276 -- It currently also executes the global finalization list, and then resets
kono
parents:
diff changeset
277 -- the "soft links".
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 procedure Free_Task (T : Task_Id);
kono
parents:
diff changeset
280 -- Recover all runtime system storage associated with the task T, but only
kono
parents:
diff changeset
281 -- if T has terminated. Do nothing in the other case. It is called from
kono
parents:
diff changeset
282 -- Unchecked_Deallocation, for objects that are or contain tasks.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 procedure Move_Activation_Chain
kono
parents:
diff changeset
285 (From, To : Activation_Chain_Access;
kono
parents:
diff changeset
286 New_Master : Master_ID);
kono
parents:
diff changeset
287 -- Compiler interface only. Do not call from within the RTS.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
288 -- Move all tasks on From list to To list, and change their Master_Of_Task
111
kono
parents:
diff changeset
289 -- to be New_Master. This is used to implement build-in-place function
kono
parents:
diff changeset
290 -- returns. Tasks that are part of the return object are initially placed
kono
parents:
diff changeset
291 -- on an activation chain local to the return statement, and their master
kono
parents:
diff changeset
292 -- is the return statement, in case the return statement is left
kono
parents:
diff changeset
293 -- prematurely (due to raising an exception, being aborted, or a goto or
kono
parents:
diff changeset
294 -- exit statement). Once the return statement has completed successfully,
kono
parents:
diff changeset
295 -- Move_Activation_Chain is called to move them to the caller's activation
kono
parents:
diff changeset
296 -- chain, and change their master to the one passed in by the caller. If
kono
parents:
diff changeset
297 -- that doesn't happen, they will never be activated, and will become
kono
parents:
diff changeset
298 -- terminated on leaving the return statement.
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 function Terminated (T : Task_Id) return Boolean;
kono
parents:
diff changeset
301 -- This is called by the compiler to implement the 'Terminated attribute.
kono
parents:
diff changeset
302 -- Though is not required to be so by the ARM, we choose to synchronize
kono
parents:
diff changeset
303 -- with the task's ATCB, so that this is more useful for polling the state
kono
parents:
diff changeset
304 -- of a task, and so that it becomes an abort completion point for the
kono
parents:
diff changeset
305 -- calling task (via Undefer_Abort).
kono
parents:
diff changeset
306 --
kono
parents:
diff changeset
307 -- source code:
kono
parents:
diff changeset
308 -- T1'Terminated
kono
parents:
diff changeset
309 --
kono
parents:
diff changeset
310 -- code expansion:
kono
parents:
diff changeset
311 -- terminated (t1._task_id)
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 procedure Terminate_Task (Self_ID : Task_Id);
kono
parents:
diff changeset
314 -- Terminate the calling task.
kono
parents:
diff changeset
315 -- This should only be called by the Task_Wrapper procedure, and to
kono
parents:
diff changeset
316 -- deallocate storage associate with foreign tasks.
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 end System.Tasking.Stages;