annotate gcc/ada/libgnarl/s-taskin.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
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 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, 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 provides necessary type definitions for compiler interface
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
kono
parents:
diff changeset
35 -- Any changes to this interface may require corresponding compiler changes.
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 with Ada.Exceptions;
kono
parents:
diff changeset
38 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 with System.Multiprocessors;
kono
parents:
diff changeset
41 with System.Parameters;
kono
parents:
diff changeset
42 with System.Soft_Links;
kono
parents:
diff changeset
43 with System.Stack_Usage;
kono
parents:
diff changeset
44 with System.Task_Info;
kono
parents:
diff changeset
45 with System.Task_Primitives;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 package System.Tasking is
kono
parents:
diff changeset
48 pragma Preelaborate;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -------------------
kono
parents:
diff changeset
51 -- Locking Rules --
kono
parents:
diff changeset
52 -------------------
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 -- The following rules must be followed at all times, to prevent
kono
parents:
diff changeset
55 -- deadlock and generally ensure correct operation of locking.
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- Never lock a lock unless abort is deferred
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- Never undefer abort while holding a lock
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- Overlapping critical sections must be properly nested, and locks must
kono
parents:
diff changeset
62 -- be released in LIFO order. E.g., the following is not allowed:
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- Lock (X);
kono
parents:
diff changeset
65 -- ...
kono
parents:
diff changeset
66 -- Lock (Y);
kono
parents:
diff changeset
67 -- ...
kono
parents:
diff changeset
68 -- Unlock (X);
kono
parents:
diff changeset
69 -- ...
kono
parents:
diff changeset
70 -- Unlock (Y);
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 -- Locks with lower (smaller) level number cannot be locked
kono
parents:
diff changeset
73 -- while holding a lock with a higher level number. (The level
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 -- 1. System.Tasking.PO_Simple.Protection.L (any PO lock)
kono
parents:
diff changeset
76 -- 2. System.Tasking.Initialization.Global_Task_Lock (in body)
kono
parents:
diff changeset
77 -- 3. System.Task_Primitives.Operations.Single_RTS_Lock
kono
parents:
diff changeset
78 -- 4. System.Tasking.Ada_Task_Control_Block.LL.L (any TCB lock)
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -- Clearly, there can be no circular chain of hold-and-wait
kono
parents:
diff changeset
81 -- relationships involving locks in different ordering levels.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 -- We used to have Global_Task_Lock before Protection.L but this was
kono
parents:
diff changeset
84 -- clearly wrong since there can be calls to "new" inside protected
kono
parents:
diff changeset
85 -- operations. The new ordering prevents these failures.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 -- Sometimes we need to hold two ATCB locks at the same time. To allow us
kono
parents:
diff changeset
88 -- to order the locking, each ATCB is given a unique serial number. If one
kono
parents:
diff changeset
89 -- needs to hold locks on two ATCBs at once, the lock with lower serial
kono
parents:
diff changeset
90 -- number must be locked first. We avoid holding three or more ATCB locks,
kono
parents:
diff changeset
91 -- because that can easily lead to complications that cause race conditions
kono
parents:
diff changeset
92 -- and deadlocks.
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 -- We don't always need to check the serial numbers, since the serial
kono
parents:
diff changeset
95 -- numbers are assigned sequentially, and so:
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- . The parent of a task always has a lower serial number.
kono
parents:
diff changeset
98 -- . The activator of a task always has a lower serial number.
kono
parents:
diff changeset
99 -- . The environment task has a lower serial number than any other task.
kono
parents:
diff changeset
100 -- . If the activator of a task is different from the task's parent,
kono
parents:
diff changeset
101 -- the parent always has a lower serial number than the activator.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 ---------------------------------
kono
parents:
diff changeset
104 -- Task_Id related definitions --
kono
parents:
diff changeset
105 ---------------------------------
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 type Ada_Task_Control_Block;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 type Task_Id is access all Ada_Task_Control_Block;
kono
parents:
diff changeset
110 for Task_Id'Size use System.Task_Primitives.Task_Address_Size;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 Null_Task : constant Task_Id;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 type Task_List is array (Positive range <>) of Task_Id;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 function Self return Task_Id;
kono
parents:
diff changeset
117 pragma Inline (Self);
kono
parents:
diff changeset
118 -- This is the compiler interface version of this function. Do not call
kono
parents:
diff changeset
119 -- from the run-time system.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 function To_Task_Id is
kono
parents:
diff changeset
122 new Ada.Unchecked_Conversion
kono
parents:
diff changeset
123 (System.Task_Primitives.Task_Address, Task_Id);
kono
parents:
diff changeset
124 function To_Address is
kono
parents:
diff changeset
125 new Ada.Unchecked_Conversion
kono
parents:
diff changeset
126 (Task_Id, System.Task_Primitives.Task_Address);
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -----------------------
kono
parents:
diff changeset
129 -- Enumeration types --
kono
parents:
diff changeset
130 -----------------------
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 type Task_States is
kono
parents:
diff changeset
133 (Unactivated,
kono
parents:
diff changeset
134 -- TCB initialized but not task has not been created.
kono
parents:
diff changeset
135 -- It cannot be executing.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 -- Activating,
kono
parents:
diff changeset
138 -- -- ??? Temporarily at end of list for GDB compatibility
kono
parents:
diff changeset
139 -- -- Task has been created and is being made Runnable.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 -- Active states
kono
parents:
diff changeset
142 -- For all states from here down, the task has been activated.
kono
parents:
diff changeset
143 -- For all states from here down, except for Terminated, the task
kono
parents:
diff changeset
144 -- may be executing.
kono
parents:
diff changeset
145 -- Activator = null iff it has not yet completed activating.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 Runnable,
kono
parents:
diff changeset
148 -- Task is not blocked for any reason known to Ada.
kono
parents:
diff changeset
149 -- (It may be waiting for a mutex, though.)
kono
parents:
diff changeset
150 -- It is conceptually "executing" in normal mode.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 Terminated,
kono
parents:
diff changeset
153 -- The task is terminated, in the sense of ARM 9.3 (5).
kono
parents:
diff changeset
154 -- Any dependents that were waiting on terminate
kono
parents:
diff changeset
155 -- alternatives have been awakened and have terminated themselves.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Activator_Sleep,
kono
parents:
diff changeset
158 -- Task is waiting for created tasks to complete activation
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 Acceptor_Sleep,
kono
parents:
diff changeset
161 -- Task is waiting on an accept or select with terminate
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- Acceptor_Delay_Sleep,
kono
parents:
diff changeset
164 -- -- ??? Temporarily at end of list for GDB compatibility
kono
parents:
diff changeset
165 -- -- Task is waiting on an selective wait statement
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 Entry_Caller_Sleep,
kono
parents:
diff changeset
168 -- Task is waiting on an entry call
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Async_Select_Sleep,
kono
parents:
diff changeset
171 -- Task is waiting to start the abortable part of an
kono
parents:
diff changeset
172 -- asynchronous select statement.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Delay_Sleep,
kono
parents:
diff changeset
175 -- Task is waiting on a select statement with only a delay
kono
parents:
diff changeset
176 -- alternative open.
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 Master_Completion_Sleep,
kono
parents:
diff changeset
179 -- Master completion has two phases.
kono
parents:
diff changeset
180 -- In Phase 1 the task is sleeping in Complete_Master
kono
parents:
diff changeset
181 -- having completed a master within itself,
kono
parents:
diff changeset
182 -- and is waiting for the tasks dependent on that master to become
kono
parents:
diff changeset
183 -- terminated or waiting on a terminate Phase.
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 Master_Phase_2_Sleep,
kono
parents:
diff changeset
186 -- In Phase 2 the task is sleeping in Complete_Master
kono
parents:
diff changeset
187 -- waiting for tasks on terminate alternatives to finish
kono
parents:
diff changeset
188 -- terminating.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -- The following are special uses of sleep, for server tasks
kono
parents:
diff changeset
191 -- within the run-time system.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 Interrupt_Server_Idle_Sleep,
kono
parents:
diff changeset
194 Interrupt_Server_Blocked_Interrupt_Sleep,
kono
parents:
diff changeset
195 Timer_Server_Sleep,
kono
parents:
diff changeset
196 AST_Server_Sleep,
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 Asynchronous_Hold,
kono
parents:
diff changeset
199 -- The task has been held by Asynchronous_Task_Control.Hold_Task
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 Interrupt_Server_Blocked_On_Event_Flag,
kono
parents:
diff changeset
202 -- The task has been blocked on a system call waiting for a
kono
parents:
diff changeset
203 -- completion event/signal to occur.
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 Activating,
kono
parents:
diff changeset
206 -- Task has been created and is being made Runnable
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 Acceptor_Delay_Sleep
kono
parents:
diff changeset
209 -- Task is waiting on an selective wait statement
kono
parents:
diff changeset
210 );
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 type Call_Modes is
kono
parents:
diff changeset
213 (Simple_Call, Conditional_Call, Asynchronous_Call, Timed_Call);
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 type Select_Modes is (Simple_Mode, Else_Mode, Terminate_Mode, Delay_Mode);
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 subtype Delay_Modes is Integer;
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 -------------------------------
kono
parents:
diff changeset
220 -- Entry related definitions --
kono
parents:
diff changeset
221 -------------------------------
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 Null_Entry : constant := 0;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 Max_Entry : constant := Integer'Last;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 Interrupt_Entry : constant := -2;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 Cancelled_Entry : constant := -1;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 type Entry_Index is range Interrupt_Entry .. Max_Entry;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 Null_Task_Entry : constant := Null_Entry;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 Max_Task_Entry : constant := Max_Entry;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 type Task_Entry_Index is new Entry_Index
kono
parents:
diff changeset
238 range Null_Task_Entry .. Max_Task_Entry;
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 type Entry_Call_Record;
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 type Entry_Call_Link is access all Entry_Call_Record;
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 type Entry_Queue is record
kono
parents:
diff changeset
245 Head : Entry_Call_Link;
kono
parents:
diff changeset
246 Tail : Entry_Call_Link;
kono
parents:
diff changeset
247 end record;
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 type Task_Entry_Queue_Array is
kono
parents:
diff changeset
250 array (Task_Entry_Index range <>) of Entry_Queue;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- A data structure which contains the string names of entries and entry
kono
parents:
diff changeset
253 -- family members.
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 type String_Access is access all String;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 ----------------------------------
kono
parents:
diff changeset
258 -- Entry_Call_Record definition --
kono
parents:
diff changeset
259 ----------------------------------
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 type Entry_Call_State is
kono
parents:
diff changeset
262 (Never_Abortable,
kono
parents:
diff changeset
263 -- the call is not abortable, and never can be
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 Not_Yet_Abortable,
kono
parents:
diff changeset
266 -- the call is not abortable, but may become so
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 Was_Abortable,
kono
parents:
diff changeset
269 -- the call is not abortable, but once was
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 Now_Abortable,
kono
parents:
diff changeset
272 -- the call is abortable
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 Done,
kono
parents:
diff changeset
275 -- the call has been completed
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 Cancelled
kono
parents:
diff changeset
278 -- the call was asynchronous, and was cancelled
kono
parents:
diff changeset
279 );
kono
parents:
diff changeset
280 pragma Ordered (Entry_Call_State);
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 -- Never_Abortable is used for calls that are made in a abort deferred
kono
parents:
diff changeset
283 -- region (see ARM 9.8(5-11), 9.8 (20)). Such a call is never abortable.
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 -- The Was_ vs. Not_Yet_ distinction is needed to decide whether it is OK
kono
parents:
diff changeset
286 -- to advance into the abortable part of an async. select stmt. That is
kono
parents:
diff changeset
287 -- allowed iff the mode is Now_ or Was_.
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 -- Done indicates the call has been completed, without cancellation, or no
kono
parents:
diff changeset
290 -- call has been made yet at this ATC nesting level, and so aborting the
kono
parents:
diff changeset
291 -- call is no longer an issue. Completion of the call does not necessarily
kono
parents:
diff changeset
292 -- indicate "success"; the call may be returning an exception if
kono
parents:
diff changeset
293 -- Exception_To_Raise is non-null.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 -- Cancelled indicates the call was cancelled, and so aborting the call is
kono
parents:
diff changeset
296 -- no longer an issue.
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 -- The call is on an entry queue unless State >= Done, in which case it may
kono
parents:
diff changeset
299 -- or may not be still Onqueue.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 -- Please do not modify the order of the values, without checking all uses
kono
parents:
diff changeset
302 -- of this type. We rely on partial "monotonicity" of
kono
parents:
diff changeset
303 -- Entry_Call_Record.State to avoid locking when we access this value for
kono
parents:
diff changeset
304 -- certain tests. In particular:
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 -- 1) Once State >= Done, we can rely that the call has been
kono
parents:
diff changeset
307 -- completed. If State >= Done, it will not
kono
parents:
diff changeset
308 -- change until the task does another entry call at this level.
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 -- 2) Once State >= Was_Abortable, we can rely that the call has
kono
parents:
diff changeset
311 -- been queued abortably at least once, and so the check for
kono
parents:
diff changeset
312 -- whether it is OK to advance to the abortable part of an
kono
parents:
diff changeset
313 -- async. select statement does not need to lock anything.
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 type Restricted_Entry_Call_Record is record
kono
parents:
diff changeset
316 Self : Task_Id;
kono
parents:
diff changeset
317 -- ID of the caller
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 Mode : Call_Modes;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 State : Entry_Call_State;
kono
parents:
diff changeset
322 pragma Atomic (State);
kono
parents:
diff changeset
323 -- Indicates part of the state of the call.
kono
parents:
diff changeset
324 --
kono
parents:
diff changeset
325 -- Protection: If the call is not on a queue, it should only be
kono
parents:
diff changeset
326 -- accessed by Self, and Self does not need any lock to modify this
kono
parents:
diff changeset
327 -- field.
kono
parents:
diff changeset
328 --
kono
parents:
diff changeset
329 -- Once the call is on a queue, the value should be something other
kono
parents:
diff changeset
330 -- than Done unless it is cancelled, and access is controller by the
kono
parents:
diff changeset
331 -- "server" of the queue -- i.e., the lock of Checked_To_Protection
kono
parents:
diff changeset
332 -- (Call_Target) if the call record is on the queue of a PO, or the
kono
parents:
diff changeset
333 -- lock of Called_Target if the call is on the queue of a task. See
kono
parents:
diff changeset
334 -- comments on type declaration for more details.
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 Uninterpreted_Data : System.Address;
kono
parents:
diff changeset
337 -- Data passed by the compiler
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 Exception_To_Raise : Ada.Exceptions.Exception_Id;
kono
parents:
diff changeset
340 -- The exception to raise once this call has been completed without
kono
parents:
diff changeset
341 -- being aborted.
kono
parents:
diff changeset
342 end record;
kono
parents:
diff changeset
343 pragma Suppress_Initialization (Restricted_Entry_Call_Record);
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 -------------------------------------------
kono
parents:
diff changeset
346 -- Task termination procedure definition --
kono
parents:
diff changeset
347 -------------------------------------------
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 -- We need to redefine here these types (already defined in
kono
parents:
diff changeset
350 -- Ada.Task_Termination) for avoiding circular dependencies.
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 type Cause_Of_Termination is (Normal, Abnormal, Unhandled_Exception);
kono
parents:
diff changeset
353 -- Possible causes for task termination:
kono
parents:
diff changeset
354 --
kono
parents:
diff changeset
355 -- Normal means that the task terminates due to completing the
kono
parents:
diff changeset
356 -- last sentence of its body, or as a result of waiting on a
kono
parents:
diff changeset
357 -- terminate alternative.
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 -- Abnormal means that the task terminates because it is being aborted
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 -- handled_Exception means that the task terminates because of exception
kono
parents:
diff changeset
362 -- raised by the execution of its task_body.
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 type Termination_Handler is access protected procedure
kono
parents:
diff changeset
365 (Cause : Cause_Of_Termination;
kono
parents:
diff changeset
366 T : Task_Id;
kono
parents:
diff changeset
367 X : Ada.Exceptions.Exception_Occurrence);
kono
parents:
diff changeset
368 -- Used to represent protected procedures to be executed when task
kono
parents:
diff changeset
369 -- terminates.
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 ------------------------------------
kono
parents:
diff changeset
372 -- Dispatching domain definitions --
kono
parents:
diff changeset
373 ------------------------------------
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 -- We need to redefine here these types (already defined in
kono
parents:
diff changeset
376 -- System.Multiprocessor.Dispatching_Domains) for avoiding circular
kono
parents:
diff changeset
377 -- dependencies.
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 type Dispatching_Domain is
kono
parents:
diff changeset
380 array (System.Multiprocessors.CPU range <>) of Boolean;
kono
parents:
diff changeset
381 -- A dispatching domain needs to contain the set of processors belonging
kono
parents:
diff changeset
382 -- to it. This is a processor mask where a True indicates that the
kono
parents:
diff changeset
383 -- processor belongs to the dispatching domain.
kono
parents:
diff changeset
384 -- Do not use the full range of CPU_Range because it would create a very
kono
parents:
diff changeset
385 -- long array. This way we can use the exact range of processors available
kono
parents:
diff changeset
386 -- in the system.
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 type Dispatching_Domain_Access is access Dispatching_Domain;
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 System_Domain : Dispatching_Domain_Access;
kono
parents:
diff changeset
391 -- All processors belong to default system dispatching domain at start up.
kono
parents:
diff changeset
392 -- We use a pointer which creates the actual variable for the reasons
kono
parents:
diff changeset
393 -- explained bellow in Dispatching_Domain_Tasks.
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 Dispatching_Domains_Frozen : Boolean := False;
kono
parents:
diff changeset
396 -- True when the main procedure has been called. Hence, no new dispatching
kono
parents:
diff changeset
397 -- domains can be created when this flag is True.
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 type Array_Allocated_Tasks is
kono
parents:
diff changeset
400 array (System.Multiprocessors.CPU range <>) of Natural;
kono
parents:
diff changeset
401 -- At start-up time, we need to store the number of tasks attached to
kono
parents:
diff changeset
402 -- concrete processors within the system domain (we can only create
kono
parents:
diff changeset
403 -- dispatching domains with processors belonging to the system domain and
kono
parents:
diff changeset
404 -- without tasks allocated).
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 type Array_Allocated_Tasks_Access is access Array_Allocated_Tasks;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 Dispatching_Domain_Tasks : Array_Allocated_Tasks_Access;
kono
parents:
diff changeset
409 -- We need to store whether there are tasks allocated to concrete
kono
parents:
diff changeset
410 -- processors in the default system dispatching domain because we need to
kono
parents:
diff changeset
411 -- check it before creating a new dispatching domain. Two comments about
kono
parents:
diff changeset
412 -- why we use a pointer here and not in package Dispatching_Domains:
kono
parents:
diff changeset
413 --
kono
parents:
diff changeset
414 -- 1) We use an array created dynamically in procedure Initialize which
kono
parents:
diff changeset
415 -- is called at the beginning of the initialization of the run-time
kono
parents:
diff changeset
416 -- library. Declaring a static array here in the spec would not work
kono
parents:
diff changeset
417 -- across different installations because it would get the value of
kono
parents:
diff changeset
418 -- Number_Of_CPUs from the machine where the run-time library is built,
kono
parents:
diff changeset
419 -- and not from the machine where the application is executed. That is
kono
parents:
diff changeset
420 -- the reason why we create the array (CPU'First .. Number_Of_CPUs) at
kono
parents:
diff changeset
421 -- execution time in the procedure body, ensuring that the function
kono
parents:
diff changeset
422 -- Number_Of_CPUs is executed at execution time (the same trick as we
kono
parents:
diff changeset
423 -- use for System_Domain).
kono
parents:
diff changeset
424 --
kono
parents:
diff changeset
425 -- 2) We have moved this declaration from package Dispatching_Domains
kono
parents:
diff changeset
426 -- because when we use a pragma CPU, the affinity is passed through the
kono
parents:
diff changeset
427 -- call to Create_Task. Hence, at this point, we may need to update the
kono
parents:
diff changeset
428 -- number of tasks associated to the processor, but we do not want to
kono
parents:
diff changeset
429 -- force a dependency from this package on Dispatching_Domains.
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 ------------------------------------
kono
parents:
diff changeset
432 -- Task related other definitions --
kono
parents:
diff changeset
433 ------------------------------------
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 type Activation_Chain is limited private;
kono
parents:
diff changeset
436 -- Linked list of to-be-activated tasks, linked through
kono
parents:
diff changeset
437 -- Activation_Link. The order of tasks on the list is irrelevant, because
kono
parents:
diff changeset
438 -- the priority rules will ensure that they actually start activating in
kono
parents:
diff changeset
439 -- priority order.
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 type Activation_Chain_Access is access all Activation_Chain;
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 type Task_Procedure_Access is access procedure (Arg : System.Address);
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 type Access_Boolean is access all Boolean;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 function Detect_Blocking return Boolean;
kono
parents:
diff changeset
448 pragma Inline (Detect_Blocking);
kono
parents:
diff changeset
449 -- Return whether the Detect_Blocking pragma is enabled
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 function Storage_Size (T : Task_Id) return System.Parameters.Size_Type;
kono
parents:
diff changeset
452 -- Retrieve from the TCB of the task the allocated size of its stack,
kono
parents:
diff changeset
453 -- either the system default or the size specified by a pragma. This is in
kono
parents:
diff changeset
454 -- general a non-static value that can depend on discriminants of the task.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 type Bit_Array is array (Integer range <>) of Boolean;
kono
parents:
diff changeset
457 pragma Pack (Bit_Array);
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 subtype Debug_Event_Array is Bit_Array (1 .. 16);
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 Global_Task_Debug_Event_Set : Boolean := False;
kono
parents:
diff changeset
462 -- Set True when running under debugger control and a task debug event
kono
parents:
diff changeset
463 -- signal has been requested.
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 ----------------------------------------------
kono
parents:
diff changeset
466 -- Ada_Task_Control_Block (ATCB) definition --
kono
parents:
diff changeset
467 ----------------------------------------------
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 -- Notes on protection (synchronization) of TRTS data structures
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 -- Any field of the TCB can be written by the activator of a task when the
kono
parents:
diff changeset
472 -- task is created, since no other task can access the new task's
kono
parents:
diff changeset
473 -- state until creation is complete.
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 -- The protection for each field is described in a comment starting with
kono
parents:
diff changeset
476 -- "Protection:".
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 -- When a lock is used to protect an ATCB field, this lock is simply named
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 -- Some protection is described in terms of tasks related to the
kono
parents:
diff changeset
481 -- ATCB being protected. These are:
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 -- Self: The task which is controlled by this ATCB
kono
parents:
diff changeset
484 -- Acceptor: A task accepting a call from Self
kono
parents:
diff changeset
485 -- Caller: A task calling an entry of Self
kono
parents:
diff changeset
486 -- Parent: The task executing the master on which Self depends
kono
parents:
diff changeset
487 -- Dependent: A task dependent on Self
kono
parents:
diff changeset
488 -- Activator: The task that created Self and initiated its activation
kono
parents:
diff changeset
489 -- Created: A task created and activated by Self
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 -- Note: The order of the fields is important to implement efficiently
kono
parents:
diff changeset
492 -- tasking support under gdb.
kono
parents:
diff changeset
493 -- Currently gdb relies on the order of the State, Parent, Base_Priority,
kono
parents:
diff changeset
494 -- Task_Image, Task_Image_Len, Call and LL fields.
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 -------------------------
kono
parents:
diff changeset
497 -- Common ATCB section --
kono
parents:
diff changeset
498 -------------------------
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 -- Section used by all GNARL implementations (regular and restricted)
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 type Common_ATCB is limited record
kono
parents:
diff changeset
503 State : Task_States;
kono
parents:
diff changeset
504 pragma Atomic (State);
kono
parents:
diff changeset
505 -- Encodes some basic information about the state of a task,
kono
parents:
diff changeset
506 -- including whether it has been activated, whether it is sleeping,
kono
parents:
diff changeset
507 -- and whether it is terminated.
kono
parents:
diff changeset
508 --
kono
parents:
diff changeset
509 -- Protection: Self.L
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 Parent : Task_Id;
kono
parents:
diff changeset
512 -- The task on which this task depends.
kono
parents:
diff changeset
513 -- See also Master_Level and Master_Within.
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 Base_Priority : System.Any_Priority;
kono
parents:
diff changeset
516 -- Base priority, not changed during entry calls, only changed
kono
parents:
diff changeset
517 -- via dynamic priorities package.
kono
parents:
diff changeset
518 --
kono
parents:
diff changeset
519 -- Protection: Only written by Self, accessed by anyone
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 Base_CPU : System.Multiprocessors.CPU_Range;
kono
parents:
diff changeset
522 -- Base CPU, only changed via dispatching domains package.
kono
parents:
diff changeset
523 --
kono
parents:
diff changeset
524 -- Protection: Self.L
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 Current_Priority : System.Any_Priority;
kono
parents:
diff changeset
527 -- Active priority, except that the effects of protected object
kono
parents:
diff changeset
528 -- priority ceilings are not reflected. This only reflects explicit
kono
parents:
diff changeset
529 -- priority changes and priority inherited through task activation
kono
parents:
diff changeset
530 -- and rendezvous.
kono
parents:
diff changeset
531 --
kono
parents:
diff changeset
532 -- Ada 95 notes: In Ada 95, this field will be transferred to the
kono
parents:
diff changeset
533 -- Priority field of an Entry_Calls component when an entry call is
kono
parents:
diff changeset
534 -- initiated. The Priority of the Entry_Calls component will not change
kono
parents:
diff changeset
535 -- for the duration of the call. The accepting task can use it to boost
kono
parents:
diff changeset
536 -- its own priority without fear of its changing in the meantime.
kono
parents:
diff changeset
537 --
kono
parents:
diff changeset
538 -- This can safely be used in the priority ordering of entry queues.
kono
parents:
diff changeset
539 -- Once a call is queued, its priority does not change.
kono
parents:
diff changeset
540 --
kono
parents:
diff changeset
541 -- Since an entry call cannot be made while executing a protected
kono
parents:
diff changeset
542 -- action, the priority of a task will never reflect a priority ceiling
kono
parents:
diff changeset
543 -- change at the point of an entry call.
kono
parents:
diff changeset
544 --
kono
parents:
diff changeset
545 -- Protection: Only written by Self, and only accessed when Acceptor
kono
parents:
diff changeset
546 -- accepts an entry or when Created activates, at which points Self is
kono
parents:
diff changeset
547 -- suspended.
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 Protected_Action_Nesting : Natural;
kono
parents:
diff changeset
550 pragma Atomic (Protected_Action_Nesting);
kono
parents:
diff changeset
551 -- The dynamic level of protected action nesting for this task. This
kono
parents:
diff changeset
552 -- field is needed for checking whether potentially blocking operations
kono
parents:
diff changeset
553 -- are invoked from protected actions. pragma Atomic is used because it
kono
parents:
diff changeset
554 -- can be read/written from protected interrupt handlers.
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 Task_Image : String (1 .. System.Parameters.Max_Task_Image_Length);
kono
parents:
diff changeset
557 -- Hold a string that provides a readable id for task, built from the
kono
parents:
diff changeset
558 -- variable of which it is a value or component.
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 Task_Image_Len : Natural;
kono
parents:
diff changeset
561 -- Actual length of Task_Image
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 Call : Entry_Call_Link;
kono
parents:
diff changeset
564 -- The entry call that has been accepted by this task.
kono
parents:
diff changeset
565 --
kono
parents:
diff changeset
566 -- Protection: Self.L. Self will modify this field when Self.Accepting
kono
parents:
diff changeset
567 -- is False, and will not need the mutex to do so. Once a task sets
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
568 -- Pending_ATC_Level = Level_Completed_Task, no other task can access
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
569 -- this field.
111
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 LL : aliased Task_Primitives.Private_Data;
kono
parents:
diff changeset
572 -- Control block used by the underlying low-level tasking service
kono
parents:
diff changeset
573 -- (GNULLI).
kono
parents:
diff changeset
574 --
kono
parents:
diff changeset
575 -- Protection: This is used only by the GNULLI implementation, which
kono
parents:
diff changeset
576 -- takes care of all of its synchronization.
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 Task_Arg : System.Address;
kono
parents:
diff changeset
579 -- The argument to task procedure. Provide a handle for discriminant
kono
parents:
diff changeset
580 -- information.
kono
parents:
diff changeset
581 --
kono
parents:
diff changeset
582 -- Protection: Part of the synchronization between Self and Activator.
kono
parents:
diff changeset
583 -- Activator writes it, once, before Self starts executing. Thereafter,
kono
parents:
diff changeset
584 -- Self only reads it.
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 Task_Alternate_Stack : System.Address;
kono
parents:
diff changeset
587 -- The address of the alternate signal stack for this task, if any
kono
parents:
diff changeset
588 --
kono
parents:
diff changeset
589 -- Protection: Only accessed by Self
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 Task_Entry_Point : Task_Procedure_Access;
kono
parents:
diff changeset
592 -- Information needed to call the procedure containing the code for
kono
parents:
diff changeset
593 -- the body of this task.
kono
parents:
diff changeset
594 --
kono
parents:
diff changeset
595 -- Protection: Part of the synchronization between Self and Activator.
kono
parents:
diff changeset
596 -- Activator writes it, once, before Self starts executing. Self reads
kono
parents:
diff changeset
597 -- it, once, as part of its execution.
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 Compiler_Data : System.Soft_Links.TSD;
kono
parents:
diff changeset
600 -- Task-specific data needed by the compiler to store per-task
kono
parents:
diff changeset
601 -- structures.
kono
parents:
diff changeset
602 --
kono
parents:
diff changeset
603 -- Protection: Only accessed by Self
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 All_Tasks_Link : Task_Id;
kono
parents:
diff changeset
606 -- Used to link this task to the list of all tasks in the system
kono
parents:
diff changeset
607 --
kono
parents:
diff changeset
608 -- Protection: RTS_Lock
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 Activation_Link : Task_Id;
kono
parents:
diff changeset
611 -- Used to link this task to a list of tasks to be activated
kono
parents:
diff changeset
612 --
kono
parents:
diff changeset
613 -- Protection: Only used by Activator
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 Activator : Task_Id;
kono
parents:
diff changeset
616 pragma Atomic (Activator);
kono
parents:
diff changeset
617 -- The task that created this task, either by declaring it as a task
kono
parents:
diff changeset
618 -- object or by executing a task allocator. The value is null iff Self
kono
parents:
diff changeset
619 -- has completed activation.
kono
parents:
diff changeset
620 --
kono
parents:
diff changeset
621 -- Protection: Set by Activator before Self is activated, and
kono
parents:
diff changeset
622 -- only modified by Self after that. Can be read by any task via
kono
parents:
diff changeset
623 -- Ada.Task_Identification.Activation_Is_Complete; hence Atomic.
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 Wait_Count : Natural;
kono
parents:
diff changeset
626 -- This count is used by a task that is waiting for other tasks. At all
kono
parents:
diff changeset
627 -- other times, the value should be zero. It is used differently in
kono
parents:
diff changeset
628 -- several different states. Since a task cannot be in more than one of
kono
parents:
diff changeset
629 -- these states at the same time, a single counter suffices.
kono
parents:
diff changeset
630 --
kono
parents:
diff changeset
631 -- Protection: Self.L
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 -- Activator_Sleep
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 -- This is the number of tasks that this task is activating, i.e. the
kono
parents:
diff changeset
636 -- children that have started activation but have not completed it.
kono
parents:
diff changeset
637 --
kono
parents:
diff changeset
638 -- Protection: Self.L and Created.L. Both mutexes must be locked, since
kono
parents:
diff changeset
639 -- Self.Activation_Count and Created.State must be synchronized.
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 -- Master_Completion_Sleep (phase 1)
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 -- This is the number dependent tasks of a master being completed by
kono
parents:
diff changeset
644 -- Self that are activated, but have not yet terminated, and are not
kono
parents:
diff changeset
645 -- waiting on a terminate alternative.
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 -- Master_Completion_2_Sleep (phase 2)
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 -- This is the count of tasks dependent on a master being completed by
kono
parents:
diff changeset
650 -- Self which are waiting on a terminate alternative.
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 Elaborated : Access_Boolean;
kono
parents:
diff changeset
653 -- Pointer to a flag indicating that this task's body has been
kono
parents:
diff changeset
654 -- elaborated. The flag is created and managed by the
kono
parents:
diff changeset
655 -- compiler-generated code.
kono
parents:
diff changeset
656 --
kono
parents:
diff changeset
657 -- Protection: The field itself is only accessed by Activator. The flag
kono
parents:
diff changeset
658 -- that it points to is updated by Master and read by Activator; access
kono
parents:
diff changeset
659 -- is assumed to be atomic.
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 Activation_Failed : Boolean;
kono
parents:
diff changeset
662 -- Set to True if activation of a chain of tasks fails,
kono
parents:
diff changeset
663 -- so that the activator should raise Tasking_Error.
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
666 -- System-specific attributes of the task as specified by the
kono
parents:
diff changeset
667 -- Task_Info pragma.
kono
parents:
diff changeset
668
kono
parents:
diff changeset
669 Analyzer : System.Stack_Usage.Stack_Analyzer;
kono
parents:
diff changeset
670 -- For storing information used to measure the stack usage
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 Global_Task_Lock_Nesting : Natural;
kono
parents:
diff changeset
673 -- This is the current nesting level of calls to
kono
parents:
diff changeset
674 -- System.Tasking.Initialization.Lock_Task. This allows a task to call
kono
parents:
diff changeset
675 -- Lock_Task multiple times without deadlocking. A task only locks
kono
parents:
diff changeset
676 -- Global_Task_Lock when its Global_Task_Lock_Nesting goes from 0 to 1,
kono
parents:
diff changeset
677 -- and only unlocked when it goes from 1 to 0.
kono
parents:
diff changeset
678 --
kono
parents:
diff changeset
679 -- Protection: Only accessed by Self
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 Fall_Back_Handler : Termination_Handler;
kono
parents:
diff changeset
682 -- This is the fall-back handler that applies to the dependent tasks of
kono
parents:
diff changeset
683 -- the task.
kono
parents:
diff changeset
684 --
kono
parents:
diff changeset
685 -- Protection: Self.L
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 Specific_Handler : Termination_Handler;
kono
parents:
diff changeset
688 -- This is the specific handler that applies only to this task, and not
kono
parents:
diff changeset
689 -- any of its dependent tasks.
kono
parents:
diff changeset
690 --
kono
parents:
diff changeset
691 -- Protection: Self.L
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 Debug_Events : Debug_Event_Array;
kono
parents:
diff changeset
694 -- Word length array of per task debug events, of which 11 kinds are
kono
parents:
diff changeset
695 -- currently defined in System.Tasking.Debugging package.
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 Domain : Dispatching_Domain_Access;
kono
parents:
diff changeset
698 -- Domain is the dispatching domain to which the task belongs. It is
kono
parents:
diff changeset
699 -- only changed via dispatching domains package. This field is made
kono
parents:
diff changeset
700 -- part of the Common_ATCB, even when restricted run-times (namely
kono
parents:
diff changeset
701 -- Ravenscar) do not use it, because this way the field is always
kono
parents:
diff changeset
702 -- available to the underlying layers to set the affinity and we do not
kono
parents:
diff changeset
703 -- need to do different things depending on the situation.
kono
parents:
diff changeset
704 --
kono
parents:
diff changeset
705 -- Protection: Self.L
kono
parents:
diff changeset
706 end record;
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 ---------------------------------------
kono
parents:
diff changeset
709 -- Restricted_Ada_Task_Control_Block --
kono
parents:
diff changeset
710 ---------------------------------------
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 -- This type should only be used by the restricted GNARLI and by restricted
kono
parents:
diff changeset
713 -- GNULL implementations to allocate an ATCB (see System.Task_Primitives.
kono
parents:
diff changeset
714 -- Operations.New_ATCB) that will take significantly less memory.
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 -- Note that the restricted GNARLI should only access fields that are
kono
parents:
diff changeset
717 -- present in the Restricted_Ada_Task_Control_Block structure.
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 type Restricted_Ada_Task_Control_Block (Entry_Num : Task_Entry_Index) is
kono
parents:
diff changeset
720 limited record
kono
parents:
diff changeset
721 Common : Common_ATCB;
kono
parents:
diff changeset
722 -- The common part between various tasking implementations
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 Entry_Call : aliased Restricted_Entry_Call_Record;
kono
parents:
diff changeset
725 -- Protection: This field is used on entry call "queues" associated
kono
parents:
diff changeset
726 -- with protected objects, and is protected by the protected object
kono
parents:
diff changeset
727 -- lock.
kono
parents:
diff changeset
728 end record;
kono
parents:
diff changeset
729 pragma Suppress_Initialization (Restricted_Ada_Task_Control_Block);
kono
parents:
diff changeset
730
kono
parents:
diff changeset
731 Interrupt_Manager_ID : Task_Id;
kono
parents:
diff changeset
732 -- This task ID is declared here to break circular dependencies.
kono
parents:
diff changeset
733 -- Also declare Interrupt_Manager_ID after Task_Id is known, to avoid
kono
parents:
diff changeset
734 -- generating unneeded finalization code.
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 -----------------------
kono
parents:
diff changeset
737 -- List of all Tasks --
kono
parents:
diff changeset
738 -----------------------
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 All_Tasks_List : Task_Id;
kono
parents:
diff changeset
741 -- Global linked list of all tasks
kono
parents:
diff changeset
742
kono
parents:
diff changeset
743 ------------------------------------------
kono
parents:
diff changeset
744 -- Regular (non restricted) definitions --
kono
parents:
diff changeset
745 ------------------------------------------
kono
parents:
diff changeset
746
kono
parents:
diff changeset
747 --------------------------------
kono
parents:
diff changeset
748 -- Master Related Definitions --
kono
parents:
diff changeset
749 --------------------------------
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 subtype Master_Level is Integer;
kono
parents:
diff changeset
752 subtype Master_ID is Master_Level;
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 -- Normally, a task starts out with internal master nesting level one
kono
parents:
diff changeset
755 -- larger than external master nesting level. It is incremented by one by
kono
parents:
diff changeset
756 -- Enter_Master, which is called in the task body only if the compiler
kono
parents:
diff changeset
757 -- thinks the task may have dependent tasks. It is set to 1 for the
kono
parents:
diff changeset
758 -- environment task, the level 2 is reserved for server tasks of the
kono
parents:
diff changeset
759 -- run-time system (the so called "independent tasks"), and the level 3 is
kono
parents:
diff changeset
760 -- for the library level tasks. Foreign threads which are detected by
kono
parents:
diff changeset
761 -- the run-time have a level of 0, allowing these tasks to be easily
kono
parents:
diff changeset
762 -- distinguished if needed.
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 Foreign_Task_Level : constant Master_Level := 0;
kono
parents:
diff changeset
765 Environment_Task_Level : constant Master_Level := 1;
kono
parents:
diff changeset
766 Independent_Task_Level : constant Master_Level := 2;
kono
parents:
diff changeset
767 Library_Task_Level : constant Master_Level := 3;
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 -------------------
kono
parents:
diff changeset
770 -- Priority info --
kono
parents:
diff changeset
771 -------------------
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 Unspecified_Priority : constant Integer := System.Priority'First - 1;
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 Priority_Not_Boosted : constant Integer := System.Priority'First - 1;
kono
parents:
diff changeset
776 -- Definition of Priority actually has to come from the RTS configuration
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 subtype Rendezvous_Priority is Integer
kono
parents:
diff changeset
779 range Priority_Not_Boosted .. System.Any_Priority'Last;
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 -------------------
kono
parents:
diff changeset
782 -- Affinity info --
kono
parents:
diff changeset
783 -------------------
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 Unspecified_CPU : constant := -1;
kono
parents:
diff changeset
786 -- No affinity specified
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 ------------------------------------
kono
parents:
diff changeset
789 -- Rendezvous related definitions --
kono
parents:
diff changeset
790 ------------------------------------
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 No_Rendezvous : constant := 0;
kono
parents:
diff changeset
793
kono
parents:
diff changeset
794 Max_Select : constant Integer := Integer'Last;
kono
parents:
diff changeset
795 -- RTS-defined
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 subtype Select_Index is Integer range No_Rendezvous .. Max_Select;
kono
parents:
diff changeset
798 -- type Select_Index is range No_Rendezvous .. Max_Select;
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 subtype Positive_Select_Index is
kono
parents:
diff changeset
801 Select_Index range 1 .. Select_Index'Last;
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 type Accept_Alternative is record
kono
parents:
diff changeset
804 Null_Body : Boolean;
kono
parents:
diff changeset
805 S : Task_Entry_Index;
kono
parents:
diff changeset
806 end record;
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 type Accept_List is
kono
parents:
diff changeset
809 array (Positive_Select_Index range <>) of Accept_Alternative;
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 type Accept_List_Access is access constant Accept_List;
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 -----------------------------------
kono
parents:
diff changeset
814 -- ATC_Level related definitions --
kono
parents:
diff changeset
815 -----------------------------------
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 Max_ATC_Nesting : constant Natural := 20;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
818 -- The maximum number of nested asynchronous select statements supported
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
819 -- by the runtime.
111
kono
parents:
diff changeset
820
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
821 subtype ATC_Level_Base is Integer range -1 .. Max_ATC_Nesting;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
822 -- Indicates the number of nested asynchronous task control statements
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
823 -- or entries a task is in.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
824
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
825 Level_Completed_Task : constant ATC_Level_Base := -1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
826 -- ATC_Level of a task that has "completed". A task reaches the completed
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
827 -- state after an abort, exception propagation, or normal exit.
111
kono
parents:
diff changeset
828
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
829 Level_No_ATC_Occurring : constant ATC_Level_Base := 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
830 -- ATC_Level of a task not executing a entry call or an asynchronous
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
831 -- select statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
832
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
833 Level_No_Pending_Abort : constant ATC_Level_Base := ATC_Level_Base'Last;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
834 -- ATC_Level when there is no pending abort
111
kono
parents:
diff changeset
835
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
836 subtype ATC_Level is ATC_Level_Base range
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
837 Level_No_ATC_Occurring .. Level_No_Pending_Abort - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
838 -- Nested ATC_Levels valid during the execution of a task
111
kono
parents:
diff changeset
839
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
840 subtype ATC_Level_Index is ATC_Level range
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
841 Level_No_ATC_Occurring + 1 .. ATC_Level'Last;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
842 -- ATC_Levels valid when a task is executing an entry call or asynchronous
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
843 -- task control statements.
111
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 ----------------------------------
kono
parents:
diff changeset
846 -- Entry_Call_Record definition --
kono
parents:
diff changeset
847 ----------------------------------
kono
parents:
diff changeset
848
kono
parents:
diff changeset
849 type Entry_Call_Record is record
kono
parents:
diff changeset
850 Self : Task_Id;
kono
parents:
diff changeset
851 -- ID of the caller
kono
parents:
diff changeset
852
kono
parents:
diff changeset
853 Mode : Call_Modes;
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 State : Entry_Call_State;
kono
parents:
diff changeset
856 pragma Atomic (State);
kono
parents:
diff changeset
857 -- Indicates part of the state of the call
kono
parents:
diff changeset
858 --
kono
parents:
diff changeset
859 -- Protection: If the call is not on a queue, it should only be
kono
parents:
diff changeset
860 -- accessed by Self, and Self does not need any lock to modify this
kono
parents:
diff changeset
861 -- field. Once the call is on a queue, the value should be something
kono
parents:
diff changeset
862 -- other than Done unless it is cancelled, and access is controller by
kono
parents:
diff changeset
863 -- the "server" of the queue -- i.e., the lock of Checked_To_Protection
kono
parents:
diff changeset
864 -- (Call_Target) if the call record is on the queue of a PO, or the
kono
parents:
diff changeset
865 -- lock of Called_Target if the call is on the queue of a task. See
kono
parents:
diff changeset
866 -- comments on type declaration for more details.
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 Uninterpreted_Data : System.Address;
kono
parents:
diff changeset
869 -- Data passed by the compiler
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 Exception_To_Raise : Ada.Exceptions.Exception_Id;
kono
parents:
diff changeset
872 -- The exception to raise once this call has been completed without
kono
parents:
diff changeset
873 -- being aborted.
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 Prev : Entry_Call_Link;
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877 Next : Entry_Call_Link;
kono
parents:
diff changeset
878
kono
parents:
diff changeset
879 Level : ATC_Level;
kono
parents:
diff changeset
880 -- One of Self and Level are redundant in this implementation, since
kono
parents:
diff changeset
881 -- each Entry_Call_Record is at Self.Entry_Calls (Level). Since we must
kono
parents:
diff changeset
882 -- have access to the entry call record to be reading this, we could
kono
parents:
diff changeset
883 -- get Self from Level, or Level from Self. However, this requires
kono
parents:
diff changeset
884 -- non-portable address arithmetic.
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 E : Entry_Index;
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 Prio : System.Any_Priority;
kono
parents:
diff changeset
889
kono
parents:
diff changeset
890 -- The above fields are those that there may be some hope of packing.
kono
parents:
diff changeset
891 -- They are gathered together to allow for compilers that lay records
kono
parents:
diff changeset
892 -- out contiguously, to allow for such packing.
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 Called_Task : Task_Id;
kono
parents:
diff changeset
895 pragma Atomic (Called_Task);
kono
parents:
diff changeset
896 -- Use for task entry calls. The value is null if the call record is
kono
parents:
diff changeset
897 -- not in use. Conversely, unless State is Done and Onqueue is false,
kono
parents:
diff changeset
898 -- Called_Task points to an ATCB.
kono
parents:
diff changeset
899 --
kono
parents:
diff changeset
900 -- Protection: Called_Task.L
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 Called_PO : System.Address;
kono
parents:
diff changeset
903 pragma Atomic (Called_PO);
kono
parents:
diff changeset
904 -- Similar to Called_Task but for protected objects
kono
parents:
diff changeset
905 --
kono
parents:
diff changeset
906 -- Note that the previous implementation tried to merge both
kono
parents:
diff changeset
907 -- Called_Task and Called_PO but this ended up in many unexpected
kono
parents:
diff changeset
908 -- complications (e.g having to add a magic number in the ATCB, which
kono
parents:
diff changeset
909 -- caused gdb lots of confusion) with no real gain since the
kono
parents:
diff changeset
910 -- Lock_Server implementation still need to loop around chasing for
kono
parents:
diff changeset
911 -- pointer changes even with a single pointer.
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 Acceptor_Prev_Call : Entry_Call_Link;
kono
parents:
diff changeset
914 -- For task entry calls only
kono
parents:
diff changeset
915
kono
parents:
diff changeset
916 Acceptor_Prev_Priority : Rendezvous_Priority := Priority_Not_Boosted;
kono
parents:
diff changeset
917 -- For task entry calls only. The priority of the most recent prior
kono
parents:
diff changeset
918 -- call being serviced. For protected entry calls, this function should
kono
parents:
diff changeset
919 -- be performed by GNULLI ceiling locking.
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 Cancellation_Attempted : Boolean := False;
kono
parents:
diff changeset
922 pragma Atomic (Cancellation_Attempted);
kono
parents:
diff changeset
923 -- Cancellation of the call has been attempted.
kono
parents:
diff changeset
924 -- Consider merging this into State???
kono
parents:
diff changeset
925
kono
parents:
diff changeset
926 With_Abort : Boolean := False;
kono
parents:
diff changeset
927 -- Tell caller whether the call may be aborted
kono
parents:
diff changeset
928 -- ??? consider merging this with Was_Abortable state
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930 Needs_Requeue : Boolean := False;
kono
parents:
diff changeset
931 -- Temporary to tell acceptor of task entry call that
kono
parents:
diff changeset
932 -- Exceptional_Complete_Rendezvous needs to do requeue.
kono
parents:
diff changeset
933 end record;
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 ------------------------------------
kono
parents:
diff changeset
936 -- Task related other definitions --
kono
parents:
diff changeset
937 ------------------------------------
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 type Access_Address is access all System.Address;
kono
parents:
diff changeset
940 -- Anonymous pointer used to implement task attributes (see s-tataat.adb
kono
parents:
diff changeset
941 -- and a-tasatt.adb)
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 pragma No_Strict_Aliasing (Access_Address);
kono
parents:
diff changeset
944 -- This type is used in contexts where aliasing may be an issue (see
kono
parents:
diff changeset
945 -- for example s-tataat.adb), so we avoid any incorrect aliasing
kono
parents:
diff changeset
946 -- assumptions.
kono
parents:
diff changeset
947
kono
parents:
diff changeset
948 ----------------------------------------------
kono
parents:
diff changeset
949 -- Ada_Task_Control_Block (ATCB) definition --
kono
parents:
diff changeset
950 ----------------------------------------------
kono
parents:
diff changeset
951
kono
parents:
diff changeset
952 type Entry_Call_Array is array (ATC_Level_Index) of
kono
parents:
diff changeset
953 aliased Entry_Call_Record;
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 type Atomic_Address is mod Memory_Size;
kono
parents:
diff changeset
956 pragma Atomic (Atomic_Address);
kono
parents:
diff changeset
957 type Attribute_Array is
kono
parents:
diff changeset
958 array (1 .. Parameters.Max_Attribute_Count) of Atomic_Address;
kono
parents:
diff changeset
959 -- Array of task attributes. The value (Atomic_Address) will either be
kono
parents:
diff changeset
960 -- converted to a task attribute if it fits, or to a pointer to a record
kono
parents:
diff changeset
961 -- by Ada.Task_Attributes.
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 type Task_Serial_Number is mod 2 ** Long_Long_Integer'Size;
kono
parents:
diff changeset
964 -- Used to give each task a unique serial number. We want 64-bits for this
kono
parents:
diff changeset
965 -- type to get as much uniqueness as possible (2**64 is operationally
kono
parents:
diff changeset
966 -- infinite in this context, but 2**32 perhaps could recycle). We use
kono
parents:
diff changeset
967 -- Long_Long_Integer (which in the normal case is always 64-bits) rather
kono
parents:
diff changeset
968 -- than 64-bits explicitly to allow codepeer to analyze this unit when
kono
parents:
diff changeset
969 -- a target configuration file forces the maximum integer size to 32.
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index) is limited record
kono
parents:
diff changeset
972 Common : Common_ATCB;
kono
parents:
diff changeset
973 -- The common part between various tasking implementations
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 Entry_Calls : Entry_Call_Array;
kono
parents:
diff changeset
976 -- An array of entry calls
kono
parents:
diff changeset
977 --
kono
parents:
diff changeset
978 -- Protection: The elements of this array are on entry call queues
kono
parents:
diff changeset
979 -- associated with protected objects or task entries, and are protected
kono
parents:
diff changeset
980 -- by the protected object lock or Acceptor.L, respectively.
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 New_Base_Priority : System.Any_Priority;
kono
parents:
diff changeset
983 -- New value for Base_Priority (for dynamic priorities package)
kono
parents:
diff changeset
984 --
kono
parents:
diff changeset
985 -- Protection: Self.L
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 Open_Accepts : Accept_List_Access;
kono
parents:
diff changeset
988 -- This points to the Open_Accepts array of accept alternatives passed
kono
parents:
diff changeset
989 -- to the RTS by the compiler-generated code to Selective_Wait. It is
kono
parents:
diff changeset
990 -- non-null iff this task is ready to accept an entry call.
kono
parents:
diff changeset
991 --
kono
parents:
diff changeset
992 -- Protection: Self.L
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 Chosen_Index : Select_Index;
kono
parents:
diff changeset
995 -- The index in Open_Accepts of the entry call accepted by a selective
kono
parents:
diff changeset
996 -- wait executed by this task.
kono
parents:
diff changeset
997 --
kono
parents:
diff changeset
998 -- Protection: Written by both Self and Caller. Usually protected by
kono
parents:
diff changeset
999 -- Self.L. However, once the selection is known to have been written it
kono
parents:
diff changeset
1000 -- can be accessed without protection. This happens after Self has
kono
parents:
diff changeset
1001 -- updated it itself using information from a suspended Caller, or
kono
parents:
diff changeset
1002 -- after Caller has updated it and awakened Self.
kono
parents:
diff changeset
1003
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1004 Master_Of_Task : Master_Level;
111
kono
parents:
diff changeset
1005 -- The task executing the master of this task, and the ID of this task's
kono
parents:
diff changeset
1006 -- master (unique only among masters currently active within Parent).
kono
parents:
diff changeset
1007 --
kono
parents:
diff changeset
1008 -- Protection: Set by Activator before Self is activated, and read
kono
parents:
diff changeset
1009 -- after Self is activated.
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 Master_Within : Master_Level;
kono
parents:
diff changeset
1012 -- The ID of the master currently executing within this task; that is,
kono
parents:
diff changeset
1013 -- the most deeply nested currently active master.
kono
parents:
diff changeset
1014 --
kono
parents:
diff changeset
1015 -- Protection: Only written by Self, and only read by Self or by
kono
parents:
diff changeset
1016 -- dependents when Self is attempting to exit a master. Since Self will
kono
parents:
diff changeset
1017 -- not write this field until the master is complete, the
kono
parents:
diff changeset
1018 -- synchronization should be adequate to prevent races.
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 Alive_Count : Natural := 0;
kono
parents:
diff changeset
1021 -- Number of tasks directly dependent on this task (including itself)
kono
parents:
diff changeset
1022 -- that are still "alive", i.e. not terminated.
kono
parents:
diff changeset
1023 --
kono
parents:
diff changeset
1024 -- Protection: Self.L
kono
parents:
diff changeset
1025
kono
parents:
diff changeset
1026 Awake_Count : Natural := 0;
kono
parents:
diff changeset
1027 -- Number of tasks directly dependent on this task (including itself)
kono
parents:
diff changeset
1028 -- still "awake", i.e., are not terminated and not waiting on a
kono
parents:
diff changeset
1029 -- terminate alternative.
kono
parents:
diff changeset
1030 --
kono
parents:
diff changeset
1031 -- Invariant: Awake_Count <= Alive_Count
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 -- Protection: Self.L
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 -- Beginning of flags
kono
parents:
diff changeset
1036
kono
parents:
diff changeset
1037 Aborting : Boolean := False;
kono
parents:
diff changeset
1038 pragma Atomic (Aborting);
kono
parents:
diff changeset
1039 -- Self is in the process of aborting. While set, prevents multiple
kono
parents:
diff changeset
1040 -- abort signals from being sent by different aborter while abort
kono
parents:
diff changeset
1041 -- is acted upon. This is essential since an aborter which calls
kono
parents:
diff changeset
1042 -- Abort_To_Level could set the Pending_ATC_Level to yet a lower level
kono
parents:
diff changeset
1043 -- (than the current level), may be preempted and would send the
kono
parents:
diff changeset
1044 -- abort signal when resuming execution. At this point, the abortee
kono
parents:
diff changeset
1045 -- may have completed abort to the proper level such that the
kono
parents:
diff changeset
1046 -- signal (and resulting abort exception) are not handled any more.
kono
parents:
diff changeset
1047 -- In other words, the flag prevents a race between multiple aborters
kono
parents:
diff changeset
1048 --
kono
parents:
diff changeset
1049 -- Protection: protected by atomic access.
kono
parents:
diff changeset
1050
kono
parents:
diff changeset
1051 ATC_Hack : Boolean := False;
kono
parents:
diff changeset
1052 pragma Atomic (ATC_Hack);
kono
parents:
diff changeset
1053 -- ?????
kono
parents:
diff changeset
1054 -- Temporary fix, to allow Undefer_Abort to reset Aborting in the
kono
parents:
diff changeset
1055 -- handler for Abort_Signal that encloses an async. entry call.
kono
parents:
diff changeset
1056 -- For the longer term, this should be done via code in the
kono
parents:
diff changeset
1057 -- handler itself.
kono
parents:
diff changeset
1058
kono
parents:
diff changeset
1059 Callable : Boolean := True;
kono
parents:
diff changeset
1060 -- It is OK to call entries of this task
kono
parents:
diff changeset
1061
kono
parents:
diff changeset
1062 Dependents_Aborted : Boolean := False;
kono
parents:
diff changeset
1063 -- This is set to True by whichever task takes responsibility for
kono
parents:
diff changeset
1064 -- aborting the dependents of this task.
kono
parents:
diff changeset
1065 --
kono
parents:
diff changeset
1066 -- Protection: Self.L
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 Interrupt_Entry : Boolean := False;
kono
parents:
diff changeset
1069 -- Indicates if one or more Interrupt Entries are attached to the task.
kono
parents:
diff changeset
1070 -- This flag is needed for cleaning up the Interrupt Entry bindings.
kono
parents:
diff changeset
1071
kono
parents:
diff changeset
1072 Pending_Action : Boolean := False;
kono
parents:
diff changeset
1073 -- Unified flag indicating some action needs to be take when abort
kono
parents:
diff changeset
1074 -- next becomes undeferred. Currently set if:
kono
parents:
diff changeset
1075 -- . Pending_Priority_Change is set
kono
parents:
diff changeset
1076 -- . Pending_ATC_Level is changed
kono
parents:
diff changeset
1077 -- . Requeue involving POs
kono
parents:
diff changeset
1078 -- (Abortable field may have changed and the Wait_Until_Abortable
kono
parents:
diff changeset
1079 -- has to recheck the abortable status of the call.)
kono
parents:
diff changeset
1080 -- . Exception_To_Raise is non-null
kono
parents:
diff changeset
1081 --
kono
parents:
diff changeset
1082 -- Protection: Self.L
kono
parents:
diff changeset
1083 --
kono
parents:
diff changeset
1084 -- This should never be reset back to False outside of the procedure
kono
parents:
diff changeset
1085 -- Do_Pending_Action, which is called by Undefer_Abort. It should only
kono
parents:
diff changeset
1086 -- be set to True by Set_Priority and Abort_To_Level.
kono
parents:
diff changeset
1087
kono
parents:
diff changeset
1088 Pending_Priority_Change : Boolean := False;
kono
parents:
diff changeset
1089 -- Flag to indicate pending priority change (for dynamic priorities
kono
parents:
diff changeset
1090 -- package). The base priority is updated on the next abort
kono
parents:
diff changeset
1091 -- completion point (aka. synchronization point).
kono
parents:
diff changeset
1092 --
kono
parents:
diff changeset
1093 -- Protection: Self.L
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 Terminate_Alternative : Boolean := False;
kono
parents:
diff changeset
1096 -- Task is accepting Select with Terminate Alternative
kono
parents:
diff changeset
1097 --
kono
parents:
diff changeset
1098 -- Protection: Self.L
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 -- End of flags
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 -- Beginning of counts
kono
parents:
diff changeset
1103
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1104 ATC_Nesting_Level : ATC_Level := Level_No_ATC_Occurring;
111
kono
parents:
diff changeset
1105 -- The dynamic level of ATC nesting (currently executing nested
kono
parents:
diff changeset
1106 -- asynchronous select statements) in this task.
kono
parents:
diff changeset
1107
kono
parents:
diff changeset
1108 -- Protection: Self_ID.L. Only Self reads or updates this field.
kono
parents:
diff changeset
1109 -- Decrementing it deallocates an Entry_Calls component, and care must
kono
parents:
diff changeset
1110 -- be taken that all references to that component are eliminated before
kono
parents:
diff changeset
1111 -- doing the decrement. This in turn will require locking a protected
kono
parents:
diff changeset
1112 -- object (for a protected entry call) or the Acceptor's lock (for a
kono
parents:
diff changeset
1113 -- task entry call). No other task should attempt to read or modify
kono
parents:
diff changeset
1114 -- this value.
kono
parents:
diff changeset
1115
kono
parents:
diff changeset
1116 Deferral_Level : Natural := 1;
kono
parents:
diff changeset
1117 -- This is the number of times that Defer_Abort has been called by
kono
parents:
diff changeset
1118 -- this task without a matching Undefer_Abort call. Abortion is only
kono
parents:
diff changeset
1119 -- allowed when this zero. It is initially 1, to protect the task at
kono
parents:
diff changeset
1120 -- startup.
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 -- Protection: Only updated by Self; access assumed to be atomic
kono
parents:
diff changeset
1123
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1124 Pending_ATC_Level : ATC_Level_Base := Level_No_Pending_Abort;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1125 -- Indicates the ATC level to which this task is currently being
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1126 -- aborted. Two special values exist:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1127 --
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1128 -- * Level_Completed_Task: the task has completed.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1129 --
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1130 -- * Level_No_Pending_Abort: the task is not being aborted to any
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1131 -- level.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1132 --
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1133 -- All other values indicate the task has not completed. This should
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1134 -- ONLY be modified by Abort_To_Level and Exit_One_ATC_Level.
111
kono
parents:
diff changeset
1135 --
kono
parents:
diff changeset
1136 -- Protection: Self.L
kono
parents:
diff changeset
1137
kono
parents:
diff changeset
1138 Serial_Number : Task_Serial_Number;
kono
parents:
diff changeset
1139 -- Monotonic counter to provide some way to check locking rules/ordering
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 Known_Tasks_Index : Integer := -1;
kono
parents:
diff changeset
1142 -- Index in the System.Tasking.Debug.Known_Tasks array
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 User_State : Long_Integer := 0;
kono
parents:
diff changeset
1145 -- User-writeable location, for use in debugging tasks; also provides a
kono
parents:
diff changeset
1146 -- simple task specific data.
kono
parents:
diff changeset
1147
kono
parents:
diff changeset
1148 Free_On_Termination : Boolean := False;
kono
parents:
diff changeset
1149 -- Deallocate the ATCB when the task terminates. This flag is normally
kono
parents:
diff changeset
1150 -- False, and is set True when Unchecked_Deallocation is called on a
kono
parents:
diff changeset
1151 -- non-terminated task so that the associated storage is automatically
kono
parents:
diff changeset
1152 -- reclaimed when the task terminates.
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 Attributes : Attribute_Array := (others => 0);
kono
parents:
diff changeset
1155 -- Task attributes
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 -- IMPORTANT Note: the Entry_Queues field is last for efficiency of
kono
parents:
diff changeset
1158 -- access to other fields, do not put new fields after this one.
kono
parents:
diff changeset
1159
kono
parents:
diff changeset
1160 Entry_Queues : Task_Entry_Queue_Array (1 .. Entry_Num);
kono
parents:
diff changeset
1161 -- An array of task entry queues
kono
parents:
diff changeset
1162 --
kono
parents:
diff changeset
1163 -- Protection: Self.L. Once a task has set Self.Stage to Completing, it
kono
parents:
diff changeset
1164 -- has exclusive access to this field.
kono
parents:
diff changeset
1165 end record;
kono
parents:
diff changeset
1166
kono
parents:
diff changeset
1167 --------------------
kono
parents:
diff changeset
1168 -- Initialization --
kono
parents:
diff changeset
1169 --------------------
kono
parents:
diff changeset
1170
kono
parents:
diff changeset
1171 procedure Initialize;
kono
parents:
diff changeset
1172 -- This procedure constitutes the first part of the initialization of the
kono
parents:
diff changeset
1173 -- GNARL. This includes creating data structures to make the initial thread
kono
parents:
diff changeset
1174 -- into the environment task. The last part of the initialization is done
kono
parents:
diff changeset
1175 -- in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
kono
parents:
diff changeset
1176 -- All the initializations used to be in Tasking.Initialization, but this
kono
parents:
diff changeset
1177 -- is no longer possible with the run time simplification (including
kono
parents:
diff changeset
1178 -- optimized PO and the restricted run time) since one cannot rely on
kono
parents:
diff changeset
1179 -- System.Tasking.Initialization being present, as was done before.
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 procedure Initialize_ATCB
kono
parents:
diff changeset
1182 (Self_ID : Task_Id;
kono
parents:
diff changeset
1183 Task_Entry_Point : Task_Procedure_Access;
kono
parents:
diff changeset
1184 Task_Arg : System.Address;
kono
parents:
diff changeset
1185 Parent : Task_Id;
kono
parents:
diff changeset
1186 Elaborated : Access_Boolean;
kono
parents:
diff changeset
1187 Base_Priority : System.Any_Priority;
kono
parents:
diff changeset
1188 Base_CPU : System.Multiprocessors.CPU_Range;
kono
parents:
diff changeset
1189 Domain : Dispatching_Domain_Access;
kono
parents:
diff changeset
1190 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
1191 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
1192 T : Task_Id;
kono
parents:
diff changeset
1193 Success : out Boolean);
kono
parents:
diff changeset
1194 -- Initialize fields of the TCB for task T, and link into global TCB
kono
parents:
diff changeset
1195 -- structures. Call this only with abort deferred and holding RTS_Lock.
kono
parents:
diff changeset
1196 -- Self_ID is the calling task (normally the activator of T). Success is
kono
parents:
diff changeset
1197 -- set to indicate whether the TCB was successfully initialized.
kono
parents:
diff changeset
1198
kono
parents:
diff changeset
1199 private
kono
parents:
diff changeset
1200
kono
parents:
diff changeset
1201 Null_Task : constant Task_Id := null;
kono
parents:
diff changeset
1202
kono
parents:
diff changeset
1203 type Activation_Chain is limited record
kono
parents:
diff changeset
1204 T_ID : Task_Id;
kono
parents:
diff changeset
1205 end record;
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207 -- Activation_Chain is an in-out parameter of initialization procedures and
kono
parents:
diff changeset
1208 -- it must be passed by reference because the init proc may terminate
kono
parents:
diff changeset
1209 -- abnormally after creating task components, and these must be properly
kono
parents:
diff changeset
1210 -- registered for removal (Expunge_Unactivated_Tasks). The "limited" forces
kono
parents:
diff changeset
1211 -- Activation_Chain to be a by-reference type; see RM-6.2(4).
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 function Number_Of_Entries (Self_Id : Task_Id) return Entry_Index;
kono
parents:
diff changeset
1214 -- Given a task, return the number of entries it contains
kono
parents:
diff changeset
1215 end System.Tasking;