OSDN Git Service

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