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-2001, 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. It is --
30 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
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.Tasking.Debug;
66 with System.Stack_Checking;
68 with System.Parameters;
69 -- used for Single_Lock
71 package body System.Tasking.Initialization is
73 package STPO renames System.Task_Primitives.Operations;
74 package SSL renames System.Soft_Links;
75 package AE renames Ada.Exceptions;
78 use Task_Primitives.Operations;
80 Global_Task_Lock : aliased System.Task_Primitives.RTS_Lock;
81 -- This is a global lock; it is used to execute in mutual exclusion
82 -- from all other tasks. It is only used by Task_Lock,
83 -- Task_Unlock, and Final_Task_Unlock.
85 function Current_Target_Exception return AE.Exception_Occurrence;
87 (Ada, Current_Target_Exception, "__gnat_current_target_exception");
88 -- Import this subprogram from the private part of Ada.Exceptions.
90 -----------------------------------------------------------------
91 -- Tasking versions of services needed by non-tasking programs --
92 -----------------------------------------------------------------
95 -- Locks out other tasks. Preceding a section of code by Task_Lock and
96 -- following it by Task_Unlock creates a critical region. This is used
97 -- for ensuring that a region of non-tasking code (such as code used to
98 -- allocate memory) is tasking safe. Note that it is valid for calls to
99 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
100 -- only the corresponding outer level Task_Unlock will actually unlock.
102 procedure Task_Unlock;
103 -- Releases lock previously set by call to Task_Lock. In the nested case,
104 -- all nested locks must be released before other tasks competing for the
105 -- tasking lock are released.
107 function Get_Jmpbuf_Address return Address;
108 procedure Set_Jmpbuf_Address (Addr : Address);
109 -- Get/Set Jmpbuf_Address for current task
111 function Get_Sec_Stack_Addr return Address;
112 procedure Set_Sec_Stack_Addr (Addr : Address);
113 -- Get/Set location of current task's secondary stack
115 function Get_Exc_Stack_Addr return Address;
116 -- Get the exception stack for the current task
118 procedure Set_Exc_Stack_Addr (Self_ID : Address; Addr : Address);
119 -- Self_ID is the Task_ID of the task that gets the exception stack.
120 -- For Self_ID = Null_Address, the current task gets the exception stack.
122 function Get_Machine_State_Addr return Address;
123 procedure Set_Machine_State_Addr (Addr : Address);
124 -- Get/Set the address for storing the current task's machine state
126 function Get_Current_Excep return SSL.EOA;
127 -- Comments needed???
129 procedure Timed_Delay_T (Time : Duration; Mode : Integer);
130 -- Comments needed???
132 function Get_Stack_Info return Stack_Checking.Stack_Access;
133 -- Get access to the current task's Stack_Info
135 procedure Update_Exception
136 (X : AE.Exception_Occurrence := Current_Target_Exception);
137 -- Handle exception setting and check for pending actions
139 function Task_Name return String;
140 -- Returns current task's name
142 ------------------------
143 -- Local Subprograms --
144 ------------------------
146 procedure Do_Pending_Action (Self_ID : Task_ID);
147 -- This is introduced to allow more efficient
148 -- in-line expansion of Undefer_Abort.
150 ----------------------------
151 -- Tasking Initialization --
152 ----------------------------
155 -- This procedure completes the initialization of the GNARL. The first
156 -- part of the initialization is done in the body of System.Tasking.
157 -- It consists of initializing global locks, and installing tasking
158 -- versions of certain operations used by the compiler. Init_RTS is called
159 -- during elaboration.
161 --------------------------
162 -- Change_Base_Priority --
163 --------------------------
165 -- Call only with abort deferred and holding Self_ID locked.
167 procedure Change_Base_Priority (T : Task_ID) is
169 if T.Common.Base_Priority /= T.New_Base_Priority then
170 T.Common.Base_Priority := T.New_Base_Priority;
171 Set_Priority (T, T.Common.Base_Priority);
173 end Change_Base_Priority;
175 ------------------------
176 -- Check_Abort_Status --
177 ------------------------
179 function Check_Abort_Status return Integer is
180 Self_ID : constant Task_ID := Self;
182 if Self_ID /= null and then Self_ID.Deferral_Level = 0
183 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
189 end Check_Abort_Status;
195 procedure Defer_Abort (Self_ID : Task_ID) is
197 if No_Abort and then not Dynamic_Priority_Support then
201 pragma Assert (Self_ID.Deferral_Level = 0);
204 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level);
206 -- The above check has been useful in detecting mismatched defer/undefer
207 -- pairs. You may uncomment it when testing on systems that support
210 -- If the OS supports preemptive abort (e.g. pthread_kill), it should
211 -- have happened already. A problem is with systems that do not support
212 -- preemptive abort, and so rely on polling. On such systems we may get
213 -- false failures of the assertion, since polling for pending abort does
214 -- no occur until the abort undefer operation.
216 -- Even on systems that only poll for abort, the assertion may be useful
217 -- for catching missed abort completion polling points. The operations
218 -- that undefer abort poll for pending aborts. This covers most of the
219 -- places where the core Ada semantics require abort to be caught,
220 -- without any special attention. However, this generally happens on
221 -- exit from runtime system call, which means a pending abort will not
222 -- be noticed on the way into the runtime system. We considered adding a
223 -- check for pending aborts at this point, but chose not to, because of
224 -- the overhead. Instead, we searched for RTS calls where abort
225 -- completion is required and a task could go farther than Ada allows
226 -- before undeferring abort; we then modified the code to ensure the
227 -- abort would be detected.
229 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
232 --------------------------
233 -- Defer_Abort_Nestable --
234 --------------------------
236 procedure Defer_Abort_Nestable (Self_ID : Task_ID) is
238 if No_Abort and then not Dynamic_Priority_Support then
243 -- ((Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level or else
244 -- Self_ID.Deferral_Level > 0));
246 -- See comment in Defer_Abort on the situations in which it may be
247 -- useful to uncomment the above assertion.
249 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
250 end Defer_Abort_Nestable;
256 procedure Defer_Abortion is
260 if No_Abort and then not Dynamic_Priority_Support then
264 Self_ID := STPO.Self;
265 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
268 -----------------------
269 -- Do_Pending_Action --
270 -----------------------
272 -- Call only when holding no locks
274 procedure Do_Pending_Action (Self_ID : Task_ID) is
275 use type Ada.Exceptions.Exception_Id;
278 pragma Assert (Self_ID = Self and then Self_ID.Deferral_Level = 0);
280 -- Needs loop to recheck for pending action in case a new one occurred
281 -- while we had abort deferred below.
284 -- Temporarily defer abortion so that we can lock Self_ID.
286 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
292 Write_Lock (Self_ID);
293 Self_ID.Pending_Action := False;
294 Poll_Base_Priority_Change (Self_ID);
301 -- Restore the original Deferral value.
303 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
305 if not Self_ID.Pending_Action then
306 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level then
307 if not Self_ID.Aborting then
308 Self_ID.Aborting := True;
310 (Debug.Trace (Self_ID, "raise Abort_Signal", 'B'));
311 raise Standard'Abort_Signal;
313 pragma Assert (not Self_ID.ATC_Hack);
315 elsif Self_ID.ATC_Hack then
316 -- The solution really belongs in the Abort_Signal handler
317 -- for async. entry calls. The present hack is very
318 -- fragile. It relies that the very next point after
319 -- Exit_One_ATC_Level at which the task becomes abortable
320 -- will be the call to Undefer_Abort in the
321 -- Abort_Signal handler.
323 Self_ID.ATC_Hack := False;
327 (Self_ID, "raise Abort_Signal (ATC hack)", 'B'));
328 raise Standard'Abort_Signal;
335 end Do_Pending_Action;
337 -----------------------
338 -- Final_Task_Unlock --
339 -----------------------
341 -- This version is only for use in Terminate_Task, when the task
342 -- is relinquishing further rights to its own ATCB.
343 -- There is a very interesting potential race condition there, where
344 -- the old task may run concurrently with a new task that is allocated
345 -- the old tasks (now reused) ATCB. The critical thing here is to
346 -- not make any reference to the ATCB after the lock is released.
347 -- See also comments on Terminate_Task and Unlock.
349 procedure Final_Task_Unlock (Self_ID : Task_ID) is
351 pragma Assert (Self_ID.Global_Task_Lock_Nesting = 1);
352 Unlock (Global_Task_Lock'Access, Global_Lock => True);
353 end Final_Task_Unlock;
359 procedure Init_RTS is
363 -- Terminate run time (regular vs restricted) specific initialization
364 -- of the environment task.
366 Self_Id := Environment_Task;
367 Self_Id.Master_of_Task := Environment_Task_Level;
368 Self_Id.Master_Within := Self_Id.Master_of_Task + 1;
370 for L in Self_Id.Entry_Calls'Range loop
371 Self_Id.Entry_Calls (L).Self := Self_Id;
372 Self_Id.Entry_Calls (L).Level := L;
375 Self_Id.Awake_Count := 1;
376 Self_Id.Alive_Count := 1;
378 Self_Id.Master_Within := Library_Task_Level;
379 -- Normally, a task starts out with internal master nesting level
380 -- one larger than external master nesting level. It is incremented
381 -- to one by Enter_Master, which is called in the task body only if
382 -- the compiler thinks the task may have dependent tasks. There is no
383 -- corresponding call to Enter_Master for the environment task, so we
384 -- would need to increment it to 2 here. Instead, we set it to 3.
385 -- By doing this we reserve the level 2 for server tasks of the runtime
386 -- system. The environment task does not need to wait for these server
388 -- Initialize lock used to implement mutual exclusion between all tasks
390 Initialize_Lock (Global_Task_Lock'Access, STPO.Global_Task_Level);
392 -- Notify that the tasking run time has been elaborated so that
393 -- the tasking version of the soft links can be used.
395 if not No_Abort or else Dynamic_Priority_Support then
396 SSL.Abort_Defer := Defer_Abortion'Access;
397 SSL.Abort_Undefer := Undefer_Abortion'Access;
400 SSL.Update_Exception := Update_Exception'Access;
401 SSL.Lock_Task := Task_Lock'Access;
402 SSL.Unlock_Task := Task_Unlock'Access;
403 SSL.Get_Jmpbuf_Address := Get_Jmpbuf_Address'Access;
404 SSL.Set_Jmpbuf_Address := Set_Jmpbuf_Address'Access;
405 SSL.Get_Sec_Stack_Addr := Get_Sec_Stack_Addr'Access;
406 SSL.Set_Sec_Stack_Addr := Set_Sec_Stack_Addr'Access;
407 SSL.Get_Exc_Stack_Addr := Get_Exc_Stack_Addr'Access;
408 SSL.Set_Exc_Stack_Addr := Set_Exc_Stack_Addr'Access;
409 SSL.Get_Machine_State_Addr := Get_Machine_State_Addr'Access;
410 SSL.Set_Machine_State_Addr := Set_Machine_State_Addr'Access;
411 SSL.Get_Current_Excep := Get_Current_Excep'Access;
412 SSL.Timed_Delay := Timed_Delay_T'Access;
413 SSL.Check_Abort_Status := Check_Abort_Status'Access;
414 SSL.Get_Stack_Info := Get_Stack_Info'Access;
415 SSL.Task_Name := Task_Name'Access;
417 -- No need to create a new Secondary Stack, since we will use the
418 -- default one created in s-secsta.adb
420 SSL.Set_Sec_Stack_Addr (SSL.Get_Sec_Stack_Addr_NT);
421 SSL.Set_Exc_Stack_Addr (Null_Address, SSL.Get_Exc_Stack_Addr_NT);
422 SSL.Set_Jmpbuf_Address (SSL.Get_Jmpbuf_Address_NT);
423 SSL.Set_Machine_State_Addr (SSL.Get_Machine_State_Addr_NT);
425 -- Abortion is deferred in a new ATCB, so we need to undefer abortion
426 -- at this stage to make the environment task abortable.
428 Undefer_Abort (Environment_Task);
431 ---------------------------
432 -- Locked_Abort_To_Level--
433 ---------------------------
435 -- Abort a task to the specified ATC nesting level.
436 -- Call this only with T locked.
438 -- An earlier version of this code contained a call to Wakeup. That
439 -- should not be necessary here, if Abort_Task is implemented correctly,
440 -- since Abort_Task should include the effect of Wakeup. However, the
441 -- above call was in earlier versions of this file, and at least for
442 -- some targets Abort_Task has not beek doing Wakeup. It should not
443 -- hurt to uncomment the above call, until the error is corrected for
446 -- See extended comments in package body System.Tasking.Abortion
447 -- for the overall design of the implementation of task abort.
449 -- If the task is sleeping it will be in an abort-deferred region,
450 -- and will not have Abort_Signal raised by Abort_Task.
451 -- Such an "abort deferral" is just to protect the RTS internals,
452 -- and not necessarily required to enforce Ada semantics.
453 -- Abort_Task should wake the task up and let it decide if it wants
454 -- to complete the aborted construct immediately.
456 -- Note that the effect of the lowl-level Abort_Task is not persistent.
457 -- If the target task is not blocked, this wakeup will be missed.
459 -- We don't bother calling Abort_Task if this task is aborting itself,
460 -- since we are inside the RTS and have abort deferred. Similarly, We
461 -- don't bother to call Abort_Task if T is terminated, since there is
462 -- no need to abort a terminated task, and it could be dangerous to try
463 -- if the task has stopped executing.
465 -- Note that an earlier version of this code had some false reasoning
466 -- about being able to reliably wake up a task that had suspended on
467 -- a blocking system call that does not atomically relase the task's
468 -- lock (e.g., UNIX nanosleep, which we once thought could be used to
469 -- implement delays). That still left the possibility of missed
472 -- We cannot safely call Vulnerable_Complete_Activation here,
473 -- since that requires locking Self_ID.Parent. The anti-deadlock
474 -- lock ordering rules would then require us to release the lock
475 -- on Self_ID first, which would create a timing window for other
476 -- tasks to lock Self_ID. This is significant for tasks that may be
477 -- aborted before their execution can enter the task body, and so
478 -- they do not get a chance to call Complete_Task. The actual work
479 -- for this case is done in Terminate_Task.
481 procedure Locked_Abort_To_Level
487 if not T.Aborting and then T /= Self_ID then
488 case T.Common.State is
489 when Unactivated | Terminated =>
490 pragma Assert (False);
494 -- This is needed to cancel an asynchronous protected entry
495 -- call during a requeue with abort.
498 (T.ATC_Nesting_Level).Cancellation_Attempted := True;
500 when Interrupt_Server_Blocked_On_Event_Flag =>
505 Interrupt_Server_Idle_Sleep |
506 Interrupt_Server_Blocked_Interrupt_Sleep |
509 Wakeup (T, T.Common.State);
511 when Acceptor_Sleep =>
512 T.Open_Accepts := null;
513 Wakeup (T, T.Common.State);
515 when Entry_Caller_Sleep =>
517 (T.ATC_Nesting_Level).Cancellation_Attempted := True;
518 Wakeup (T, T.Common.State);
520 when Activator_Sleep |
521 Master_Completion_Sleep |
522 Master_Phase_2_Sleep |
528 if T.Pending_ATC_Level > L then
529 T.Pending_ATC_Level := L;
530 T.Pending_Action := True;
536 -- This prevents aborted task from accepting calls
540 -- The test above is just a heuristic, to reduce wasteful
541 -- calls to Abort_Task. We are holding T locked, and this
542 -- value will not be set to False except with T also locked,
543 -- inside Exit_One_ATC_Level, so we should not miss wakeups.
545 if T.Common.State = Acceptor_Sleep then
546 T.Open_Accepts := null;
549 elsif T /= Self_ID and then
550 (T.Common.State = Runnable
551 or else T.Common.State = Interrupt_Server_Blocked_On_Event_Flag)
552 -- The task is blocked on a system call waiting for the
553 -- completion event. In this case Abort_Task may need to take
554 -- special action in order to succeed. Example system: VMS.
560 end Locked_Abort_To_Level;
562 -------------------------------
563 -- Poll_Base_Priority_Change --
564 -------------------------------
566 -- Poll for pending base priority change and for held tasks.
567 -- This should always be called with (only) Self_ID locked.
568 -- It may temporarily release Self_ID's lock.
570 -- The call to Yield is to force enqueuing at the
571 -- tail of the dispatching queue.
573 -- We must unlock Self_ID for this to take effect,
574 -- since we are inheriting high active priority from the lock.
576 -- See also Poll_Base_Priority_Change_At_Entry_Call,
577 -- in package System.Tasking.Entry_Calls.
579 -- In this version, we check if the task is held too because
580 -- doing this only in Do_Pending_Action is not enough.
582 procedure Poll_Base_Priority_Change (Self_ID : Task_ID) is
584 if Dynamic_Priority_Support and then Self_ID.Pending_Priority_Change then
585 -- Check for ceiling violations ???
587 Self_ID.Pending_Priority_Change := False;
589 if Self_ID.Common.Base_Priority = Self_ID.New_Base_Priority then
597 Write_Lock (Self_ID);
600 elsif Self_ID.Common.Base_Priority < Self_ID.New_Base_Priority then
601 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
602 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
607 Self_ID.Common.Base_Priority := Self_ID.New_Base_Priority;
608 Set_Priority (Self_ID, Self_ID.Common.Base_Priority);
617 Write_Lock (Self_ID);
621 end Poll_Base_Priority_Change;
623 --------------------------------
624 -- Remove_From_All_Tasks_List --
625 --------------------------------
627 procedure Remove_From_All_Tasks_List (T : Task_ID) is
633 (Debug.Trace ("Remove_From_All_Tasks_List", 'C'));
635 Previous := Null_Task;
638 while C /= Null_Task loop
640 if Previous = Null_Task then
642 All_Tasks_List.Common.All_Tasks_Link;
644 Previous.Common.All_Tasks_Link := C.Common.All_Tasks_Link;
651 C := C.Common.All_Tasks_Link;
654 pragma Assert (False);
655 end Remove_From_All_Tasks_List;
661 procedure Task_Lock (Self_ID : Task_ID) is
663 Self_ID.Global_Task_Lock_Nesting := Self_ID.Global_Task_Lock_Nesting + 1;
665 if Self_ID.Global_Task_Lock_Nesting = 1 then
666 Defer_Abort_Nestable (Self_ID);
667 Write_Lock (Global_Task_Lock'Access, Global_Lock => True);
671 procedure Task_Lock is
673 Task_Lock (STPO.Self);
680 function Task_Name return String is
681 use System.Task_Info;
684 if STPO.Self.Common.Task_Image /= null then
685 return STPO.Self.Common.Task_Image.all;
695 procedure Task_Unlock (Self_ID : Task_ID) is
697 pragma Assert (Self_ID.Global_Task_Lock_Nesting > 0);
698 Self_ID.Global_Task_Lock_Nesting := Self_ID.Global_Task_Lock_Nesting - 1;
700 if Self_ID.Global_Task_Lock_Nesting = 0 then
701 Unlock (Global_Task_Lock'Access, Global_Lock => True);
702 Undefer_Abort_Nestable (Self_ID);
706 procedure Task_Unlock is
708 Task_Unlock (STPO.Self);
715 -- Precondition : Self does not hold any locks!
717 -- Undefer_Abort is called on any abortion completion point (aka.
718 -- synchronization point). It performs the following actions if they
719 -- are pending: (1) change the base priority, (2) abort the task.
721 -- The priority change has to occur before abortion. Otherwise, it would
722 -- take effect no earlier than the next abortion completion point.
724 procedure Undefer_Abort (Self_ID : Task_ID) is
726 if No_Abort and then not Dynamic_Priority_Support then
730 pragma Assert (Self_ID.Deferral_Level = 1);
732 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
734 if Self_ID.Deferral_Level = 0 then
735 pragma Assert (Check_No_Locks (Self_ID));
737 if Self_ID.Pending_Action then
738 Do_Pending_Action (Self_ID);
743 ----------------------------
744 -- Undefer_Abort_Nestable --
745 ----------------------------
747 -- An earlier version would re-defer abort if an abort is in progress.
748 -- Then, we modified the effect of the raise statement so that it defers
749 -- abort until control reaches a handler. That was done to prevent
750 -- "skipping over" a handler if another asynchronous abort occurs during
751 -- the propagation of the abort to the handler.
753 -- There has been talk of reversing that decision, based on a newer
754 -- implementation of exception propagation. Care must be taken to evaluate
755 -- how such a change would interact with the above code and all the places
756 -- where abort-deferral is used to bridge over critical transitions, such
757 -- as entry to the scope of a region with a finalizer and entry into the
758 -- body of an accept-procedure.
760 procedure Undefer_Abort_Nestable (Self_ID : Task_ID) is
762 if No_Abort and then not Dynamic_Priority_Support then
766 pragma Assert (Self_ID.Deferral_Level > 0);
768 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
770 if Self_ID.Deferral_Level = 0 then
772 pragma Assert (Check_No_Locks (Self_ID));
774 if Self_ID.Pending_Action then
775 Do_Pending_Action (Self_ID);
778 end Undefer_Abort_Nestable;
780 ----------------------
781 -- Undefer_Abortion --
782 ----------------------
784 -- Phase out RTS-internal use of Undefer_Abortion
785 -- to reduce overhead due to multiple calls to Self.
787 procedure Undefer_Abortion is
790 if No_Abort and then not Dynamic_Priority_Support then
794 Self_ID := STPO.Self;
795 pragma Assert (Self_ID.Deferral_Level > 0);
797 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
799 if Self_ID.Deferral_Level = 0 then
800 pragma Assert (Check_No_Locks (Self_ID));
802 if Self_ID.Pending_Action then
803 Do_Pending_Action (Self_ID);
806 end Undefer_Abortion;
808 ----------------------
809 -- Update_Exception --
810 ----------------------
812 -- Call only when holding no locks.
814 procedure Update_Exception
815 (X : AE.Exception_Occurrence := Current_Target_Exception)
817 Self_Id : constant Task_ID := Self;
821 Save_Occurrence (Self_Id.Common.Compiler_Data.Current_Excep, X);
823 if Self_Id.Deferral_Level = 0 then
824 if Self_Id.Pending_Action then
825 Self_Id.Pending_Action := False;
826 Self_Id.Deferral_Level := Self_Id.Deferral_Level + 1;
832 Write_Lock (Self_Id);
833 Self_Id.Pending_Action := False;
834 Poll_Base_Priority_Change (Self_Id);
841 Self_Id.Deferral_Level := Self_Id.Deferral_Level - 1;
843 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
844 if not Self_Id.Aborting then
845 Self_Id.Aborting := True;
846 raise Standard'Abort_Signal;
851 end Update_Exception;
853 --------------------------
854 -- Wakeup_Entry_Caller --
855 --------------------------
857 -- This is called at the end of service of an entry call, to abort the
858 -- caller if he is in an abortable part, and to wake up the caller if it
859 -- is on Entry_Caller_Sleep. It assumes that the call is already off-queue.
861 -- (This enforces the rule that a task must be off-queue if its state is
862 -- Done or Cancelled.) Call it holding the lock of Entry_Call.Self.
864 -- Timed_Call or Simple_Call:
865 -- The caller is waiting on Entry_Caller_Sleep, in
866 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
869 -- The caller might be in Wait_For_Completion,
870 -- waiting for a rendezvous (possibly requeued without abort)
873 -- Asynchronous_Call:
874 -- The caller may be executing in the abortable part o
875 -- an async. select, or on a time delay,
876 -- if Entry_Call.State >= Was_Abortable.
878 procedure Wakeup_Entry_Caller
880 Entry_Call : Entry_Call_Link;
881 New_State : Entry_Call_State)
883 Caller : constant Task_ID := Entry_Call.Self;
885 pragma Debug (Debug.Trace
886 (Self_ID, "Wakeup_Entry_Caller", Caller, 'E'));
887 pragma Assert (New_State = Done or else New_State = Cancelled);
890 (Caller.Common.State /= Terminated
891 and then Caller.Common.State /= Unactivated);
893 Entry_Call.State := New_State;
895 if Entry_Call.Mode = Asynchronous_Call then
897 -- Abort the caller in his abortable part,
898 -- but do so only if call has been queued abortably
900 if Entry_Call.State >= Was_Abortable or else New_State = Done then
901 Locked_Abort_To_Level (Self_ID, Caller, Entry_Call.Level - 1);
904 elsif Caller.Common.State = Entry_Caller_Sleep then
905 Wakeup (Caller, Entry_Caller_Sleep);
907 end Wakeup_Entry_Caller;
909 ----------------------
910 -- Soft-Link Bodies --
911 ----------------------
913 function Get_Current_Excep return SSL.EOA is
914 Me : constant Task_ID := STPO.Self;
916 return Me.Common.Compiler_Data.Current_Excep'Access;
917 end Get_Current_Excep;
919 function Get_Exc_Stack_Addr return Address is
920 Me : constant Task_ID := STPO.Self;
922 return Me.Common.Compiler_Data.Exc_Stack_Addr;
923 end Get_Exc_Stack_Addr;
925 function Get_Jmpbuf_Address return Address is
926 Me : constant Task_ID := STPO.Self;
928 return Me.Common.Compiler_Data.Jmpbuf_Address;
929 end Get_Jmpbuf_Address;
931 function Get_Machine_State_Addr return Address is
932 Me : constant Task_ID := STPO.Self;
934 return Me.Common.Compiler_Data.Machine_State_Addr;
935 end Get_Machine_State_Addr;
937 function Get_Sec_Stack_Addr return Address is
938 Me : constant Task_ID := STPO.Self;
940 return Me.Common.Compiler_Data.Sec_Stack_Addr;
941 end Get_Sec_Stack_Addr;
943 function Get_Stack_Info return Stack_Checking.Stack_Access is
944 Me : constant Task_ID := STPO.Self;
946 return Me.Common.Compiler_Data.Pri_Stack_Info'Access;
949 procedure Set_Exc_Stack_Addr (Self_ID : Address; Addr : Address) is
950 Me : Task_ID := To_Task_Id (Self_ID);
952 if Me = Null_Task then
956 Me.Common.Compiler_Data.Exc_Stack_Addr := Addr;
957 end Set_Exc_Stack_Addr;
959 procedure Set_Jmpbuf_Address (Addr : Address) is
960 Me : Task_ID := STPO.Self;
962 Me.Common.Compiler_Data.Jmpbuf_Address := Addr;
963 end Set_Jmpbuf_Address;
965 procedure Set_Machine_State_Addr (Addr : Address) is
966 Me : Task_ID := STPO.Self;
968 Me.Common.Compiler_Data.Machine_State_Addr := Addr;
969 end Set_Machine_State_Addr;
971 procedure Set_Sec_Stack_Addr (Addr : Address) is
972 Me : Task_ID := STPO.Self;
974 Me.Common.Compiler_Data.Sec_Stack_Addr := Addr;
975 end Set_Sec_Stack_Addr;
977 procedure Timed_Delay_T (Time : Duration; Mode : Integer) is
979 STPO.Timed_Delay (STPO.Self, Time, Mode);
982 -----------------------
983 -- Soft-Link Dummies --
984 -----------------------
986 -- These are dummies for subprograms that are only needed by certain
987 -- optional run-time system packages. If they are needed, the soft
988 -- links will be redirected to the real subprogram by elaboration of
989 -- the subprogram body where the real subprogram is declared.
991 procedure Finalize_Attributes (T : Task_ID) is
992 pragma Warnings (Off, T);
995 end Finalize_Attributes;
997 procedure Initialize_Attributes (T : Task_ID) is
998 pragma Warnings (Off, T);
1001 end Initialize_Attributes;
1005 end System.Tasking.Initialization;