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