1 ------------------------------------------------------------------------------
3 -- GNU ADA 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-2004, 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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 pragma Style_Checks
(All_Checks
);
35 -- Turn off subprogram alpha ordering check, since we group soft link
36 -- bodies and dummy soft link bodies together separately in this unit.
39 -- Turn polling off for this package. We don't need polling during any
40 -- of the routines in this package, and more to the point, if we try
41 -- to poll it can cause infinite loops.
44 -- used for Exception_Occurrence_Access.
47 pragma Elaborate_All
(System
.Tasking
);
48 -- ensure that the first step initializations have been performed
50 with System
.Task_Primitives
;
53 with System
.Task_Primitives
.Operations
;
54 -- used for Set_Priority
59 with System
.Soft_Links
;
60 -- used for the non-tasking routines (*_NT) that refer to global data.
61 -- They are needed here before the tasking run time has been elaborated.
63 with System
.Soft_Links
.Tasking
;
64 -- Used for Init_Tasking_Soft_Links
66 with System
.Tasking
.Debug
;
69 with System
.Stack_Checking
;
71 with System
.Parameters
;
72 -- used for Single_Lock
74 package body System
.Tasking
.Initialization
is
76 package STPO
renames System
.Task_Primitives
.Operations
;
77 package SSL
renames System
.Soft_Links
;
78 package AE
renames Ada
.Exceptions
;
81 use Task_Primitives
.Operations
;
83 Global_Task_Lock
: aliased System
.Task_Primitives
.RTS_Lock
;
84 -- This is a global lock; it is used to execute in mutual exclusion
85 -- from all other tasks. It is only used by Task_Lock,
86 -- Task_Unlock, and Final_Task_Unlock.
88 function Current_Target_Exception
return AE
.Exception_Occurrence
;
90 (Ada
, Current_Target_Exception
, "__gnat_current_target_exception");
91 -- Import this subprogram from the private part of Ada.Exceptions.
93 ----------------------------------------------------------------------
94 -- Tasking versions of some services needed by non-tasking programs --
95 ----------------------------------------------------------------------
98 -- Locks out other tasks. Preceding a section of code by Task_Lock and
99 -- following it by Task_Unlock creates a critical region. This is used
100 -- for ensuring that a region of non-tasking code (such as code used to
101 -- allocate memory) is tasking safe. Note that it is valid for calls to
102 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
103 -- only the corresponding outer level Task_Unlock will actually unlock.
105 procedure Task_Unlock
;
106 -- Releases lock previously set by call to Task_Lock. In the nested case,
107 -- all nested locks must be released before other tasks competing for the
108 -- tasking lock are released.
110 function Get_Exc_Stack_Addr
return Address
;
111 -- Get the exception stack for the current task
113 procedure Set_Exc_Stack_Addr
(Self_ID
: Address
; Addr
: Address
);
114 -- Self_ID is the Task_Id of the task that gets the exception stack.
115 -- For Self_ID = Null_Address, the current task gets the exception stack.
117 function Get_Stack_Info
return Stack_Checking
.Stack_Access
;
118 -- Get access to the current task's Stack_Info
120 procedure Update_Exception
121 (X
: AE
.Exception_Occurrence
:= Current_Target_Exception
);
122 -- Handle exception setting and check for pending actions
124 function Task_Name
return String;
125 -- Returns current task's name
127 ------------------------
128 -- Local Subprograms --
129 ------------------------
131 ----------------------------
132 -- Tasking Initialization --
133 ----------------------------
135 procedure Gnat_Install_Locks
(Lock
, Unlock
: SSL
.No_Param_Proc
);
136 pragma Import
(C
, Gnat_Install_Locks
, "__gnatlib_install_locks");
137 -- Used by Init_RTS to install procedure Lock and Unlock for the
138 -- thread locking. This has no effect on GCC 2. For GCC 3,
139 -- it has an effect only if gcc is configured with
140 -- --enable_threads=gnat.
143 -- This procedure completes the initialization of the GNARL. The first
144 -- part of the initialization is done in the body of System.Tasking.
145 -- It consists of initializing global locks, and installing tasking
146 -- versions of certain operations used by the compiler. Init_RTS is called
147 -- during elaboration.
149 --------------------------
150 -- Change_Base_Priority --
151 --------------------------
153 -- Call only with abort deferred and holding Self_ID locked.
155 procedure Change_Base_Priority
(T
: Task_Id
) is
157 if T
.Common
.Base_Priority
/= T
.New_Base_Priority
then
158 T
.Common
.Base_Priority
:= T
.New_Base_Priority
;
159 Set_Priority
(T
, T
.Common
.Base_Priority
);
161 end Change_Base_Priority
;
163 ------------------------
164 -- Check_Abort_Status --
165 ------------------------
167 function Check_Abort_Status
return Integer is
168 Self_ID
: constant Task_Id
:= Self
;
170 if Self_ID
/= null and then Self_ID
.Deferral_Level
= 0
171 and then Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
177 end Check_Abort_Status
;
183 procedure Defer_Abort
(Self_ID
: Task_Id
) is
185 if No_Abort
and then not Dynamic_Priority_Support
then
189 pragma Assert
(Self_ID
.Deferral_Level
= 0);
192 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level);
194 -- The above check has been useful in detecting mismatched defer/undefer
195 -- pairs. You may uncomment it when testing on systems that support
198 -- If the OS supports preemptive abort (e.g. pthread_kill), it should
199 -- have happened already. A problem is with systems that do not support
200 -- preemptive abort, and so rely on polling. On such systems we may get
201 -- false failures of the assertion, since polling for pending abort does
202 -- no occur until the abort undefer operation.
204 -- Even on systems that only poll for abort, the assertion may be useful
205 -- for catching missed abort completion polling points. The operations
206 -- that undefer abort poll for pending aborts. This covers most of the
207 -- places where the core Ada semantics require abort to be caught,
208 -- without any special attention. However, this generally happens on
209 -- exit from runtime system call, which means a pending abort will not
210 -- be noticed on the way into the runtime system. We considered adding a
211 -- check for pending aborts at this point, but chose not to, because of
212 -- the overhead. Instead, we searched for RTS calls where abort
213 -- completion is required and a task could go farther than Ada allows
214 -- before undeferring abort; we then modified the code to ensure the
215 -- abort would be detected.
217 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
220 --------------------------
221 -- Defer_Abort_Nestable --
222 --------------------------
224 procedure Defer_Abort_Nestable
(Self_ID
: Task_Id
) is
226 if No_Abort
and then not Dynamic_Priority_Support
then
231 -- ((Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level or else
232 -- Self_ID.Deferral_Level > 0));
234 -- See comment in Defer_Abort on the situations in which it may be
235 -- useful to uncomment the above assertion.
237 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
238 end Defer_Abort_Nestable
;
244 procedure Defer_Abortion
is
248 if No_Abort
and then not Dynamic_Priority_Support
then
252 Self_ID
:= STPO
.Self
;
253 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
256 -----------------------
257 -- Do_Pending_Action --
258 -----------------------
260 -- Call only when holding no locks
262 procedure Do_Pending_Action
(Self_ID
: Task_Id
) is
263 use type Ada
.Exceptions
.Exception_Id
;
266 pragma Assert
(Self_ID
= Self
and then Self_ID
.Deferral_Level
= 0);
268 -- Needs loop to recheck for pending action in case a new one occurred
269 -- while we had abort deferred below.
272 -- Temporarily defer abortion so that we can lock Self_ID.
274 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
+ 1;
280 Write_Lock
(Self_ID
);
281 Self_ID
.Pending_Action
:= False;
282 Poll_Base_Priority_Change
(Self_ID
);
289 -- Restore the original Deferral value.
291 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
293 if not Self_ID
.Pending_Action
then
294 if Self_ID
.Pending_ATC_Level
< Self_ID
.ATC_Nesting_Level
then
295 if not Self_ID
.Aborting
then
296 Self_ID
.Aborting
:= True;
298 (Debug
.Trace
(Self_ID
, "raise Abort_Signal", 'B'));
299 raise Standard
'Abort_Signal;
301 pragma Assert
(not Self_ID
.ATC_Hack
);
303 elsif Self_ID
.ATC_Hack
then
304 -- The solution really belongs in the Abort_Signal handler
305 -- for async. entry calls. The present hack is very
306 -- fragile. It relies that the very next point after
307 -- Exit_One_ATC_Level at which the task becomes abortable
308 -- will be the call to Undefer_Abort in the
309 -- Abort_Signal handler.
311 Self_ID
.ATC_Hack
:= False;
315 (Self_ID
, "raise Abort_Signal (ATC hack)", 'B'));
316 raise Standard
'Abort_Signal;
323 end Do_Pending_Action
;
325 -----------------------
326 -- Final_Task_Unlock --
327 -----------------------
329 -- This version is only for use in Terminate_Task, when the task
330 -- is relinquishing further rights to its own ATCB.
331 -- There is a very interesting potential race condition there, where
332 -- the old task may run concurrently with a new task that is allocated
333 -- the old tasks (now reused) ATCB. The critical thing here is to
334 -- not make any reference to the ATCB after the lock is released.
335 -- See also comments on Terminate_Task and Unlock.
337 procedure Final_Task_Unlock
(Self_ID
: Task_Id
) is
339 pragma Assert
(Self_ID
.Global_Task_Lock_Nesting
= 1);
340 Unlock
(Global_Task_Lock
'Access, Global_Lock
=> True);
341 end Final_Task_Unlock
;
347 procedure Init_RTS
is
351 -- Terminate run time (regular vs restricted) specific initialization
352 -- of the environment task.
354 Self_Id
:= Environment_Task
;
355 Self_Id
.Master_of_Task
:= Environment_Task_Level
;
356 Self_Id
.Master_Within
:= Self_Id
.Master_of_Task
+ 1;
358 for L
in Self_Id
.Entry_Calls
'Range loop
359 Self_Id
.Entry_Calls
(L
).Self
:= Self_Id
;
360 Self_Id
.Entry_Calls
(L
).Level
:= L
;
363 Self_Id
.Awake_Count
:= 1;
364 Self_Id
.Alive_Count
:= 1;
366 Self_Id
.Master_Within
:= Library_Task_Level
;
367 -- Normally, a task starts out with internal master nesting level
368 -- one larger than external master nesting level. It is incremented
369 -- to one by Enter_Master, which is called in the task body only if
370 -- the compiler thinks the task may have dependent tasks. There is no
371 -- corresponding call to Enter_Master for the environment task, so we
372 -- would need to increment it to 2 here. Instead, we set it to 3.
373 -- By doing this we reserve the level 2 for server tasks of the runtime
374 -- system. The environment task does not need to wait for these server
376 -- Initialize lock used to implement mutual exclusion between all tasks
378 Initialize_Lock
(Global_Task_Lock
'Access, STPO
.Global_Task_Level
);
380 -- Notify that the tasking run time has been elaborated so that
381 -- the tasking version of the soft links can be used.
383 if not No_Abort
or else Dynamic_Priority_Support
then
384 SSL
.Abort_Defer
:= Defer_Abortion
'Access;
385 SSL
.Abort_Undefer
:= Undefer_Abortion
'Access;
388 SSL
.Update_Exception
:= Update_Exception
'Access;
389 SSL
.Lock_Task
:= Task_Lock
'Access;
390 SSL
.Unlock_Task
:= Task_Unlock
'Access;
391 SSL
.Get_Exc_Stack_Addr
:= Get_Exc_Stack_Addr
'Access;
392 SSL
.Set_Exc_Stack_Addr
:= Set_Exc_Stack_Addr
'Access;
393 SSL
.Check_Abort_Status
:= Check_Abort_Status
'Access;
394 SSL
.Get_Stack_Info
:= Get_Stack_Info
'Access;
395 SSL
.Task_Name
:= Task_Name
'Access;
397 SSL
.Set_Exc_Stack_Addr
(Null_Address
, SSL
.Get_Exc_Stack_Addr_NT
);
399 -- Initialize the tasking soft links (if not done yet) that are common
400 -- to the full and the restricted run times.
402 SSL
.Tasking
.Init_Tasking_Soft_Links
;
404 -- Install tasking locks in the GCC runtime.
406 Gnat_Install_Locks
(Task_Lock
'Access, Task_Unlock
'Access);
408 -- Abortion is deferred in a new ATCB, so we need to undefer abortion
409 -- at this stage to make the environment task abortable.
411 Undefer_Abort
(Environment_Task
);
414 ---------------------------
415 -- Locked_Abort_To_Level--
416 ---------------------------
418 -- Abort a task to the specified ATC nesting level.
419 -- Call this only with T locked.
421 -- An earlier version of this code contained a call to Wakeup. That
422 -- should not be necessary here, if Abort_Task is implemented correctly,
423 -- since Abort_Task should include the effect of Wakeup. However, the
424 -- above call was in earlier versions of this file, and at least for
425 -- some targets Abort_Task has not beek doing Wakeup. It should not
426 -- hurt to uncomment the above call, until the error is corrected for
429 -- See extended comments in package body System.Tasking.Abortion
430 -- for the overall design of the implementation of task abort.
432 -- If the task is sleeping it will be in an abort-deferred region,
433 -- and will not have Abort_Signal raised by Abort_Task.
434 -- Such an "abort deferral" is just to protect the RTS internals,
435 -- and not necessarily required to enforce Ada semantics.
436 -- Abort_Task should wake the task up and let it decide if it wants
437 -- to complete the aborted construct immediately.
439 -- Note that the effect of the lowl-level Abort_Task is not persistent.
440 -- If the target task is not blocked, this wakeup will be missed.
442 -- We don't bother calling Abort_Task if this task is aborting itself,
443 -- since we are inside the RTS and have abort deferred. Similarly, We
444 -- don't bother to call Abort_Task if T is terminated, since there is
445 -- no need to abort a terminated task, and it could be dangerous to try
446 -- if the task has stopped executing.
448 -- Note that an earlier version of this code had some false reasoning
449 -- about being able to reliably wake up a task that had suspended on
450 -- a blocking system call that does not atomically relase the task's
451 -- lock (e.g., UNIX nanosleep, which we once thought could be used to
452 -- implement delays). That still left the possibility of missed
455 -- We cannot safely call Vulnerable_Complete_Activation here,
456 -- since that requires locking Self_ID.Parent. The anti-deadlock
457 -- lock ordering rules would then require us to release the lock
458 -- on Self_ID first, which would create a timing window for other
459 -- tasks to lock Self_ID. This is significant for tasks that may be
460 -- aborted before their execution can enter the task body, and so
461 -- they do not get a chance to call Complete_Task. The actual work
462 -- for this case is done in Terminate_Task.
464 procedure Locked_Abort_To_Level
470 if not T
.Aborting
and then T
/= Self_ID
then
471 case T
.Common
.State
is
472 when Unactivated | Terminated
=>
473 pragma Assert
(False);
477 -- This is needed to cancel an asynchronous protected entry
478 -- call during a requeue with abort.
481 (T
.ATC_Nesting_Level
).Cancellation_Attempted
:= True;
483 when Interrupt_Server_Blocked_On_Event_Flag
=>
488 Interrupt_Server_Idle_Sleep |
489 Interrupt_Server_Blocked_Interrupt_Sleep |
492 Wakeup
(T
, T
.Common
.State
);
494 when Acceptor_Sleep
=>
495 T
.Open_Accepts
:= null;
496 Wakeup
(T
, T
.Common
.State
);
498 when Entry_Caller_Sleep
=>
500 (T
.ATC_Nesting_Level
).Cancellation_Attempted
:= True;
501 Wakeup
(T
, T
.Common
.State
);
503 when Activator_Sleep |
504 Master_Completion_Sleep |
505 Master_Phase_2_Sleep |
511 if T
.Pending_ATC_Level
> L
then
512 T
.Pending_ATC_Level
:= L
;
513 T
.Pending_Action
:= True;
519 -- This prevents aborted task from accepting calls
523 -- The test above is just a heuristic, to reduce wasteful
524 -- calls to Abort_Task. We are holding T locked, and this
525 -- value will not be set to False except with T also locked,
526 -- inside Exit_One_ATC_Level, so we should not miss wakeups.
528 if T
.Common
.State
= Acceptor_Sleep
then
529 T
.Open_Accepts
:= null;
532 elsif T
/= Self_ID
and then
533 (T
.Common
.State
= Runnable
534 or else T
.Common
.State
= Interrupt_Server_Blocked_On_Event_Flag
)
535 -- The task is blocked on a system call waiting for the
536 -- completion event. In this case Abort_Task may need to take
537 -- special action in order to succeed. Example system: VMS.
543 end Locked_Abort_To_Level
;
545 -------------------------------
546 -- Poll_Base_Priority_Change --
547 -------------------------------
549 -- Poll for pending base priority change and for held tasks.
550 -- This should always be called with (only) Self_ID locked.
551 -- It may temporarily release Self_ID's lock.
553 -- The call to Yield is to force enqueuing at the
554 -- tail of the dispatching queue.
556 -- We must unlock Self_ID for this to take effect,
557 -- since we are inheriting high active priority from the lock.
559 -- See also Poll_Base_Priority_Change_At_Entry_Call,
560 -- in package System.Tasking.Entry_Calls.
562 -- In this version, we check if the task is held too because
563 -- doing this only in Do_Pending_Action is not enough.
565 procedure Poll_Base_Priority_Change
(Self_ID
: Task_Id
) is
567 if Dynamic_Priority_Support
and then Self_ID
.Pending_Priority_Change
then
569 -- Check for ceiling violations ???
571 Self_ID
.Pending_Priority_Change
:= False;
573 if Self_ID
.Common
.Base_Priority
= Self_ID
.New_Base_Priority
then
581 Write_Lock
(Self_ID
);
584 elsif Self_ID
.Common
.Base_Priority
< Self_ID
.New_Base_Priority
then
585 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
586 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
591 Self_ID
.Common
.Base_Priority
:= Self_ID
.New_Base_Priority
;
592 Set_Priority
(Self_ID
, Self_ID
.Common
.Base_Priority
);
601 Write_Lock
(Self_ID
);
605 end Poll_Base_Priority_Change
;
607 --------------------------------
608 -- Remove_From_All_Tasks_List --
609 --------------------------------
611 procedure Remove_From_All_Tasks_List
(T
: Task_Id
) is
617 (Debug
.Trace
(Self
, "Remove_From_All_Tasks_List", 'C'));
619 Previous
:= Null_Task
;
622 while C
/= Null_Task
loop
624 if Previous
= Null_Task
then
626 All_Tasks_List
.Common
.All_Tasks_Link
;
628 Previous
.Common
.All_Tasks_Link
:= C
.Common
.All_Tasks_Link
;
635 C
:= C
.Common
.All_Tasks_Link
;
638 pragma Assert
(False);
639 end Remove_From_All_Tasks_List
;
645 procedure Task_Lock
(Self_ID
: Task_Id
) is
647 Self_ID
.Global_Task_Lock_Nesting
:= Self_ID
.Global_Task_Lock_Nesting
+ 1;
649 if Self_ID
.Global_Task_Lock_Nesting
= 1 then
650 Defer_Abort_Nestable
(Self_ID
);
651 Write_Lock
(Global_Task_Lock
'Access, Global_Lock
=> True);
655 procedure Task_Lock
is
657 Task_Lock
(STPO
.Self
);
664 function Task_Name
return String is
665 Self_Id
: constant Task_Id
:= STPO
.Self
;
668 return Self_Id
.Common
.Task_Image
(1 .. Self_Id
.Common
.Task_Image_Len
);
675 procedure Task_Unlock
(Self_ID
: Task_Id
) is
677 pragma Assert
(Self_ID
.Global_Task_Lock_Nesting
> 0);
678 Self_ID
.Global_Task_Lock_Nesting
:= Self_ID
.Global_Task_Lock_Nesting
- 1;
680 if Self_ID
.Global_Task_Lock_Nesting
= 0 then
681 Unlock
(Global_Task_Lock
'Access, Global_Lock
=> True);
682 Undefer_Abort_Nestable
(Self_ID
);
686 procedure Task_Unlock
is
688 Task_Unlock
(STPO
.Self
);
695 -- Precondition : Self does not hold any locks!
697 -- Undefer_Abort is called on any abortion completion point (aka.
698 -- synchronization point). It performs the following actions if they
699 -- are pending: (1) change the base priority, (2) abort the task.
701 -- The priority change has to occur before abortion. Otherwise, it would
702 -- take effect no earlier than the next abortion completion point.
704 procedure Undefer_Abort
(Self_ID
: Task_Id
) is
706 if No_Abort
and then not Dynamic_Priority_Support
then
710 pragma Assert
(Self_ID
.Deferral_Level
= 1);
712 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
714 if Self_ID
.Deferral_Level
= 0 then
715 pragma Assert
(Check_No_Locks
(Self_ID
));
717 if Self_ID
.Pending_Action
then
718 Do_Pending_Action
(Self_ID
);
723 ----------------------------
724 -- Undefer_Abort_Nestable --
725 ----------------------------
727 -- An earlier version would re-defer abort if an abort is in progress.
728 -- Then, we modified the effect of the raise statement so that it defers
729 -- abort until control reaches a handler. That was done to prevent
730 -- "skipping over" a handler if another asynchronous abort occurs during
731 -- the propagation of the abort to the handler.
733 -- There has been talk of reversing that decision, based on a newer
734 -- implementation of exception propagation. Care must be taken to evaluate
735 -- how such a change would interact with the above code and all the places
736 -- where abort-deferral is used to bridge over critical transitions, such
737 -- as entry to the scope of a region with a finalizer and entry into the
738 -- body of an accept-procedure.
740 procedure Undefer_Abort_Nestable
(Self_ID
: Task_Id
) is
742 if No_Abort
and then not Dynamic_Priority_Support
then
746 pragma Assert
(Self_ID
.Deferral_Level
> 0);
748 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
750 if Self_ID
.Deferral_Level
= 0 then
752 pragma Assert
(Check_No_Locks
(Self_ID
));
754 if Self_ID
.Pending_Action
then
755 Do_Pending_Action
(Self_ID
);
758 end Undefer_Abort_Nestable
;
760 ----------------------
761 -- Undefer_Abortion --
762 ----------------------
764 -- Phase out RTS-internal use of Undefer_Abortion
765 -- to reduce overhead due to multiple calls to Self.
767 procedure Undefer_Abortion
is
771 if No_Abort
and then not Dynamic_Priority_Support
then
775 Self_ID
:= STPO
.Self
;
777 if Self_ID
.Deferral_Level
= 0 then
779 -- In case there are different views on whether Abort is supported
780 -- between the expander and the run time, we may end up with
781 -- Self_ID.Deferral_Level being equal to zero, when called from
782 -- the procedure created by the expander that corresponds to a
785 -- In this case, there's nothing to be done
787 -- See related code in System.Tasking.Stages.Create_Task resetting
788 -- Deferral_Level when System.Restrictions.Abort_Allowed is False.
793 pragma Assert
(Self_ID
.Deferral_Level
> 0);
794 Self_ID
.Deferral_Level
:= Self_ID
.Deferral_Level
- 1;
796 if Self_ID
.Deferral_Level
= 0 then
797 pragma Assert
(Check_No_Locks
(Self_ID
));
799 if Self_ID
.Pending_Action
then
800 Do_Pending_Action
(Self_ID
);
803 end Undefer_Abortion
;
805 ----------------------
806 -- Update_Exception --
807 ----------------------
809 -- Call only when holding no locks.
811 procedure Update_Exception
812 (X
: AE
.Exception_Occurrence
:= Current_Target_Exception
)
814 Self_Id
: constant Task_Id
:= Self
;
818 Save_Occurrence
(Self_Id
.Common
.Compiler_Data
.Current_Excep
, X
);
820 if Self_Id
.Deferral_Level
= 0 then
821 if Self_Id
.Pending_Action
then
822 Self_Id
.Pending_Action
:= False;
823 Self_Id
.Deferral_Level
:= Self_Id
.Deferral_Level
+ 1;
829 Write_Lock
(Self_Id
);
830 Self_Id
.Pending_Action
:= False;
831 Poll_Base_Priority_Change
(Self_Id
);
838 Self_Id
.Deferral_Level
:= Self_Id
.Deferral_Level
- 1;
840 if Self_Id
.Pending_ATC_Level
< Self_Id
.ATC_Nesting_Level
then
841 if not Self_Id
.Aborting
then
842 Self_Id
.Aborting
:= True;
843 raise Standard
'Abort_Signal;
848 end Update_Exception
;
850 --------------------------
851 -- Wakeup_Entry_Caller --
852 --------------------------
854 -- This is called at the end of service of an entry call, to abort the
855 -- caller if he is in an abortable part, and to wake up the caller if it
856 -- is on Entry_Caller_Sleep. It assumes that the call is already off-queue.
858 -- (This enforces the rule that a task must be off-queue if its state is
859 -- Done or Cancelled.) Call it holding the lock of Entry_Call.Self.
861 -- Timed_Call or Simple_Call:
862 -- The caller is waiting on Entry_Caller_Sleep, in
863 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
866 -- The caller might be in Wait_For_Completion,
867 -- waiting for a rendezvous (possibly requeued without abort)
870 -- Asynchronous_Call:
871 -- The caller may be executing in the abortable part o
872 -- an async. select, or on a time delay,
873 -- if Entry_Call.State >= Was_Abortable.
875 procedure Wakeup_Entry_Caller
877 Entry_Call
: Entry_Call_Link
;
878 New_State
: Entry_Call_State
)
880 Caller
: constant Task_Id
:= Entry_Call
.Self
;
883 pragma Debug
(Debug
.Trace
884 (Self_ID
, "Wakeup_Entry_Caller", 'E', Caller
));
885 pragma Assert
(New_State
= Done
or else New_State
= Cancelled
);
888 (Caller
.Common
.State
/= Terminated
889 and then Caller
.Common
.State
/= Unactivated
);
891 Entry_Call
.State
:= New_State
;
893 if Entry_Call
.Mode
= Asynchronous_Call
then
895 -- Abort the caller in his abortable part,
896 -- but do so only if call has been queued abortably
898 if Entry_Call
.State
>= Was_Abortable
or else New_State
= Done
then
899 Locked_Abort_To_Level
(Self_ID
, Caller
, Entry_Call
.Level
- 1);
902 elsif Caller
.Common
.State
= Entry_Caller_Sleep
then
903 Wakeup
(Caller
, Entry_Caller_Sleep
);
905 end Wakeup_Entry_Caller
;
907 ----------------------
908 -- Soft-Link Bodies --
909 ----------------------
911 function Get_Exc_Stack_Addr
return Address
is
913 return STPO
.Self
.Common
.Compiler_Data
.Exc_Stack_Addr
;
914 end Get_Exc_Stack_Addr
;
916 function Get_Stack_Info
return Stack_Checking
.Stack_Access
is
918 return STPO
.Self
.Common
.Compiler_Data
.Pri_Stack_Info
'Access;
921 procedure Set_Exc_Stack_Addr
(Self_ID
: Address
; Addr
: Address
) is
922 Me
: Task_Id
:= To_Task_Id
(Self_ID
);
924 if Me
= Null_Task
then
928 Me
.Common
.Compiler_Data
.Exc_Stack_Addr
:= Addr
;
929 end Set_Exc_Stack_Addr
;
931 -----------------------
932 -- Soft-Link Dummies --
933 -----------------------
935 -- These are dummies for subprograms that are only needed by certain
936 -- optional run-time system packages. If they are needed, the soft
937 -- links will be redirected to the real subprogram by elaboration of
938 -- the subprogram body where the real subprogram is declared.
940 procedure Finalize_Attributes
(T
: Task_Id
) is
941 pragma Warnings
(Off
, T
);
945 end Finalize_Attributes
;
947 procedure Initialize_Attributes
(T
: Task_Id
) is
948 pragma Warnings
(Off
, T
);
952 end Initialize_Attributes
;
956 end System
.Tasking
.Initialization
;