annotate gcc/ada/libgnarl/s-tarest.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 . R E S T R I C T E D . 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 is a simplified version of the System.Tasking.Stages package,
kono
parents:
diff changeset
33 -- intended to be used in a restricted run time.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- This package represents the high level tasking interface used by the
kono
parents:
diff changeset
36 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
kono
parents:
diff changeset
37 -- (aka GNARLI, GNU Ada Run-time Library Interface)
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
kono
parents:
diff changeset
40 -- Any changes to this interface may require corresponding compiler changes
kono
parents:
diff changeset
41 -- in exp_ch9.adb and possibly exp_ch7.adb
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 -- The restricted GNARLI is also composed of System.Protected_Objects and
kono
parents:
diff changeset
44 -- System.Protected_Objects.Single_Entry
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with System.Parameters;
kono
parents:
diff changeset
47 with System.Secondary_Stack;
kono
parents:
diff changeset
48 with System.Task_Info;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package System.Tasking.Restricted.Stages is
kono
parents:
diff changeset
51 pragma Elaborate_Body;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 ---------------------------------
kono
parents:
diff changeset
54 -- Compiler Interface (GNARLI) --
kono
parents:
diff changeset
55 ---------------------------------
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- The compiler will expand in the GNAT tree the following construct:
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- task type T (Discr : Integer);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- task body T is
kono
parents:
diff changeset
62 -- ...declarations, possibly some controlled...
kono
parents:
diff changeset
63 -- begin
kono
parents:
diff changeset
64 -- ...B...;
kono
parents:
diff changeset
65 -- end T;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 -- T1 : T (1);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- as follows:
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 -- task type t (discr : integer);
kono
parents:
diff changeset
72 -- tE : aliased boolean := false;
kono
parents:
diff changeset
73 -- tZ : size_type := unspecified_size;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 -- type tV (discr : integer) is limited record
kono
parents:
diff changeset
76 -- _task_id : task_id;
kono
parents:
diff changeset
77 -- _atcb : aliased system__tasking__ada_task_control_block (0);
kono
parents:
diff changeset
78 -- end record;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -- procedure tB (_task : access tV);
kono
parents:
diff changeset
81 -- freeze tV [
kono
parents:
diff changeset
82 -- procedure tVIP (_init : in out tV; _master : master_id;
kono
parents:
diff changeset
83 -- _chain : in out activation_chain; _task_name : in string;
kono
parents:
diff changeset
84 -- discr : integer) is
kono
parents:
diff changeset
85 -- begin
kono
parents:
diff changeset
86 -- _init.discr := discr;
kono
parents:
diff changeset
87 -- _init._task_id := null;
kono
parents:
diff changeset
88 -- system__tasking__ada_task_control_blockIP (_init._atcb, 0);
kono
parents:
diff changeset
89 -- _init._task_id := _init._atcb'unchecked_access;
kono
parents:
diff changeset
90 -- create_restricted_task (unspecified_priority, tZ,
kono
parents:
diff changeset
91 -- unspecified_task_info, unspecified_cpu,
kono
parents:
diff changeset
92 -- task_procedure_access!(tB'address), _init'address,
kono
parents:
diff changeset
93 -- tE'unchecked_access, _task_name, _init._task_id);
kono
parents:
diff changeset
94 -- return;
kono
parents:
diff changeset
95 -- end tVIP;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- _chain : aliased activation_chain;
kono
parents:
diff changeset
98 -- activation_chainIP (_chain);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 -- procedure tB (_task : access tV) is
kono
parents:
diff changeset
101 -- discr : integer renames _task.discr;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 -- procedure _clean is
kono
parents:
diff changeset
104 -- begin
kono
parents:
diff changeset
105 -- complete_restricted_task;
kono
parents:
diff changeset
106 -- finalize_list (F14b);
kono
parents:
diff changeset
107 -- return;
kono
parents:
diff changeset
108 -- end _clean;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 -- begin
kono
parents:
diff changeset
111 -- ...declarations...
kono
parents:
diff changeset
112 -- complete_restricted_activation;
kono
parents:
diff changeset
113 -- ...B...;
kono
parents:
diff changeset
114 -- return;
kono
parents:
diff changeset
115 -- at end
kono
parents:
diff changeset
116 -- _clean;
kono
parents:
diff changeset
117 -- end tB;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- tE := true;
kono
parents:
diff changeset
120 -- t1 : t (1);
kono
parents:
diff changeset
121 -- t1S : constant String := "t1";
kono
parents:
diff changeset
122 -- tIP (t1, 3, _chain, t1S, 1);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 Partition_Elaboration_Policy : Character := 'C';
kono
parents:
diff changeset
125 pragma Export (C, Partition_Elaboration_Policy,
kono
parents:
diff changeset
126 "__gnat_partition_elaboration_policy");
kono
parents:
diff changeset
127 -- Partition elaboration policy. Value can be either 'C' for concurrent,
kono
parents:
diff changeset
128 -- which is the default or 'S' for sequential. This value can be modified
kono
parents:
diff changeset
129 -- by the binder generated code, before calling elaboration code.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Create_Restricted_Task
kono
parents:
diff changeset
132 (Priority : Integer;
kono
parents:
diff changeset
133 Stack_Address : System.Address;
kono
parents:
diff changeset
134 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
135 Sec_Stack_Address : System.Secondary_Stack.SS_Stack_Ptr;
kono
parents:
diff changeset
136 Sec_Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
137 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
138 CPU : Integer;
kono
parents:
diff changeset
139 State : Task_Procedure_Access;
kono
parents:
diff changeset
140 Discriminants : System.Address;
kono
parents:
diff changeset
141 Elaborated : Access_Boolean;
kono
parents:
diff changeset
142 Chain : in out Activation_Chain;
kono
parents:
diff changeset
143 Task_Image : String;
kono
parents:
diff changeset
144 Created_Task : Task_Id);
kono
parents:
diff changeset
145 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
146 -- This must be called to create a new task, when the partition
kono
parents:
diff changeset
147 -- elaboration policy is not specified (or is concurrent).
kono
parents:
diff changeset
148 --
kono
parents:
diff changeset
149 -- Priority is the task's priority (assumed to be in the
kono
parents:
diff changeset
150 -- System.Any_Priority'Range).
kono
parents:
diff changeset
151 --
kono
parents:
diff changeset
152 -- Stack_Address is the start address of the stack associated to the task,
kono
parents:
diff changeset
153 -- in case it has been preallocated by the compiler; it is equal to
kono
parents:
diff changeset
154 -- Null_Address when the stack needs to be allocated by the underlying
kono
parents:
diff changeset
155 -- operating system.
kono
parents:
diff changeset
156 --
kono
parents:
diff changeset
157 -- Stack_Size is the stack size of the task to create.
kono
parents:
diff changeset
158 --
kono
parents:
diff changeset
159 -- Sec_Stack_Address is the pointer to the secondary stack created by the
kono
parents:
diff changeset
160 -- compiler. If null, the secondary stack is either allocated by the binder
kono
parents:
diff changeset
161 -- or the run-time.
kono
parents:
diff changeset
162 --
kono
parents:
diff changeset
163 -- Secondary_Stack_Size is the secondary stack size of the task to create.
kono
parents:
diff changeset
164 --
kono
parents:
diff changeset
165 -- Task_Info is the task info associated with the created task, or
kono
parents:
diff changeset
166 -- Unspecified_Task_Info if none.
kono
parents:
diff changeset
167 --
kono
parents:
diff changeset
168 -- CPU is the task affinity. We pass it as an Integer to avoid an explicit
kono
parents:
diff changeset
169 -- dependency from System.Multiprocessors when not needed. Static range
kono
parents:
diff changeset
170 -- checks are performed when analyzing the pragma, and dynamic ones are
kono
parents:
diff changeset
171 -- performed before setting the affinity at run time.
kono
parents:
diff changeset
172 --
kono
parents:
diff changeset
173 -- State is the compiler generated task's procedure body.
kono
parents:
diff changeset
174 --
kono
parents:
diff changeset
175 -- Discriminants is a pointer to a limited record whose discriminants are
kono
parents:
diff changeset
176 -- those of the task to create. This parameter should be passed as the
kono
parents:
diff changeset
177 -- single argument to State.
kono
parents:
diff changeset
178 --
kono
parents:
diff changeset
179 -- Elaborated is a pointer to a Boolean that must be set to true on exit
kono
parents:
diff changeset
180 -- if the task could be successfully elaborated.
kono
parents:
diff changeset
181 --
kono
parents:
diff changeset
182 -- Chain is a linked list of task that needs to be created. On exit,
kono
parents:
diff changeset
183 -- Created_Task.Activation_Link will be Chain.T_ID, and Chain.T_ID will be
kono
parents:
diff changeset
184 -- Created_Task (the created task will be linked at the front of Chain).
kono
parents:
diff changeset
185 --
kono
parents:
diff changeset
186 -- Task_Image is a string created by the compiler that the run time can
kono
parents:
diff changeset
187 -- store to ease the debugging and the Ada.Task_Identification facility.
kono
parents:
diff changeset
188 --
kono
parents:
diff changeset
189 -- Created_Task is the resulting task.
kono
parents:
diff changeset
190 --
kono
parents:
diff changeset
191 -- This procedure can raise Storage_Error if the task creation fails.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 procedure Create_Restricted_Task_Sequential
kono
parents:
diff changeset
194 (Priority : Integer;
kono
parents:
diff changeset
195 Stack_Address : System.Address;
kono
parents:
diff changeset
196 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
197 Sec_Stack_Address : System.Secondary_Stack.SS_Stack_Ptr;
kono
parents:
diff changeset
198 Sec_Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
199 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
200 CPU : Integer;
kono
parents:
diff changeset
201 State : Task_Procedure_Access;
kono
parents:
diff changeset
202 Discriminants : System.Address;
kono
parents:
diff changeset
203 Elaborated : Access_Boolean;
kono
parents:
diff changeset
204 Task_Image : String;
kono
parents:
diff changeset
205 Created_Task : Task_Id);
kono
parents:
diff changeset
206 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
207 -- This must be called to create a new task, when the sequential partition
kono
parents:
diff changeset
208 -- elaboration policy is used.
kono
parents:
diff changeset
209 --
kono
parents:
diff changeset
210 -- The parameters are the same as Create_Restricted_Task except there is
kono
parents:
diff changeset
211 -- no Chain parameter (for the activation chain), as there is only one
kono
parents:
diff changeset
212 -- global activation chain, which is declared in the body of this package.
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 procedure Activate_Restricted_Tasks
kono
parents:
diff changeset
215 (Chain_Access : Activation_Chain_Access);
kono
parents:
diff changeset
216 -- Compiler interface only. Do not call from within the RTS.
kono
parents:
diff changeset
217 -- This must be called by the creator of a chain of one or more new tasks,
kono
parents:
diff changeset
218 -- to activate them. The chain is a linked list that up to this point is
kono
parents:
diff changeset
219 -- only known to the task that created them, though the individual tasks
kono
parents:
diff changeset
220 -- are already in the All_Tasks_List.
kono
parents:
diff changeset
221 --
kono
parents:
diff changeset
222 -- The compiler builds the chain in LIFO order (as a stack). Another
kono
parents:
diff changeset
223 -- version of this procedure had code to reverse the chain, so as to
kono
parents:
diff changeset
224 -- activate the tasks in the order of declaration. This might be nice, but
kono
parents:
diff changeset
225 -- it is not needed if priority-based scheduling is supported, since all
kono
parents:
diff changeset
226 -- the activated tasks synchronize on the activators lock before they start
kono
parents:
diff changeset
227 -- activating and so they should start activating in priority order.
kono
parents:
diff changeset
228 --
kono
parents:
diff changeset
229 -- When the partition elaboration policy is sequential, this procedure
kono
parents:
diff changeset
230 -- does nothing, tasks will be activated at end of elaboration.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 procedure Activate_All_Tasks_Sequential;
kono
parents:
diff changeset
233 pragma Export (C, Activate_All_Tasks_Sequential,
kono
parents:
diff changeset
234 "__gnat_activate_all_tasks");
kono
parents:
diff changeset
235 -- Binder interface only. Do not call from within the RTS. This must be
kono
parents:
diff changeset
236 -- called an the end of the elaboration to activate all tasks, in order
kono
parents:
diff changeset
237 -- to implement the sequential elaboration policy.
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 procedure Complete_Restricted_Activation;
kono
parents:
diff changeset
240 -- Compiler interface only. Do not call from within the RTS. This should be
kono
parents:
diff changeset
241 -- called from the task body at the end of the elaboration code for its
kono
parents:
diff changeset
242 -- declarative part. Decrement the count of tasks to be activated by the
kono
parents:
diff changeset
243 -- activator and wake it up so it can check to see if all tasks have been
kono
parents:
diff changeset
244 -- activated. Except for the environment task, which should never call this
kono
parents:
diff changeset
245 -- procedure, T.Activator should only be null iff T has completed
kono
parents:
diff changeset
246 -- activation.
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 procedure Complete_Restricted_Task;
kono
parents:
diff changeset
249 -- Compiler interface only. Do not call from within the RTS. This should be
kono
parents:
diff changeset
250 -- called from an implicit at-end handler associated with the task body,
kono
parents:
diff changeset
251 -- when it completes. From this point, the current task will become not
kono
parents:
diff changeset
252 -- callable. If the current task have not completed activation, this should
kono
parents:
diff changeset
253 -- be done now in order to wake up the activator (the environment task).
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Restricted_Terminated (T : Task_Id) return Boolean;
kono
parents:
diff changeset
256 -- Compiler interface only. Do not call from within the RTS. This is called
kono
parents:
diff changeset
257 -- by the compiler to implement the 'Terminated attribute.
kono
parents:
diff changeset
258 --
kono
parents:
diff changeset
259 -- source code:
kono
parents:
diff changeset
260 -- T1'Terminated
kono
parents:
diff changeset
261 --
kono
parents:
diff changeset
262 -- code expansion:
kono
parents:
diff changeset
263 -- restricted_terminated (t1._task_id)
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 procedure Finalize_Global_Tasks;
kono
parents:
diff changeset
266 -- This is needed to support the compiler interface. It will only be called
kono
parents:
diff changeset
267 -- by the Environment task in the binder generated file (by adafinal).
kono
parents:
diff changeset
268 -- Instead, it will cause the Environment to block forever, since none of
kono
parents:
diff changeset
269 -- the dependent tasks are expected to terminate
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 end System.Tasking.Restricted.Stages;