* libgfortran.h (support_fpu_underflow_control,
[official-gcc.git] / gcc / ada / s-tasini.adb
blob45c99cdadce1a56b2d015a468d528a0b13208ba6
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
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 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
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- --
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. --
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/>. --
26 -- --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
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.
36 pragma Polling (Off);
37 -- Turn polling off for this package. We don't need polling during any of the
38 -- routines in this package, and more to the point, if we try to poll it can
39 -- cause infinite loops.
41 with Ada.Exceptions;
43 with System.Task_Primitives;
44 with System.Task_Primitives.Operations;
45 with System.Soft_Links;
46 with System.Soft_Links.Tasking;
47 with System.Tasking.Debug;
48 with System.Parameters;
50 with System.Secondary_Stack;
51 pragma Elaborate_All (System.Secondary_Stack);
52 pragma Unreferenced (System.Secondary_Stack);
53 -- Make sure the body of Secondary_Stack is elaborated before calling
54 -- Init_Tasking_Soft_Links. See comments for this routine for explanation.
56 package body System.Tasking.Initialization is
58 package STPO renames System.Task_Primitives.Operations;
59 package SSL renames System.Soft_Links;
60 package AE renames Ada.Exceptions;
62 use Parameters;
63 use Task_Primitives.Operations;
65 Global_Task_Lock : aliased System.Task_Primitives.RTS_Lock;
66 -- This is a global lock; it is used to execute in mutual exclusion from
67 -- all other tasks. It is only used by Task_Lock, Task_Unlock, and
68 -- Final_Task_Unlock.
70 ----------------------------------------------------------------------
71 -- Tasking versions of some services needed by non-tasking programs --
72 ----------------------------------------------------------------------
74 procedure Abort_Defer;
75 -- NON-INLINE versions without Self_ID for soft links
77 procedure Abort_Undefer;
78 -- NON-INLINE versions without Self_ID for soft links
80 procedure Task_Lock;
81 -- Locks out other tasks. Preceding a section of code by Task_Lock and
82 -- following it by Task_Unlock creates a critical region. This is used
83 -- for ensuring that a region of non-tasking code (such as code used to
84 -- allocate memory) is tasking safe. Note that it is valid for calls to
85 -- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
86 -- only the corresponding outer level Task_Unlock will actually unlock.
88 procedure Task_Unlock;
89 -- Releases lock previously set by call to Task_Lock. In the nested case,
90 -- all nested locks must be released before other tasks competing for the
91 -- tasking lock are released.
93 function Get_Current_Excep return SSL.EOA;
94 -- Task-safe version of SSL.Get_Current_Excep
96 procedure Update_Exception
97 (X : AE.Exception_Occurrence := SSL.Current_Target_Exception);
98 -- Handle exception setting and check for pending actions
100 function Task_Name return String;
101 -- Returns current task's name
103 ------------------------
104 -- Local Subprograms --
105 ------------------------
107 ----------------------------
108 -- Tasking Initialization --
109 ----------------------------
111 procedure Init_RTS;
112 -- This procedure completes the initialization of the GNARL. The first part
113 -- of the initialization is done in the body of System.Tasking. It consists
114 -- of initializing global locks, and installing tasking versions of certain
115 -- operations used by the compiler. Init_RTS is called during elaboration.
117 --------------------------
118 -- Change_Base_Priority --
119 --------------------------
121 -- Call only with abort deferred and holding Self_ID locked
123 procedure Change_Base_Priority (T : Task_Id) is
124 begin
125 if T.Common.Base_Priority /= T.New_Base_Priority then
126 T.Common.Base_Priority := T.New_Base_Priority;
127 Set_Priority (T, T.Common.Base_Priority);
128 end if;
129 end Change_Base_Priority;
131 ------------------------
132 -- Check_Abort_Status --
133 ------------------------
135 function Check_Abort_Status return Integer is
136 Self_ID : constant Task_Id := Self;
137 begin
138 if Self_ID /= null
139 and then Self_ID.Deferral_Level = 0
140 and then Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
141 then
142 return 1;
143 else
144 return 0;
145 end if;
146 end Check_Abort_Status;
148 -----------------
149 -- Defer_Abort --
150 -----------------
152 procedure Defer_Abort (Self_ID : Task_Id) is
153 begin
154 if No_Abort then
155 return;
156 end if;
158 pragma Assert (Self_ID.Deferral_Level = 0);
160 -- pragma Assert
161 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level);
163 -- The above check has been useful in detecting mismatched defer/undefer
164 -- pairs. You may uncomment it when testing on systems that support
165 -- preemptive abort.
167 -- If the OS supports preemptive abort (e.g. pthread_kill), it should
168 -- have happened already. A problem is with systems that do not support
169 -- preemptive abort, and so rely on polling. On such systems we may get
170 -- false failures of the assertion, since polling for pending abort does
171 -- no occur until the abort undefer operation.
173 -- Even on systems that only poll for abort, the assertion may be useful
174 -- for catching missed abort completion polling points. The operations
175 -- that undefer abort poll for pending aborts. This covers most of the
176 -- places where the core Ada semantics require abort to be caught,
177 -- without any special attention. However, this generally happens on
178 -- exit from runtime system call, which means a pending abort will not
179 -- be noticed on the way into the runtime system. We considered adding a
180 -- check for pending aborts at this point, but chose not to, because of
181 -- the overhead. Instead, we searched for RTS calls where abort
182 -- completion is required and a task could go farther than Ada allows
183 -- before undeferring abort; we then modified the code to ensure the
184 -- abort would be detected.
186 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
187 end Defer_Abort;
189 --------------------------
190 -- Defer_Abort_Nestable --
191 --------------------------
193 procedure Defer_Abort_Nestable (Self_ID : Task_Id) is
194 begin
195 if No_Abort then
196 return;
197 end if;
199 -- The following assertion is by default disabled. See the comment in
200 -- Defer_Abort on the situations in which it may be useful to uncomment
201 -- this assertion and enable the test.
203 -- pragma Assert
204 -- (Self_ID.Pending_ATC_Level >= Self_ID.ATC_Nesting_Level or else
205 -- Self_ID.Deferral_Level > 0);
207 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
208 end Defer_Abort_Nestable;
210 -----------------
211 -- Abort_Defer --
212 -----------------
214 procedure Abort_Defer is
215 Self_ID : Task_Id;
216 begin
217 if No_Abort then
218 return;
219 end if;
221 Self_ID := STPO.Self;
222 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
223 end Abort_Defer;
225 -----------------------
226 -- Get_Current_Excep --
227 -----------------------
229 function Get_Current_Excep return SSL.EOA is
230 begin
231 return STPO.Self.Common.Compiler_Data.Current_Excep'Access;
232 end Get_Current_Excep;
234 -----------------------
235 -- Do_Pending_Action --
236 -----------------------
238 -- Call only when holding no locks
240 procedure Do_Pending_Action (Self_ID : Task_Id) is
241 use type Ada.Exceptions.Exception_Id;
243 begin
244 pragma Assert (Self_ID = Self and then Self_ID.Deferral_Level = 0);
246 -- Needs loop to recheck for pending action in case a new one occurred
247 -- while we had abort deferred below.
249 loop
250 -- Temporarily defer abort so that we can lock Self_ID
252 Self_ID.Deferral_Level := Self_ID.Deferral_Level + 1;
254 if Single_Lock then
255 Lock_RTS;
256 end if;
258 Write_Lock (Self_ID);
259 Self_ID.Pending_Action := False;
260 Unlock (Self_ID);
262 if Single_Lock then
263 Unlock_RTS;
264 end if;
266 -- Restore the original Deferral value
268 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
270 if not Self_ID.Pending_Action then
271 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level then
272 if not Self_ID.Aborting then
273 Self_ID.Aborting := True;
274 pragma Debug
275 (Debug.Trace (Self_ID, "raise Abort_Signal", 'B'));
276 raise Standard'Abort_Signal;
278 pragma Assert (not Self_ID.ATC_Hack);
280 elsif Self_ID.ATC_Hack then
282 -- The solution really belongs in the Abort_Signal handler
283 -- for async. entry calls. The present hack is very
284 -- fragile. It relies that the very next point after
285 -- Exit_One_ATC_Level at which the task becomes abortable
286 -- will be the call to Undefer_Abort in the
287 -- Abort_Signal handler.
289 Self_ID.ATC_Hack := False;
291 pragma Debug
292 (Debug.Trace
293 (Self_ID, "raise Abort_Signal (ATC hack)", 'B'));
294 raise Standard'Abort_Signal;
295 end if;
296 end if;
298 return;
299 end if;
300 end loop;
301 end Do_Pending_Action;
303 -----------------------
304 -- Final_Task_Unlock --
305 -----------------------
307 -- This version is only for use in Terminate_Task, when the task is
308 -- relinquishing further rights to its own ATCB.
310 -- There is a very interesting potential race condition there, where the
311 -- old task may run concurrently with a new task that is allocated the old
312 -- tasks (now reused) ATCB. The critical thing here is to not make any
313 -- reference to the ATCB after the lock is released. See also comments on
314 -- Terminate_Task and Unlock.
316 procedure Final_Task_Unlock (Self_ID : Task_Id) is
317 begin
318 pragma Assert (Self_ID.Common.Global_Task_Lock_Nesting = 1);
319 Unlock (Global_Task_Lock'Access, Global_Lock => True);
320 end Final_Task_Unlock;
322 --------------
323 -- Init_RTS --
324 --------------
326 procedure Init_RTS is
327 Self_Id : Task_Id;
328 begin
329 Tasking.Initialize;
331 -- Terminate run time (regular vs restricted) specific initialization
332 -- of the environment task.
334 Self_Id := Environment_Task;
335 Self_Id.Master_of_Task := Environment_Task_Level;
336 Self_Id.Master_Within := Self_Id.Master_of_Task + 1;
338 for L in Self_Id.Entry_Calls'Range loop
339 Self_Id.Entry_Calls (L).Self := Self_Id;
340 Self_Id.Entry_Calls (L).Level := L;
341 end loop;
343 Self_Id.Awake_Count := 1;
344 Self_Id.Alive_Count := 1;
346 -- Normally, a task starts out with internal master nesting level one
347 -- larger than external master nesting level. It is incremented to one
348 -- by Enter_Master, which is called in the task body only if the
349 -- compiler thinks the task may have dependent tasks. There is no
350 -- corresponding call to Enter_Master for the environment task, so we
351 -- would need to increment it to 2 here. Instead, we set it to 3. By
352 -- doing this we reserve the level 2 for server tasks of the runtime
353 -- system. The environment task does not need to wait for these server
355 Self_Id.Master_Within := Library_Task_Level;
357 -- Initialize lock used to implement mutual exclusion between all tasks
359 Initialize_Lock (Global_Task_Lock'Access, STPO.Global_Task_Level);
361 -- Notify that the tasking run time has been elaborated so that
362 -- the tasking version of the soft links can be used.
364 if not No_Abort then
365 SSL.Abort_Defer := Abort_Defer'Access;
366 SSL.Abort_Undefer := Abort_Undefer'Access;
367 end if;
369 SSL.Lock_Task := Task_Lock'Access;
370 SSL.Unlock_Task := Task_Unlock'Access;
371 SSL.Check_Abort_Status := Check_Abort_Status'Access;
372 SSL.Task_Name := Task_Name'Access;
373 SSL.Update_Exception := Update_Exception'Access;
374 SSL.Get_Current_Excep := Get_Current_Excep'Access;
376 -- Initialize the tasking soft links (if not done yet) that are common
377 -- to the full and the restricted run times.
379 SSL.Tasking.Init_Tasking_Soft_Links;
381 -- Abort is deferred in a new ATCB, so we need to undefer abort at this
382 -- stage to make the environment task abortable.
384 Undefer_Abort (Environment_Task);
385 end Init_RTS;
387 ---------------------------
388 -- Locked_Abort_To_Level--
389 ---------------------------
391 -- Abort a task to the specified ATC nesting level.
392 -- Call this only with T locked.
394 -- An earlier version of this code contained a call to Wakeup. That should
395 -- not be necessary here, if Abort_Task is implemented correctly, since
396 -- Abort_Task should include the effect of Wakeup. However, the above call
397 -- was in earlier versions of this file, and at least for some targets
398 -- Abort_Task has not been doing Wakeup. It should not hurt to uncomment
399 -- the above call, until the error is corrected for all targets.
401 -- See extended comments in package body System.Tasking.Abort for the
402 -- overall design of the implementation of task abort.
403 -- ??? there is no such package ???
405 -- If the task is sleeping it will be in an abort-deferred region, and will
406 -- not have Abort_Signal raised by Abort_Task. Such an "abort deferral" is
407 -- just to protect the RTS internals, and not necessarily required to
408 -- enforce Ada semantics. Abort_Task should wake the task up and let it
409 -- decide if it wants to complete the aborted construct immediately.
411 -- Note that the effect of the low-level Abort_Task is not persistent.
412 -- If the target task is not blocked, this wakeup will be missed.
414 -- We don't bother calling Abort_Task if this task is aborting itself,
415 -- since we are inside the RTS and have abort deferred. Similarly, We don't
416 -- bother to call Abort_Task if T is terminated, since there is no need to
417 -- abort a terminated task, and it could be dangerous to try if the task
418 -- has stopped executing.
420 -- Note that an earlier version of this code had some false reasoning about
421 -- being able to reliably wake up a task that had suspended on a blocking
422 -- system call that does not atomically release the task's lock (e.g., UNIX
423 -- nanosleep, which we once thought could be used to implement delays).
424 -- That still left the possibility of missed wakeups.
426 -- We cannot safely call Vulnerable_Complete_Activation here, since that
427 -- requires locking Self_ID.Parent. The anti-deadlock lock ordering rules
428 -- would then require us to release the lock on Self_ID first, which would
429 -- create a timing window for other tasks to lock Self_ID. This is
430 -- significant for tasks that may be aborted before their execution can
431 -- enter the task body, and so they do not get a chance to call
432 -- Complete_Task. The actual work for this case is done in Terminate_Task.
434 procedure Locked_Abort_To_Level
435 (Self_ID : Task_Id;
436 T : Task_Id;
437 L : ATC_Level)
439 begin
440 if not T.Aborting and then T /= Self_ID then
441 case T.Common.State is
442 when Unactivated | Terminated =>
443 pragma Assert (False);
444 null;
446 when Activating | Runnable =>
448 -- This is needed to cancel an asynchronous protected entry
449 -- call during a requeue with abort.
451 T.Entry_Calls
452 (T.ATC_Nesting_Level).Cancellation_Attempted := True;
454 when Interrupt_Server_Blocked_On_Event_Flag =>
455 null;
457 when Delay_Sleep |
458 Async_Select_Sleep |
459 Interrupt_Server_Idle_Sleep |
460 Interrupt_Server_Blocked_Interrupt_Sleep |
461 Timer_Server_Sleep |
462 AST_Server_Sleep =>
463 Wakeup (T, T.Common.State);
465 when Acceptor_Sleep | Acceptor_Delay_Sleep =>
466 T.Open_Accepts := null;
467 Wakeup (T, T.Common.State);
469 when Entry_Caller_Sleep =>
470 T.Entry_Calls
471 (T.ATC_Nesting_Level).Cancellation_Attempted := True;
472 Wakeup (T, T.Common.State);
474 when Activator_Sleep |
475 Master_Completion_Sleep |
476 Master_Phase_2_Sleep |
477 Asynchronous_Hold =>
478 null;
479 end case;
480 end if;
482 if T.Pending_ATC_Level > L then
483 T.Pending_ATC_Level := L;
484 T.Pending_Action := True;
486 if L = 0 then
487 T.Callable := False;
488 end if;
490 -- This prevents aborted task from accepting calls
492 if T.Aborting then
494 -- The test above is just a heuristic, to reduce wasteful
495 -- calls to Abort_Task. We are holding T locked, and this
496 -- value will not be set to False except with T also locked,
497 -- inside Exit_One_ATC_Level, so we should not miss wakeups.
499 if T.Common.State = Acceptor_Sleep
500 or else
501 T.Common.State = Acceptor_Delay_Sleep
502 then
503 T.Open_Accepts := null;
504 end if;
506 elsif T /= Self_ID and then
507 (T.Common.State = Runnable
508 or else T.Common.State = Interrupt_Server_Blocked_On_Event_Flag)
510 -- The task is blocked on a system call waiting for the
511 -- completion event. In this case Abort_Task may need to take
512 -- special action in order to succeed. Example system: VMS.
514 then
515 Abort_Task (T);
516 end if;
517 end if;
518 end Locked_Abort_To_Level;
520 --------------------------------
521 -- Remove_From_All_Tasks_List --
522 --------------------------------
524 procedure Remove_From_All_Tasks_List (T : Task_Id) is
525 C : Task_Id;
526 Previous : Task_Id;
528 begin
529 pragma Debug
530 (Debug.Trace (Self, "Remove_From_All_Tasks_List", 'C'));
532 Previous := Null_Task;
533 C := All_Tasks_List;
534 while C /= Null_Task loop
535 if C = T then
536 if Previous = Null_Task then
537 All_Tasks_List := All_Tasks_List.Common.All_Tasks_Link;
538 else
539 Previous.Common.All_Tasks_Link := C.Common.All_Tasks_Link;
540 end if;
542 return;
543 end if;
545 Previous := C;
546 C := C.Common.All_Tasks_Link;
547 end loop;
549 pragma Assert (False);
550 end Remove_From_All_Tasks_List;
552 ---------------
553 -- Task_Lock --
554 ---------------
556 procedure Task_Lock (Self_ID : Task_Id) is
557 begin
558 Self_ID.Common.Global_Task_Lock_Nesting :=
559 Self_ID.Common.Global_Task_Lock_Nesting + 1;
561 if Self_ID.Common.Global_Task_Lock_Nesting = 1 then
562 Defer_Abort_Nestable (Self_ID);
563 Write_Lock (Global_Task_Lock'Access, Global_Lock => True);
564 end if;
565 end Task_Lock;
567 procedure Task_Lock is
568 begin
569 Task_Lock (STPO.Self);
570 end Task_Lock;
572 ---------------
573 -- Task_Name --
574 ---------------
576 function Task_Name return String is
577 Self_Id : constant Task_Id := STPO.Self;
578 begin
579 return Self_Id.Common.Task_Image (1 .. Self_Id.Common.Task_Image_Len);
580 end Task_Name;
582 -----------------
583 -- Task_Unlock --
584 -----------------
586 procedure Task_Unlock (Self_ID : Task_Id) is
587 begin
588 pragma Assert (Self_ID.Common.Global_Task_Lock_Nesting > 0);
589 Self_ID.Common.Global_Task_Lock_Nesting :=
590 Self_ID.Common.Global_Task_Lock_Nesting - 1;
592 if Self_ID.Common.Global_Task_Lock_Nesting = 0 then
593 Unlock (Global_Task_Lock'Access, Global_Lock => True);
594 Undefer_Abort_Nestable (Self_ID);
595 end if;
596 end Task_Unlock;
598 procedure Task_Unlock is
599 begin
600 Task_Unlock (STPO.Self);
601 end Task_Unlock;
603 -------------------
604 -- Undefer_Abort --
605 -------------------
607 -- Precondition : Self does not hold any locks
609 -- Undefer_Abort is called on any abort completion point (aka.
610 -- synchronization point). It performs the following actions if they
611 -- are pending: (1) change the base priority, (2) abort the task.
613 -- The priority change has to occur before abort. Otherwise, it would
614 -- take effect no earlier than the next abort completion point.
616 procedure Undefer_Abort (Self_ID : Task_Id) is
617 begin
618 if No_Abort then
619 return;
620 end if;
622 pragma Assert (Self_ID.Deferral_Level = 1);
624 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
626 if Self_ID.Deferral_Level = 0 then
627 pragma Assert (Check_No_Locks (Self_ID));
629 if Self_ID.Pending_Action then
630 Do_Pending_Action (Self_ID);
631 end if;
632 end if;
633 end Undefer_Abort;
635 ----------------------------
636 -- Undefer_Abort_Nestable --
637 ----------------------------
639 -- An earlier version would re-defer abort if an abort is in progress.
640 -- Then, we modified the effect of the raise statement so that it defers
641 -- abort until control reaches a handler. That was done to prevent
642 -- "skipping over" a handler if another asynchronous abort occurs during
643 -- the propagation of the abort to the handler.
645 -- There has been talk of reversing that decision, based on a newer
646 -- implementation of exception propagation. Care must be taken to evaluate
647 -- how such a change would interact with the above code and all the places
648 -- where abort-deferral is used to bridge over critical transitions, such
649 -- as entry to the scope of a region with a finalizer and entry into the
650 -- body of an accept-procedure.
652 procedure Undefer_Abort_Nestable (Self_ID : Task_Id) is
653 begin
654 if No_Abort then
655 return;
656 end if;
658 pragma Assert (Self_ID.Deferral_Level > 0);
660 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
662 if Self_ID.Deferral_Level = 0 then
664 pragma Assert (Check_No_Locks (Self_ID));
666 if Self_ID.Pending_Action then
667 Do_Pending_Action (Self_ID);
668 end if;
669 end if;
670 end Undefer_Abort_Nestable;
672 -------------------
673 -- Abort_Undefer --
674 -------------------
676 procedure Abort_Undefer is
677 Self_ID : Task_Id;
678 begin
679 if No_Abort then
680 return;
681 end if;
683 Self_ID := STPO.Self;
685 if Self_ID.Deferral_Level = 0 then
687 -- In case there are different views on whether Abort is supported
688 -- between the expander and the run time, we may end up with
689 -- Self_ID.Deferral_Level being equal to zero, when called from
690 -- the procedure created by the expander that corresponds to a
691 -- task body. In this case, there's nothing to be done.
693 -- See related code in System.Tasking.Stages.Create_Task resetting
694 -- Deferral_Level when System.Restrictions.Abort_Allowed is False.
696 return;
697 end if;
699 pragma Assert (Self_ID.Deferral_Level > 0);
700 Self_ID.Deferral_Level := Self_ID.Deferral_Level - 1;
702 if Self_ID.Deferral_Level = 0 then
703 pragma Assert (Check_No_Locks (Self_ID));
705 if Self_ID.Pending_Action then
706 Do_Pending_Action (Self_ID);
707 end if;
708 end if;
709 end Abort_Undefer;
711 ----------------------
712 -- Update_Exception --
713 ----------------------
715 -- Call only when holding no locks
717 procedure Update_Exception
718 (X : AE.Exception_Occurrence := SSL.Current_Target_Exception)
720 Self_Id : constant Task_Id := Self;
721 use Ada.Exceptions;
723 begin
724 Save_Occurrence (Self_Id.Common.Compiler_Data.Current_Excep, X);
726 if Self_Id.Deferral_Level = 0 then
727 if Self_Id.Pending_Action then
728 Self_Id.Pending_Action := False;
729 Self_Id.Deferral_Level := Self_Id.Deferral_Level + 1;
731 if Single_Lock then
732 Lock_RTS;
733 end if;
735 Write_Lock (Self_Id);
736 Self_Id.Pending_Action := False;
737 Unlock (Self_Id);
739 if Single_Lock then
740 Unlock_RTS;
741 end if;
743 Self_Id.Deferral_Level := Self_Id.Deferral_Level - 1;
745 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
746 if not Self_Id.Aborting then
747 Self_Id.Aborting := True;
748 raise Standard'Abort_Signal;
749 end if;
750 end if;
751 end if;
752 end if;
753 end Update_Exception;
755 --------------------------
756 -- Wakeup_Entry_Caller --
757 --------------------------
759 -- This is called at the end of service of an entry call, to abort the
760 -- caller if he is in an abortable part, and to wake up the caller if it
761 -- is on Entry_Caller_Sleep. It assumes that the call is already off-queue.
763 -- (This enforces the rule that a task must be off-queue if its state is
764 -- Done or Cancelled.) Call it holding the lock of Entry_Call.Self.
766 -- Timed_Call or Simple_Call:
767 -- The caller is waiting on Entry_Caller_Sleep, in
768 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
770 -- Conditional_Call:
771 -- The caller might be in Wait_For_Completion,
772 -- waiting for a rendezvous (possibly requeued without abort)
773 -- to complete.
775 -- Asynchronous_Call:
776 -- The caller may be executing in the abortable part o
777 -- an async. select, or on a time delay,
778 -- if Entry_Call.State >= Was_Abortable.
780 procedure Wakeup_Entry_Caller
781 (Self_ID : Task_Id;
782 Entry_Call : Entry_Call_Link;
783 New_State : Entry_Call_State)
785 Caller : constant Task_Id := Entry_Call.Self;
787 begin
788 pragma Debug (Debug.Trace
789 (Self_ID, "Wakeup_Entry_Caller", 'E', Caller));
790 pragma Assert (New_State = Done or else New_State = Cancelled);
792 pragma Assert (Caller.Common.State /= Unactivated);
794 Entry_Call.State := New_State;
796 if Entry_Call.Mode = Asynchronous_Call then
798 -- Abort the caller in his abortable part, but do so only if call has
799 -- been queued abortably.
801 if Entry_Call.State >= Was_Abortable or else New_State = Done then
802 Locked_Abort_To_Level (Self_ID, Caller, Entry_Call.Level - 1);
803 end if;
805 elsif Caller.Common.State = Entry_Caller_Sleep then
806 Wakeup (Caller, Entry_Caller_Sleep);
807 end if;
808 end Wakeup_Entry_Caller;
810 -----------------------
811 -- Soft-Link Dummies --
812 -----------------------
814 -- These are dummies for subprograms that are only needed by certain
815 -- optional run-time system packages. If they are needed, the soft links
816 -- will be redirected to the real subprogram by elaboration of the
817 -- subprogram body where the real subprogram is declared.
819 procedure Finalize_Attributes (T : Task_Id) is
820 pragma Unreferenced (T);
821 begin
822 null;
823 end Finalize_Attributes;
825 procedure Initialize_Attributes (T : Task_Id) is
826 pragma Unreferenced (T);
827 begin
828 null;
829 end Initialize_Attributes;
831 begin
832 Init_RTS;
833 end System.Tasking.Initialization;