OSDN Git Service

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