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