1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . I N I T I A L I Z A T I O N --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
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- --
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- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
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. --
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/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 pragma Style_Checks
(All_Checks
);
33 -- Turn off subprogram alpha ordering check, since we group soft link bodies
34 -- and dummy soft link bodies together separately in this unit.
37 with System
.Soft_Links
;
38 with System
.Soft_Links
.Tasking
;
39 with System
.Task_Primitives
;
40 with System
.Task_Primitives
.Operations
;
41 with System
.Tasking
.Debug
;
42 with System
.Tasking
.Task_Attributes
;
44 with System
.Secondary_Stack
;
45 pragma Elaborate_All
(System
.Secondary_Stack
);
46 pragma Unreferenced
(System
.Secondary_Stack
);
47 -- Make sure the body of Secondary_Stack is elaborated before calling
48 -- Init_Tasking_Soft_Links. See comments for this routine for explanation.
50 package body System
.Tasking
.Initialization
is
52 package SOL
renames System
.OS_Locks
;
53 package SSL
renames System
.Soft_Links
;
54 package STPO
renames System
.Task_Primitives
.Operations
;
57 use Task_Primitives
.Operations
;
59 Global_Task_Lock
: aliased SOL
.RTS_Lock
;
60 -- This is a global lock; it is used to execute in mutual exclusion from
61 -- all other tasks. It is only used by Task_Lock, Task_Unlock, and
64 ----------------------------------------------------------------------
65 -- Tasking versions of some services needed by non-tasking programs --
66 ----------------------------------------------------------------------
68 procedure Abort_Defer
;
69 -- NON-INLINE versions without Self_ID for soft links
71 procedure Abort_Undefer
;
72 -- NON-INLINE versions without Self_ID for soft links
75 -- Locks out other tasks. Preceding a section of code by Task_Lock and
76 -- following it by Task_Unlock creates a critical region. This is used
77 -- for ensuring that a region of non-tasking code (such as code used to
78 -- allocate memory) is tasking safe. Note that it is valid for calls to
79 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
80 -- only the corresponding outer level Task_Unlock will actually unlock.
82 procedure Task_Unlock
;
83 -- Releases lock previously set by call to Task_Lock. In the nested case,
84 -- all nested locks must be released before other tasks competing for the
85 -- tasking lock are released.
87 function Get_Current_Excep
return SSL
.EOA
;
88 -- Task-safe version of SSL.Get_Current_Excep
90 function Task_Name
return String;
91 -- Returns current task's name
93 procedure Initialize_RTS_Lock
(Addr
: Address
);
94 -- Initialize the RTS lock at Addr
96 procedure Finalize_RTS_Lock
(Addr
: Address
);
97 -- Finalize the RTS lock at Addr
99 procedure Acquire_RTS_Lock
(Addr
: Address
);
100 -- Acquire the RTS lock at Addr
102 procedure Release_RTS_Lock
(Addr
: Address
);
103 -- Release the RTS lock at Addr
105 ----------------------------
106 -- Tasking Initialization --
107 ----------------------------
110 -- This procedure completes the initialization of the GNARL. The first part
111 -- of the initialization is done in the body of System.Tasking. It consists
112 -- of initializing global locks, and installing tasking versions of certain
113 -- operations used by the compiler. Init_RTS is called during elaboration.
115 procedure Tasking_Runtime_Initialize
;
116 pragma Export
(Ada
, Tasking_Runtime_Initialize
,
117 "__gnat_tasking_runtime_initialize");
118 -- This procedure starts the initialization of the GNARL. It installs the
119 -- tasking versions of the RTS_Lock manipulation routines. It is called
120 -- very early before the elaboration of all the Ada units of the program,
121 -- including those of the runtime, because this elaboration may require
122 -- the initialization of RTS_Lock objects.
124 --------------------------
125 -- Change_Base_Priority --
126 --------------------------
128 -- Call only with abort deferred and holding Self_ID locked
130 procedure Change_Base_Priority
(T
: Task_Id
) is
132 if T
.Common
.Base_Priority
/= T
.New_Base_Priority
then
133 T
.Common
.Base_Priority
:= T
.New_Base_Priority
;
134 Set_Priority
(T
, T
.Common
.Base_Priority
);
136 end Change_Base_Priority
;
138 ------------------------
139 -- Check_Abort_Status --
140 ------------------------
142 function Check_Abort_Status
return Integer is
143 Self_ID
: constant Task_Id
:= Self
;
146 and then Self_ID
.Deferral_Level
= 0
147 and then Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
148 and then not Self_ID
.Aborting
154 end Check_Abort_Status
;
160 procedure Defer_Abort
(Self_ID
: Task_Id
) is
166 pragma Assert
(Self_ID
.Deferral_Level
= 0);
169 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level);
171 -- The above check has been useful in detecting mismatched defer/undefer
172 -- pairs. You may uncomment it when testing on systems that support
175 -- If the OS supports preemptive abort (e.g. pthread_kill), it should
176 -- have happened already. A problem is with systems that do not support
177 -- preemptive abort, and so rely on polling. On such systems we may get
178 -- false failures of the assertion, since polling for pending abort does
179 -- no occur until the abort undefer operation.
181 -- Even on systems that only poll for abort, the assertion may be useful
182 -- for catching missed abort completion polling points. The operations
183 -- that undefer abort poll for pending aborts. This covers most of the
184 -- places where the core Ada semantics require abort to be caught,
185 -- without any special attention. However, this generally happens on
186 -- exit from runtime system call, which means a pending abort will not
187 -- be noticed on the way into the runtime system. We considered adding a
188 -- check for pending aborts at this point, but chose not to, because of
189 -- the overhead. Instead, we searched for RTS calls where abort
190 -- completion is required and a task could go farther than Ada allows
191 -- before undeferring abort; we then modified the code to ensure the
192 -- abort would be detected.
194 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
197 --------------------------
198 -- Defer_Abort_Nestable --
199 --------------------------
201 procedure Defer_Abort_Nestable
(Self_ID
: Task_Id
) is
207 -- The following assertion is by default disabled. See the comment in
208 -- Defer_Abort on the situations in which it may be useful to uncomment
209 -- this assertion and enable the test.
212 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level or else
213 -- Self_ID.Deferral_Level > 0);
215 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
216 end Defer_Abort_Nestable
;
222 procedure Abort_Defer
is
229 Self_ID
:= STPO
.Self
;
230 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
233 -----------------------
234 -- Get_Current_Excep --
235 -----------------------
237 function Get_Current_Excep
return SSL
.EOA
is
239 return STPO
.Self
.Common
.Compiler_Data
.Current_Excep
'Access;
240 end Get_Current_Excep
;
242 -------------------------
243 -- Initialize_RTS_Lock --
244 -------------------------
246 procedure Initialize_RTS_Lock
(Addr
: Address
) is
247 Lock
: aliased SOL
.RTS_Lock
;
248 for Lock
'Address use Addr
;
249 pragma Import
(Ada
, Lock
);
252 Initialize_Lock
(Lock
'Unchecked_Access, PO_Level
);
253 end Initialize_RTS_Lock
;
255 -----------------------
256 -- Finalize_RTS_Lock --
257 -----------------------
259 procedure Finalize_RTS_Lock
(Addr
: Address
) is
260 Lock
: aliased SOL
.RTS_Lock
;
261 for Lock
'Address use Addr
;
262 pragma Import
(Ada
, Lock
);
265 Finalize_Lock
(Lock
'Unchecked_Access);
266 end Finalize_RTS_Lock
;
268 ----------------------
269 -- Acquire_RTS_Lock --
270 ----------------------
272 procedure Acquire_RTS_Lock
(Addr
: Address
) is
273 Lock
: aliased SOL
.RTS_Lock
;
274 for Lock
'Address use Addr
;
275 pragma Import
(Ada
, Lock
);
278 Write_Lock
(Lock
'Unchecked_Access);
279 end Acquire_RTS_Lock
;
281 ----------------------
282 -- Release_RTS_Lock --
283 ----------------------
285 procedure Release_RTS_Lock
(Addr
: Address
) is
286 Lock
: aliased SOL
.RTS_Lock
;
287 for Lock
'Address use Addr
;
288 pragma Import
(Ada
, Lock
);
291 Unlock
(Lock
'Unchecked_Access);
292 end Release_RTS_Lock
;
294 -----------------------
295 -- Do_Pending_Action --
296 -----------------------
298 -- Call only when holding no locks
300 procedure Do_Pending_Action
(Self_ID
: Task_Id
) is
303 pragma Assert
(Self_ID
= Self
and then Self_ID
.Deferral_Level
= 0);
305 -- Needs loop to recheck for pending action in case a new one occurred
306 -- while we had abort deferred below.
309 -- Temporarily defer abort so that we can lock Self_ID
311 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
313 Write_Lock
(Self_ID
);
314 Self_ID
.Pending_Action
:= False;
317 -- Restore the original Deferral value
319 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
321 if not Self_ID
.Pending_Action
then
322 if Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
then
323 if not Self_ID
.Aborting
then
324 Self_ID
.Aborting
:= True;
326 (Debug
.Trace
(Self_ID
, "raise Abort_Signal", 'B'));
327 raise Standard
'Abort_Signal;
329 pragma Assert
(not Self_ID
.ATC_Hack
);
331 elsif Self_ID
.ATC_Hack
then
333 -- The solution really belongs in the Abort_Signal handler
334 -- for async. entry calls. The present hack is very
335 -- fragile. It relies that the very next point after
336 -- Exit_One_ATC_Level at which the task becomes abortable
337 -- will be the call to Undefer_Abort in the
338 -- Abort_Signal handler.
340 Self_ID
.ATC_Hack
:= False;
344 (Self_ID
, "raise Abort_Signal (ATC hack)", 'B'));
345 raise Standard
'Abort_Signal;
352 end Do_Pending_Action
;
354 -----------------------
355 -- Final_Task_Unlock --
356 -----------------------
358 -- This version is only for use in Terminate_Task, when the task is
359 -- relinquishing further rights to its own ATCB.
361 -- There is a very interesting potential race condition there, where the
362 -- old task may run concurrently with a new task that is allocated the old
363 -- tasks (now reused) ATCB. The critical thing here is to not make any
364 -- reference to the ATCB after the lock is released. See also comments on
365 -- Terminate_Task and Unlock.
367 procedure Final_Task_Unlock
(Self_ID
: Task_Id
) is
369 pragma Assert
(Self_ID
.Common
.Global_Task_Lock_Nesting
= 1);
370 Unlock
(Global_Task_Lock
'Access);
371 end Final_Task_Unlock
;
377 procedure Init_RTS
is
382 -- Terminate run time (regular vs restricted) specific initialization
383 -- of the environment task.
385 Self_Id
:= Environment_Task
;
386 Self_Id
.Master_Of_Task
:= Environment_Task_Level
;
387 Self_Id
.Master_Within
:= Self_Id
.Master_Of_Task
+ 1;
389 for L
in Self_Id
.Entry_Calls
'Range loop
390 Self_Id
.Entry_Calls
(L
).Self
:= Self_Id
;
391 Self_Id
.Entry_Calls
(L
).Level
:= L
;
394 Self_Id
.Awake_Count
:= 1;
395 Self_Id
.Alive_Count
:= 1;
397 -- Normally, a task starts out with internal master nesting level one
398 -- larger than external master nesting level. It is incremented to one
399 -- by Enter_Master, which is called in the task body only if the
400 -- compiler thinks the task may have dependent tasks. There is no
401 -- corresponding call to Enter_Master for the environment task, so we
402 -- would need to increment it to 2 here. Instead, we set it to 3. By
403 -- doing this we reserve the level 2 for server tasks of the runtime
404 -- system. The environment task does not need to wait for these server
406 Self_Id
.Master_Within
:= Library_Task_Level
;
408 -- Initialize lock used to implement mutual exclusion between all tasks
410 Initialize_Lock
(Global_Task_Lock
'Access, STPO
.Global_Task_Level
);
412 -- Notify that the tasking run time has been elaborated so that
413 -- the tasking version of the soft links can be used.
416 SSL
.Abort_Defer
:= Abort_Defer
'Access;
417 SSL
.Abort_Undefer
:= Abort_Undefer
'Access;
420 SSL
.Lock_Task
:= Task_Lock
'Access;
421 SSL
.Unlock_Task
:= Task_Unlock
'Access;
422 SSL
.Check_Abort_Status
:= Check_Abort_Status
'Access;
423 SSL
.Task_Name
:= Task_Name
'Access;
424 SSL
.Get_Current_Excep
:= Get_Current_Excep
'Access;
426 -- Initialize the tasking soft links (if not done yet) that are common
427 -- to the full and the restricted run times.
429 SSL
.Tasking
.Init_Tasking_Soft_Links
;
431 -- Abort is deferred in a new ATCB, so we need to undefer abort at this
432 -- stage to make the environment task abortable.
434 Undefer_Abort
(Environment_Task
);
437 --------------------------------
438 -- Tasking_Runtime_Initialize --
439 --------------------------------
441 procedure Tasking_Runtime_Initialize
is
443 SSL
.Initialize_RTS_Lock
:= Initialize_RTS_Lock
'Access;
444 SSL
.Finalize_RTS_Lock
:= Finalize_RTS_Lock
'Access;
445 SSL
.Acquire_RTS_Lock
:= Acquire_RTS_Lock
'Access;
446 SSL
.Release_RTS_Lock
:= Release_RTS_Lock
'Access;
447 end Tasking_Runtime_Initialize
;
449 ---------------------------
450 -- Locked_Abort_To_Level--
451 ---------------------------
453 -- Abort a task to the specified ATC nesting level.
454 -- Call this only with T locked.
456 -- An earlier version of this code contained a call to Wakeup. That should
457 -- not be necessary here, if Abort_Task is implemented correctly, since
458 -- Abort_Task should include the effect of Wakeup. However, the above call
459 -- was in earlier versions of this file, and at least for some targets
460 -- Abort_Task has not been doing Wakeup. It should not hurt to uncomment
461 -- the above call, until the error is corrected for all targets.
463 -- See extended comments in package body System.Tasking.Abort for the
464 -- overall design of the implementation of task abort.
465 -- ??? there is no such package ???
467 -- If the task is sleeping it will be in an abort-deferred region, and will
468 -- not have Abort_Signal raised by Abort_Task. Such an "abort deferral" is
469 -- just to protect the RTS internals, and not necessarily required to
470 -- enforce Ada semantics. Abort_Task should wake the task up and let it
471 -- decide if it wants to complete the aborted construct immediately.
473 -- Note that the effect of the low-level Abort_Task is not persistent.
474 -- If the target task is not blocked, this wakeup will be missed.
476 -- We don't bother calling Abort_Task if this task is aborting itself,
477 -- since we are inside the RTS and have abort deferred. Similarly, We don't
478 -- bother to call Abort_Task if T is terminated, since there is no need to
479 -- abort a terminated task, and it could be dangerous to try if the task
480 -- has stopped executing.
482 -- Note that an earlier version of this code had some false reasoning about
483 -- being able to reliably wake up a task that had suspended on a blocking
484 -- system call that does not atomically release the task's lock (e.g., UNIX
485 -- nanosleep, which we once thought could be used to implement delays).
486 -- That still left the possibility of missed wakeups.
488 -- We cannot safely call Vulnerable_Complete_Activation here, since that
489 -- requires locking Self_ID.Parent. The anti-deadlock lock ordering rules
490 -- would then require us to release the lock on Self_ID first, which would
491 -- create a timing window for other tasks to lock Self_ID. This is
492 -- significant for tasks that may be aborted before their execution can
493 -- enter the task body, and so they do not get a chance to call
494 -- Complete_Task. The actual work for this case is done in Terminate_Task.
496 procedure Locked_Abort_To_Level
502 if not T
.Aborting
and then T
/= Self_ID
then
503 case T
.Common
.State
is
507 pragma Assert
(Standard
.False);
513 if T
.ATC_Nesting_Level
> Level_No_ATC_Occurring
then
514 -- This scenario occurs when an asynchronous protected entry
515 -- call is canceled during a requeue with abort.
518 (T
.ATC_Nesting_Level
).Cancellation_Attempted
:= True;
521 when Interrupt_Server_Blocked_On_Event_Flag
=>
524 when AST_Server_Sleep
527 | Interrupt_Server_Blocked_Interrupt_Sleep
528 | Interrupt_Server_Idle_Sleep
531 Wakeup
(T
, T
.Common
.State
);
533 when Acceptor_Delay_Sleep
536 T
.Open_Accepts
:= null;
537 Wakeup
(T
, T
.Common
.State
);
539 when Entry_Caller_Sleep
=>
540 pragma Assert
(T
.ATC_Nesting_Level
> Level_No_ATC_Occurring
);
543 (T
.ATC_Nesting_Level
).Cancellation_Attempted
:= True;
544 Wakeup
(T
, T
.Common
.State
);
548 | Master_Completion_Sleep
549 | Master_Phase_2_Sleep
555 if T
.Pending_ATC_Level
> L
then
556 T
.Pending_ATC_Level
:= L
;
557 T
.Pending_Action
:= True;
559 if L
= Level_Completed_Task
then
563 -- This prevents aborted task from accepting calls
567 -- The test above is just a heuristic, to reduce wasteful
568 -- calls to Abort_Task. We are holding T locked, and this
569 -- value will not be set to False except with T also locked,
570 -- inside Exit_One_ATC_Level, so we should not miss wakeups.
572 if T
.Common
.State
= Acceptor_Sleep
574 T
.Common
.State
= Acceptor_Delay_Sleep
576 T
.Open_Accepts
:= null;
579 elsif T
/= Self_ID
and then
580 (T
.Common
.State
= Runnable
581 or else T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
)
583 -- The task is blocked on a system call waiting for the
584 -- completion event. In this case Abort_Task may need to take
585 -- special action in order to succeed.
591 end Locked_Abort_To_Level
;
593 --------------------------------
594 -- Remove_From_All_Tasks_List --
595 --------------------------------
597 procedure Remove_From_All_Tasks_List
(T
: Task_Id
) is
603 (Debug
.Trace
(Self
, "Remove_From_All_Tasks_List", 'C'));
605 Previous
:= Null_Task
;
607 while C
/= Null_Task
loop
609 if Previous
= Null_Task
then
610 All_Tasks_List
:= All_Tasks_List
.Common
.All_Tasks_Link
;
612 Previous
.Common
.All_Tasks_Link
:= C
.Common
.All_Tasks_Link
;
619 C
:= C
.Common
.All_Tasks_Link
;
622 pragma Assert
(Standard
.False);
623 end Remove_From_All_Tasks_List
;
629 procedure Task_Lock
(Self_ID
: Task_Id
) is
631 Self_ID
.Common
.Global_Task_Lock_Nesting
:=
632 Self_ID
.Common
.Global_Task_Lock_Nesting
+ 1;
634 if Self_ID
.Common
.Global_Task_Lock_Nesting
= 1 then
635 Defer_Abort_Nestable
(Self_ID
);
636 Write_Lock
(Global_Task_Lock
'Access);
640 procedure Task_Lock
is
642 Task_Lock
(STPO
.Self
);
649 function Task_Name
return String is
650 Self_Id
: constant Task_Id
:= STPO
.Self
;
652 return Self_Id
.Common
.Task_Image
(1 .. Self_Id
.Common
.Task_Image_Len
);
659 procedure Task_Unlock
(Self_ID
: Task_Id
) is
661 pragma Assert
(Self_ID
.Common
.Global_Task_Lock_Nesting
> 0);
662 Self_ID
.Common
.Global_Task_Lock_Nesting
:=
663 Self_ID
.Common
.Global_Task_Lock_Nesting
- 1;
665 if Self_ID
.Common
.Global_Task_Lock_Nesting
= 0 then
666 Unlock
(Global_Task_Lock
'Access);
667 Undefer_Abort_Nestable
(Self_ID
);
671 procedure Task_Unlock
is
673 Task_Unlock
(STPO
.Self
);
680 -- Precondition : Self does not hold any locks
682 -- Undefer_Abort is called on any abort completion point (aka.
683 -- synchronization point). It performs the following actions if they
684 -- are pending: (1) change the base priority, (2) abort the task.
686 -- The priority change has to occur before abort. Otherwise, it would
687 -- take effect no earlier than the next abort completion point.
689 procedure Undefer_Abort
(Self_ID
: Task_Id
) is
695 pragma Assert
(Self_ID
.Deferral_Level
= 1);
697 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
699 if Self_ID
.Deferral_Level
= 0 then
700 pragma Assert
(Check_No_Locks
(Self_ID
));
702 if Self_ID
.Pending_Action
then
703 Do_Pending_Action
(Self_ID
);
708 ----------------------------
709 -- Undefer_Abort_Nestable --
710 ----------------------------
712 -- An earlier version would re-defer abort if an abort is in progress.
713 -- Then, we modified the effect of the raise statement so that it defers
714 -- abort until control reaches a handler. That was done to prevent
715 -- "skipping over" a handler if another asynchronous abort occurs during
716 -- the propagation of the abort to the handler.
718 -- There has been talk of reversing that decision, based on a newer
719 -- implementation of exception propagation. Care must be taken to evaluate
720 -- how such a change would interact with the above code and all the places
721 -- where abort-deferral is used to bridge over critical transitions, such
722 -- as entry to the scope of a region with a finalizer and entry into the
723 -- body of an accept-procedure.
725 procedure Undefer_Abort_Nestable
(Self_ID
: Task_Id
) is
731 pragma Assert
(Self_ID
.Deferral_Level
> 0);
733 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
735 if Self_ID
.Deferral_Level
= 0 then
737 pragma Assert
(Check_No_Locks
(Self_ID
));
739 if Self_ID
.Pending_Action
then
740 Do_Pending_Action
(Self_ID
);
743 end Undefer_Abort_Nestable
;
749 procedure Abort_Undefer
is
756 Self_ID
:= STPO
.Self
;
758 if Self_ID
.Deferral_Level
= 0 then
760 -- In case there are different views on whether Abort is supported
761 -- between the expander and the run time, we may end up with
762 -- Self_ID.Deferral_Level being equal to zero, when called from
763 -- the procedure created by the expander that corresponds to a
764 -- task body. In this case, there's nothing to be done.
766 -- See related code in System.Tasking.Stages.Create_Task resetting
767 -- Deferral_Level when System.Restrictions.Abort_Allowed is False.
772 pragma Assert
(Self_ID
.Deferral_Level
> 0);
773 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
775 if Self_ID
.Deferral_Level
= 0 then
776 pragma Assert
(Check_No_Locks
(Self_ID
));
778 if Self_ID
.Pending_Action
then
779 Do_Pending_Action
(Self_ID
);
784 --------------------------
785 -- Wakeup_Entry_Caller --
786 --------------------------
788 -- This is called at the end of service of an entry call, to abort the
789 -- caller if he is in an abortable part, and to wake up the caller if it
790 -- is on Entry_Caller_Sleep. It assumes that the call is already off-queue.
792 -- (This enforces the rule that a task must be off-queue if its state is
793 -- Done or Cancelled.) Call it holding the lock of Entry_Call.Self.
795 -- Timed_Call or Simple_Call:
796 -- The caller is waiting on Entry_Caller_Sleep, in
797 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
800 -- The caller might be in Wait_For_Completion,
801 -- waiting for a rendezvous (possibly requeued without abort)
804 -- Asynchronous_Call:
805 -- The caller may be executing in the abortable part o
806 -- an async. select, or on a time delay,
807 -- if Entry_Call.State >= Was_Abortable.
809 procedure Wakeup_Entry_Caller
811 Entry_Call
: Entry_Call_Link
;
812 New_State
: Entry_Call_State
)
814 Caller
: constant Task_Id
:= Entry_Call
.Self
;
817 pragma Debug
(Debug
.Trace
818 (Self_ID
, "Wakeup_Entry_Caller", 'E', Caller
));
819 pragma Assert
(New_State
= Done
or else New_State
= Cancelled
);
821 pragma Assert
(Caller
.Common
.State
/= Unactivated
);
823 Entry_Call
.State
:= New_State
;
825 if Entry_Call
.Mode
= Asynchronous_Call
then
827 -- Abort the caller in his abortable part, but do so only if call has
828 -- been queued abortably.
830 if Entry_Call
.State
>= Was_Abortable
or else New_State
= Done
then
831 Locked_Abort_To_Level
(Self_ID
, Caller
, Entry_Call
.Level
- 1);
834 elsif Caller
.Common
.State
= Entry_Caller_Sleep
then
835 Wakeup
(Caller
, Entry_Caller_Sleep
);
837 end Wakeup_Entry_Caller
;
839 -------------------------
840 -- Finalize_Attributes --
841 -------------------------
843 procedure Finalize_Attributes
(T
: Task_Id
) is
844 Attr
: System
.Address
;
847 for J
in T
.Attributes
'Range loop
848 Attr
:= T
.Attributes
(J
);
850 if Attr
/= 0 and then Task_Attributes
.Require_Finalization
(J
) then
851 Task_Attributes
.To_Attribute
(Attr
).Free
(Attr
);
852 T
.Attributes
(J
) := 0;
855 end Finalize_Attributes
;
859 end System
.Tasking
.Initialization
;