1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . R E N D E Z V O U S --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
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. --
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/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 with System.Task_Primitives.Operations;
33 with System.Tasking.Entry_Calls;
34 with System.Tasking.Initialization;
35 with System.Tasking.Queuing;
36 with System.Tasking.Utilities;
37 with System.Tasking.Protected_Objects.Operations;
38 with System.Tasking.Debug;
39 with System.Restrictions;
40 with System.Parameters;
41 with System.Traces.Tasking;
43 package body System.Tasking.Rendezvous is
45 package STPO renames System.Task_Primitives.Operations;
46 package POO renames Protected_Objects.Operations;
47 package POE renames Protected_Objects.Entries;
50 use Task_Primitives.Operations;
52 use System.Traces.Tasking;
54 type Select_Treatment is (
55 Accept_Alternative_Selected, -- alternative with non-null body
56 Accept_Alternative_Completed, -- alternative with null body
59 Accept_Alternative_Open,
66 Default_Treatment : constant array (Select_Modes) of Select_Treatment :=
67 (Simple_Mode => No_Alternative_Open,
68 Else_Mode => Else_Selected,
69 Terminate_Mode => Terminate_Selected,
70 Delay_Mode => No_Alternative_Open);
72 New_State : constant array (Boolean, Entry_Call_State)
73 of Entry_Call_State :=
75 (Never_Abortable => Never_Abortable,
76 Not_Yet_Abortable => Now_Abortable,
77 Was_Abortable => Now_Abortable,
78 Now_Abortable => Now_Abortable,
80 Cancelled => Cancelled),
82 (Never_Abortable => Never_Abortable,
83 Not_Yet_Abortable => Not_Yet_Abortable,
84 Was_Abortable => Was_Abortable,
85 Now_Abortable => Now_Abortable,
87 Cancelled => Cancelled)
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Local_Defer_Abort (Self_Id : Task_Id) renames
95 System.Tasking.Initialization.Defer_Abort_Nestable;
97 procedure Local_Undefer_Abort (Self_Id : Task_Id) renames
98 System.Tasking.Initialization.Undefer_Abort_Nestable;
100 -- Florist defers abort around critical sections that
101 -- make entry calls to the Interrupt_Manager task, which
102 -- violates the general rule about top-level runtime system
103 -- calls from abort-deferred regions. It is not that this is
104 -- unsafe, but when it occurs in "normal" programs it usually
105 -- means either the user is trying to do a potentially blocking
106 -- operation from within a protected object, or there is a
107 -- runtime system/compiler error that has failed to undefer
108 -- an earlier abort deferral. Thus, for debugging it may be
109 -- wise to modify the above renamings to the non-nestable forms.
111 procedure Boost_Priority (Call : Entry_Call_Link; Acceptor : Task_Id);
112 pragma Inline (Boost_Priority);
113 -- Call this only with abort deferred and holding lock of Acceptor
115 procedure Call_Synchronous
117 E : Task_Entry_Index;
118 Uninterpreted_Data : System.Address;
120 Rendezvous_Successful : out Boolean);
121 pragma Inline (Call_Synchronous);
122 -- This call is used to make a simple or conditional entry call.
123 -- Called from Call_Simple and Task_Entry_Call.
125 procedure Setup_For_Rendezvous_With_Body
126 (Entry_Call : Entry_Call_Link;
128 pragma Inline (Setup_For_Rendezvous_With_Body);
129 -- Call this only with abort deferred and holding lock of Acceptor.
130 -- When a rendezvous selected (ready for rendezvous) we need to save
131 -- previous caller and adjust the priority. Also we need to make
132 -- this call not Abortable (Cancellable) since the rendezvous has
133 -- already been started.
135 procedure Wait_For_Call (Self_Id : Task_Id);
136 pragma Inline (Wait_For_Call);
137 -- Call this only with abort deferred and holding lock of Self_Id.
138 -- An accepting task goes into Sleep by calling this routine
139 -- waiting for a call from the caller or waiting for an abort.
140 -- Make sure Self_Id is locked before calling this routine.
146 procedure Accept_Call
147 (E : Task_Entry_Index;
148 Uninterpreted_Data : out System.Address)
150 Self_Id : constant Task_Id := STPO.Self;
151 Caller : Task_Id := null;
152 Open_Accepts : aliased Accept_List (1 .. 1);
153 Entry_Call : Entry_Call_Link;
156 Initialization.Defer_Abort (Self_Id);
162 STPO.Write_Lock (Self_Id);
164 if not Self_Id.Callable then
165 pragma Assert (Self_Id.Pending_ATC_Level = 0);
167 pragma Assert (Self_Id.Pending_Action);
169 STPO.Unlock (Self_Id);
175 Initialization.Undefer_Abort (Self_Id);
177 -- Should never get here ???
179 pragma Assert (False);
180 raise Standard'Abort_Signal;
183 Queuing.Dequeue_Head (Self_Id.Entry_Queues (E), Entry_Call);
185 if Entry_Call /= null then
186 Caller := Entry_Call.Self;
187 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
188 Uninterpreted_Data := Entry_Call.Uninterpreted_Data;
193 Open_Accepts (1).Null_Body := False;
194 Open_Accepts (1).S := E;
195 Self_Id.Open_Accepts := Open_Accepts'Unrestricted_Access;
197 -- Wait for normal call
199 if Parameters.Runtime_Traces then
200 Send_Trace_Info (W_Accept, Self_Id, Integer (Open_Accepts'Length));
204 (Debug.Trace (Self_Id, "Accept_Call: wait", 'R'));
205 Wait_For_Call (Self_Id);
207 pragma Assert (Self_Id.Open_Accepts = null);
209 if Self_Id.Common.Call /= null then
210 Caller := Self_Id.Common.Call.Self;
211 Uninterpreted_Data :=
212 Caller.Entry_Calls (Caller.ATC_Nesting_Level).Uninterpreted_Data;
214 -- Case of an aborted task
216 Uninterpreted_Data := System.Null_Address;
220 -- Self_Id.Common.Call should already be updated by the Caller
221 -- On return, we will start the rendezvous.
223 STPO.Unlock (Self_Id);
229 Initialization.Undefer_Abort (Self_Id);
231 if Parameters.Runtime_Traces then
232 Send_Trace_Info (M_Accept_Complete, Caller, Entry_Index (E));
240 procedure Accept_Trivial (E : Task_Entry_Index) is
241 Self_Id : constant Task_Id := STPO.Self;
242 Caller : Task_Id := null;
243 Open_Accepts : aliased Accept_List (1 .. 1);
244 Entry_Call : Entry_Call_Link;
247 Initialization.Defer_Abort_Nestable (Self_Id);
253 STPO.Write_Lock (Self_Id);
255 if not Self_Id.Callable then
256 pragma Assert (Self_Id.Pending_ATC_Level = 0);
258 pragma Assert (Self_Id.Pending_Action);
260 STPO.Unlock (Self_Id);
266 Initialization.Undefer_Abort_Nestable (Self_Id);
268 -- Should never get here ???
270 pragma Assert (False);
271 raise Standard'Abort_Signal;
274 Queuing.Dequeue_Head (Self_Id.Entry_Queues (E), Entry_Call);
276 if Entry_Call = null then
277 -- Need to wait for entry call
279 Open_Accepts (1).Null_Body := True;
280 Open_Accepts (1).S := E;
281 Self_Id.Open_Accepts := Open_Accepts'Unrestricted_Access;
283 if Parameters.Runtime_Traces then
284 Send_Trace_Info (W_Accept, Self_Id, Integer (Open_Accepts'Length));
288 (Debug.Trace (Self_Id, "Accept_Trivial: wait", 'R'));
290 Wait_For_Call (Self_Id);
292 pragma Assert (Self_Id.Open_Accepts = null);
294 -- No need to do anything special here for pending abort.
295 -- Abort_Signal will be raised by Undefer on exit.
297 STPO.Unlock (Self_Id);
299 else -- found caller already waiting
300 pragma Assert (Entry_Call.State < Done);
302 STPO.Unlock (Self_Id);
303 Caller := Entry_Call.Self;
305 STPO.Write_Lock (Caller);
306 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
307 STPO.Unlock (Caller);
310 if Parameters.Runtime_Traces then
311 Send_Trace_Info (M_Accept_Complete);
313 -- Fake one, since there is (???) no way
314 -- to know that the rendezvous is over
316 Send_Trace_Info (M_RDV_Complete);
323 Initialization.Undefer_Abort_Nestable (Self_Id);
330 procedure Boost_Priority (Call : Entry_Call_Link; Acceptor : Task_Id) is
331 Caller : constant Task_Id := Call.Self;
332 Caller_Prio : constant System.Any_Priority := Get_Priority (Caller);
333 Acceptor_Prio : constant System.Any_Priority := Get_Priority (Acceptor);
336 if Caller_Prio > Acceptor_Prio then
337 Call.Acceptor_Prev_Priority := Acceptor_Prio;
338 Set_Priority (Acceptor, Caller_Prio);
341 Call.Acceptor_Prev_Priority := Priority_Not_Boosted;
349 procedure Call_Simple
351 E : Task_Entry_Index;
352 Uninterpreted_Data : System.Address)
354 Rendezvous_Successful : Boolean;
355 pragma Unreferenced (Rendezvous_Successful);
358 -- If pragma Detect_Blocking is active then Program_Error must be
359 -- raised if this potentially blocking operation is called from a
362 if System.Tasking.Detect_Blocking
363 and then STPO.Self.Common.Protected_Action_Nesting > 0
365 raise Program_Error with "potentially blocking operation";
369 (Acceptor, E, Uninterpreted_Data, Simple_Call, Rendezvous_Successful);
372 ----------------------
373 -- Call_Synchronous --
374 ----------------------
376 procedure Call_Synchronous
378 E : Task_Entry_Index;
379 Uninterpreted_Data : System.Address;
381 Rendezvous_Successful : out Boolean)
383 Self_Id : constant Task_Id := STPO.Self;
385 Entry_Call : Entry_Call_Link;
388 pragma Assert (Mode /= Asynchronous_Call);
390 Local_Defer_Abort (Self_Id);
391 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
393 (Debug.Trace (Self_Id, "CS: entered ATC level: " &
394 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
395 Level := Self_Id.ATC_Nesting_Level;
396 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
397 Entry_Call.Next := null;
398 Entry_Call.Mode := Mode;
399 Entry_Call.Cancellation_Attempted := False;
401 if Parameters.Runtime_Traces then
402 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
405 -- If this is a call made inside of an abort deferred region,
406 -- the call should be never abortable.
408 if Self_Id.Deferral_Level > 1 then
409 Entry_Call.State := Never_Abortable;
411 Entry_Call.State := Now_Abortable;
414 Entry_Call.E := Entry_Index (E);
415 Entry_Call.Prio := Get_Priority (Self_Id);
416 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
417 Entry_Call.Called_Task := Acceptor;
418 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
419 Entry_Call.With_Abort := True;
421 -- Note: the caller will undefer abort on return (see WARNING above)
427 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
428 STPO.Write_Lock (Self_Id);
429 Utilities.Exit_One_ATC_Level (Self_Id);
430 STPO.Unlock (Self_Id);
436 if Parameters.Runtime_Traces then
437 Send_Trace_Info (E_Missed, Acceptor);
440 Local_Undefer_Abort (Self_Id);
444 STPO.Write_Lock (Self_Id);
446 (Debug.Trace (Self_Id, "Call_Synchronous: wait", 'R'));
447 Entry_Calls.Wait_For_Completion (Entry_Call);
449 (Debug.Trace (Self_Id, "Call_Synchronous: done waiting", 'R'));
450 Rendezvous_Successful := Entry_Call.State = Done;
451 STPO.Unlock (Self_Id);
457 Local_Undefer_Abort (Self_Id);
458 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
459 end Call_Synchronous;
465 function Callable (T : Task_Id) return Boolean is
467 Self_Id : constant Task_Id := STPO.Self;
470 Initialization.Defer_Abort_Nestable (Self_Id);
477 Result := T.Callable;
484 Initialization.Undefer_Abort_Nestable (Self_Id);
488 ----------------------------
489 -- Cancel_Task_Entry_Call --
490 ----------------------------
492 procedure Cancel_Task_Entry_Call (Cancelled : out Boolean) is
494 Entry_Calls.Try_To_Cancel_Entry_Call (Cancelled);
495 end Cancel_Task_Entry_Call;
497 -------------------------
498 -- Complete_Rendezvous --
499 -------------------------
501 procedure Complete_Rendezvous is
503 Exceptional_Complete_Rendezvous (Ada.Exceptions.Null_Id);
504 end Complete_Rendezvous;
506 -------------------------------------
507 -- Exceptional_Complete_Rendezvous --
508 -------------------------------------
510 procedure Exceptional_Complete_Rendezvous
511 (Ex : Ada.Exceptions.Exception_Id)
513 Self_Id : constant Task_Id := STPO.Self;
514 Entry_Call : Entry_Call_Link := Self_Id.Common.Call;
516 Called_PO : STPE.Protection_Entries_Access;
517 Acceptor_Prev_Priority : Integer;
519 Exception_To_Raise : Ada.Exceptions.Exception_Id := Ex;
520 Ceiling_Violation : Boolean;
522 use type Ada.Exceptions.Exception_Id;
523 procedure Internal_Reraise;
524 pragma Import (C, Internal_Reraise, "__gnat_reraise");
526 procedure Transfer_Occurrence
527 (Target : Ada.Exceptions.Exception_Occurrence_Access;
528 Source : Ada.Exceptions.Exception_Occurrence);
529 pragma Import (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
531 use type STPE.Protection_Entries_Access;
534 -- Consider phasing out Complete_Rendezvous in favor
535 -- of direct call to this with Ada.Exceptions.Null_ID.
536 -- See code expansion examples for Accept_Call and Selective_Wait.
537 -- Also consider putting an explicit re-raise after this call, in
538 -- the generated code. That way we could eliminate the
539 -- code here that reraises the exception.
541 -- The deferral level is critical here,
542 -- since we want to raise an exception or allow abort to take
543 -- place, if there is an exception or abort pending.
546 (Debug.Trace (Self_Id, "Exceptional_Complete_Rendezvous", 'R'));
548 if Ex = Ada.Exceptions.Null_Id then
549 -- The call came from normal end-of-rendezvous,
550 -- so abort is not yet deferred.
552 if Parameters.Runtime_Traces then
553 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
556 Initialization.Defer_Abort_Nestable (Self_Id);
559 -- We need to clean up any accepts which Self may have
560 -- been serving when it was aborted.
562 if Ex = Standard'Abort_Signal'Identity then
567 while Entry_Call /= null loop
568 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
570 -- All forms of accept make sure that the acceptor is not
571 -- completed, before accepting further calls, so that we
572 -- can be sure that no further calls are made after the
573 -- current calls are purged.
575 Caller := Entry_Call.Self;
577 -- Take write lock. This follows the lock precedence rule that
578 -- Caller may be locked while holding lock of Acceptor.
579 -- Complete the call abnormally, with exception.
581 STPO.Write_Lock (Caller);
582 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
583 STPO.Unlock (Caller);
584 Entry_Call := Entry_Call.Acceptor_Prev_Call;
592 Caller := Entry_Call.Self;
594 if Entry_Call.Needs_Requeue then
595 -- We dare not lock Self_Id at the same time as Caller,
596 -- for fear of deadlock.
598 Entry_Call.Needs_Requeue := False;
599 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
601 if Entry_Call.Called_Task /= null then
602 -- Requeue to another task entry
608 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
613 Initialization.Undefer_Abort (Self_Id);
622 -- Requeue to a protected entry
624 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
625 STPE.Lock_Entries (Called_PO, Ceiling_Violation);
627 if Ceiling_Violation then
628 pragma Assert (Ex = Ada.Exceptions.Null_Id);
630 Exception_To_Raise := Program_Error'Identity;
631 Entry_Call.Exception_To_Raise := Exception_To_Raise;
637 STPO.Write_Lock (Caller);
638 Initialization.Wakeup_Entry_Caller
639 (Self_Id, Entry_Call, Done);
640 STPO.Unlock (Caller);
647 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
648 POO.PO_Service_Entries (Self_Id, Called_PO);
652 Entry_Calls.Reset_Priority
653 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
656 -- The call does not need to be requeued
658 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
659 Entry_Call.Exception_To_Raise := Ex;
665 STPO.Write_Lock (Caller);
667 -- Done with Caller locked to make sure that Wakeup is not lost
669 if Ex /= Ada.Exceptions.Null_Id then
671 (Caller.Common.Compiler_Data.Current_Excep'Access,
672 Self_Id.Common.Compiler_Data.Current_Excep);
675 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
676 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
678 STPO.Unlock (Caller);
684 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
688 Initialization.Undefer_Abort (Self_Id);
690 if Exception_To_Raise /= Ada.Exceptions.Null_Id then
694 -- ??? Do we need to give precedence to Program_Error that might be
695 -- raised due to failure of finalization, over Tasking_Error from
696 -- failure of requeue?
697 end Exceptional_Complete_Rendezvous;
699 -------------------------------------
700 -- Requeue_Protected_To_Task_Entry --
701 -------------------------------------
703 procedure Requeue_Protected_To_Task_Entry
704 (Object : STPE.Protection_Entries_Access;
706 E : Task_Entry_Index;
707 With_Abort : Boolean)
709 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
711 pragma Assert (STPO.Self.Deferral_Level > 0);
713 Entry_Call.E := Entry_Index (E);
714 Entry_Call.Called_Task := Acceptor;
715 Entry_Call.Called_PO := Null_Address;
716 Entry_Call.With_Abort := With_Abort;
717 Object.Call_In_Progress := null;
718 end Requeue_Protected_To_Task_Entry;
720 ------------------------
721 -- Requeue_Task_Entry --
722 ------------------------
724 procedure Requeue_Task_Entry
726 E : Task_Entry_Index;
727 With_Abort : Boolean)
729 Self_Id : constant Task_Id := STPO.Self;
730 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
733 Initialization.Defer_Abort (Self_Id);
734 Entry_Call.Needs_Requeue := True;
735 Entry_Call.With_Abort := With_Abort;
736 Entry_Call.E := Entry_Index (E);
737 Entry_Call.Called_Task := Acceptor;
738 Initialization.Undefer_Abort (Self_Id);
739 end Requeue_Task_Entry;
745 procedure Selective_Wait
746 (Open_Accepts : Accept_List_Access;
747 Select_Mode : Select_Modes;
748 Uninterpreted_Data : out System.Address;
749 Index : out Select_Index)
751 Self_Id : constant Task_Id := STPO.Self;
752 Entry_Call : Entry_Call_Link;
753 Treatment : Select_Treatment;
755 Selection : Select_Index;
756 Open_Alternative : Boolean;
759 Initialization.Defer_Abort (Self_Id);
765 STPO.Write_Lock (Self_Id);
767 if not Self_Id.Callable then
768 pragma Assert (Self_Id.Pending_ATC_Level = 0);
770 pragma Assert (Self_Id.Pending_Action);
772 STPO.Unlock (Self_Id);
778 -- ??? In some cases abort is deferred more than once. Need to
779 -- figure out why this happens.
781 if Self_Id.Deferral_Level > 1 then
782 Self_Id.Deferral_Level := 1;
785 Initialization.Undefer_Abort (Self_Id);
787 -- Should never get here ???
789 pragma Assert (False);
790 raise Standard'Abort_Signal;
793 pragma Assert (Open_Accepts /= null);
795 Uninterpreted_Data := Null_Address;
797 Queuing.Select_Task_Entry_Call
798 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
800 -- Determine the kind and disposition of the select
802 Treatment := Default_Treatment (Select_Mode);
803 Self_Id.Chosen_Index := No_Rendezvous;
805 if Open_Alternative then
806 if Entry_Call /= null then
807 if Open_Accepts (Selection).Null_Body then
808 Treatment := Accept_Alternative_Completed;
810 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
811 Treatment := Accept_Alternative_Selected;
814 Self_Id.Chosen_Index := Selection;
816 elsif Treatment = No_Alternative_Open then
817 Treatment := Accept_Alternative_Open;
821 -- Handle the select according to the disposition selected above
824 when Accept_Alternative_Selected =>
825 -- Ready to rendezvous
827 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
829 -- In this case the accept body is not Null_Body. Defer abort
830 -- until it gets into the accept body.
832 pragma Assert (Self_Id.Deferral_Level = 1);
834 Initialization.Defer_Abort_Nestable (Self_Id);
835 STPO.Unlock (Self_Id);
837 when Accept_Alternative_Completed =>
839 -- Accept body is null, so rendezvous is over immediately
841 if Parameters.Runtime_Traces then
842 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
845 STPO.Unlock (Self_Id);
846 Caller := Entry_Call.Self;
848 STPO.Write_Lock (Caller);
849 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
850 STPO.Unlock (Caller);
852 when Accept_Alternative_Open =>
856 Self_Id.Open_Accepts := Open_Accepts;
858 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R'));
860 if Parameters.Runtime_Traces then
861 Send_Trace_Info (W_Select, Self_Id,
862 Integer (Open_Accepts'Length));
865 Wait_For_Call (Self_Id);
867 pragma Assert (Self_Id.Open_Accepts = null);
869 -- Self_Id.Common.Call should already be updated by the Caller if
870 -- not aborted. It might also be ready to do rendezvous even if
871 -- this wakes up due to an abort. Therefore, if the call is not
872 -- empty we need to do the rendezvous if the accept body is not
875 -- Aren't the first two conditions below redundant???
877 if Self_Id.Chosen_Index /= No_Rendezvous
878 and then Self_Id.Common.Call /= null
879 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
881 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
884 (Self_Id.Deferral_Level = 1
886 (Self_Id.Deferral_Level = 0
887 and then not Restrictions.Abort_Allowed));
889 Initialization.Defer_Abort_Nestable (Self_Id);
891 -- Leave abort deferred until the accept body
894 STPO.Unlock (Self_Id);
896 when Else_Selected =>
897 pragma Assert (Self_Id.Open_Accepts = null);
899 if Parameters.Runtime_Traces then
900 Send_Trace_Info (M_Select_Else);
903 STPO.Unlock (Self_Id);
905 when Terminate_Selected =>
906 -- Terminate alternative is open
908 Self_Id.Open_Accepts := Open_Accepts;
909 Self_Id.Common.State := Acceptor_Sleep;
911 -- Notify ancestors that this task is on a terminate alternative
913 STPO.Unlock (Self_Id);
914 Utilities.Make_Passive (Self_Id, Task_Completed => False);
915 STPO.Write_Lock (Self_Id);
917 -- Wait for normal entry call or termination
919 Wait_For_Call (Self_Id);
921 pragma Assert (Self_Id.Open_Accepts = null);
923 if Self_Id.Terminate_Alternative then
924 -- An entry call should have reset this to False,
925 -- so we must be aborted.
926 -- We cannot be in an async. select, since that
927 -- is not legal, so the abort must be of the entire
928 -- task. Therefore, we do not need to cancel the
929 -- terminate alternative. The cleanup will be done
930 -- in Complete_Master.
932 pragma Assert (Self_Id.Pending_ATC_Level = 0);
933 pragma Assert (Self_Id.Awake_Count = 0);
935 STPO.Unlock (Self_Id);
941 Index := Self_Id.Chosen_Index;
942 Initialization.Undefer_Abort_Nestable (Self_Id);
944 if Self_Id.Pending_Action then
945 Initialization.Do_Pending_Action (Self_Id);
951 -- Self_Id.Common.Call and Self_Id.Chosen_Index
952 -- should already be updated by the Caller.
954 if Self_Id.Chosen_Index /= No_Rendezvous
955 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
957 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
959 pragma Assert (Self_Id.Deferral_Level = 1);
961 -- We need an extra defer here, to keep abort
962 -- deferred until we get into the accept body
964 Initialization.Defer_Abort_Nestable (Self_Id);
968 STPO.Unlock (Self_Id);
970 when No_Alternative_Open =>
971 -- In this case, Index will be No_Rendezvous on return, which
972 -- should cause a Program_Error if it is not a Delay_Mode.
974 -- If delay alternative exists (Delay_Mode) we should suspend
975 -- until the delay expires.
977 Self_Id.Open_Accepts := null;
979 if Select_Mode = Delay_Mode then
980 Self_Id.Common.State := Delay_Sleep;
984 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
985 Sleep (Self_Id, Delay_Sleep);
988 Self_Id.Common.State := Runnable;
989 STPO.Unlock (Self_Id);
992 STPO.Unlock (Self_Id);
998 Initialization.Undefer_Abort (Self_Id);
999 raise Program_Error with "Entry call not a delay mode";
1007 -- Caller has been chosen.
1008 -- Self_Id.Common.Call should already be updated by the Caller.
1009 -- Self_Id.Chosen_Index should either be updated by the Caller
1010 -- or by Test_Selective_Wait.
1011 -- On return, we sill start rendezvous unless the accept body is
1012 -- null. In the latter case, we will have already completed the RV.
1014 Index := Self_Id.Chosen_Index;
1015 Initialization.Undefer_Abort_Nestable (Self_Id);
1018 ------------------------------------
1019 -- Setup_For_Rendezvous_With_Body --
1020 ------------------------------------
1022 procedure Setup_For_Rendezvous_With_Body
1023 (Entry_Call : Entry_Call_Link;
1024 Acceptor : Task_Id) is
1026 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1027 Acceptor.Common.Call := Entry_Call;
1029 if Entry_Call.State = Now_Abortable then
1030 Entry_Call.State := Was_Abortable;
1033 Boost_Priority (Entry_Call, Acceptor);
1034 end Setup_For_Rendezvous_With_Body;
1040 function Task_Count (E : Task_Entry_Index) return Natural is
1041 Self_Id : constant Task_Id := STPO.Self;
1042 Return_Count : Natural;
1045 Initialization.Defer_Abort (Self_Id);
1051 STPO.Write_Lock (Self_Id);
1052 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1053 STPO.Unlock (Self_Id);
1059 Initialization.Undefer_Abort (Self_Id);
1061 -- Call Yield to let other tasks get a chance to run as this is a
1062 -- potential dispatching point.
1064 Yield (Do_Yield => False);
1065 return Return_Count;
1068 ----------------------
1069 -- Task_Do_Or_Queue --
1070 ----------------------
1072 function Task_Do_Or_Queue
1074 Entry_Call : Entry_Call_Link) return Boolean
1076 E : constant Task_Entry_Index :=
1077 Task_Entry_Index (Entry_Call.E);
1078 Old_State : constant Entry_Call_State := Entry_Call.State;
1079 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1080 Parent : constant Task_Id := Acceptor.Common.Parent;
1081 Parent_Locked : Boolean := False;
1082 Null_Body : Boolean;
1085 -- Find out whether Entry_Call can be accepted immediately
1087 -- If the Acceptor is not callable, return False.
1088 -- If the rendezvous can start, initiate it.
1089 -- If the accept-body is trivial, also complete the rendezvous.
1090 -- If the acceptor is not ready, enqueue the call.
1092 -- This should have a special case for Accept_Call and Accept_Trivial,
1093 -- so that we don't have the loop setup overhead, below.
1095 -- The call state Done is used here and elsewhere to include both the
1096 -- case of normal successful completion, and the case of an exception
1097 -- being raised. The difference is that if an exception is raised no one
1098 -- will pay attention to the fact that State = Done. Instead the
1099 -- exception will be raised in Undefer_Abort, and control will skip past
1100 -- the place where we normally would resume from an entry call.
1102 pragma Assert (not Queuing.Onqueue (Entry_Call));
1104 -- We rely that the call is off-queue for protection, that the caller
1105 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1106 -- record for another call.
1107 -- We rely on the Caller's lock for call State mod's.
1109 -- We can't lock Acceptor.Parent while holding Acceptor,
1110 -- so lock it in advance if we expect to need to lock it.
1112 if Acceptor.Terminate_Alternative then
1113 STPO.Write_Lock (Parent);
1114 Parent_Locked := True;
1117 STPO.Write_Lock (Acceptor);
1119 -- If the acceptor is not callable, abort the call and return False
1121 if not Acceptor.Callable then
1122 STPO.Unlock (Acceptor);
1124 if Parent_Locked then
1125 STPO.Unlock (Parent);
1128 pragma Assert (Entry_Call.State < Done);
1130 -- In case we are not the caller, set up the caller
1131 -- to raise Tasking_Error when it wakes up.
1133 STPO.Write_Lock (Entry_Call.Self);
1134 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1135 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1136 STPO.Unlock (Entry_Call.Self);
1141 -- Try to serve the call immediately
1143 if Acceptor.Open_Accepts /= null then
1144 for J in Acceptor.Open_Accepts'Range loop
1145 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1147 -- Commit acceptor to rendezvous with us
1149 Acceptor.Chosen_Index := J;
1150 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1151 Acceptor.Open_Accepts := null;
1153 -- Prevent abort while call is being served
1155 if Entry_Call.State = Now_Abortable then
1156 Entry_Call.State := Was_Abortable;
1159 if Acceptor.Terminate_Alternative then
1161 -- Cancel terminate alternative. See matching code in
1162 -- Selective_Wait and Vulnerable_Complete_Master.
1164 Acceptor.Terminate_Alternative := False;
1165 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1167 if Acceptor.Awake_Count = 1 then
1169 -- Notify parent that acceptor is awake
1171 pragma Assert (Parent.Awake_Count > 0);
1173 Parent.Awake_Count := Parent.Awake_Count + 1;
1175 if Parent.Common.State = Master_Completion_Sleep
1176 and then Acceptor.Master_of_Task = Parent.Master_Within
1178 Parent.Common.Wait_Count :=
1179 Parent.Common.Wait_Count + 1;
1186 -- Rendezvous is over immediately
1188 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1189 STPO.Unlock (Acceptor);
1191 if Parent_Locked then
1192 STPO.Unlock (Parent);
1195 STPO.Write_Lock (Entry_Call.Self);
1196 Initialization.Wakeup_Entry_Caller
1197 (Self_ID, Entry_Call, Done);
1198 STPO.Unlock (Entry_Call.Self);
1201 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1203 -- For terminate_alternative, acceptor may not be asleep
1204 -- yet, so we skip the wakeup
1206 if Acceptor.Common.State /= Runnable then
1207 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1210 STPO.Unlock (Acceptor);
1212 if Parent_Locked then
1213 STPO.Unlock (Parent);
1221 -- The acceptor is accepting, but not this entry
1224 -- If the acceptor was ready to accept this call,
1225 -- we would not have gotten this far, so now we should
1226 -- (re)enqueue the call, if the mode permits that.
1228 if Entry_Call.Mode /= Conditional_Call
1229 or else not Entry_Call.With_Abort
1231 -- Timed_Call, Simple_Call, or Asynchronous_Call
1233 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1235 -- Update abortability of call
1237 pragma Assert (Old_State < Done);
1240 New_State (Entry_Call.With_Abort, Entry_Call.State);
1242 STPO.Unlock (Acceptor);
1244 if Parent_Locked then
1245 STPO.Unlock (Parent);
1248 if Old_State /= Entry_Call.State
1249 and then Entry_Call.State = Now_Abortable
1250 and then Entry_Call.Mode > Simple_Call
1251 and then Entry_Call.Self /= Self_ID
1253 -- Asynchronous_Call or Conditional_Call
1256 -- Because of ATCB lock ordering rule
1258 STPO.Write_Lock (Entry_Call.Self);
1260 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1262 -- Caller may not yet have reached wait-point
1264 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1267 STPO.Unlock (Entry_Call.Self);
1271 -- Conditional_Call and With_Abort
1273 STPO.Unlock (Acceptor);
1275 if Parent_Locked then
1276 STPO.Unlock (Parent);
1279 STPO.Write_Lock (Entry_Call.Self);
1281 pragma Assert (Entry_Call.State >= Was_Abortable);
1283 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1284 STPO.Unlock (Entry_Call.Self);
1288 end Task_Do_Or_Queue;
1290 ---------------------
1291 -- Task_Entry_Call --
1292 ---------------------
1294 procedure Task_Entry_Call
1295 (Acceptor : Task_Id;
1296 E : Task_Entry_Index;
1297 Uninterpreted_Data : System.Address;
1299 Rendezvous_Successful : out Boolean)
1301 Self_Id : constant Task_Id := STPO.Self;
1302 Entry_Call : Entry_Call_Link;
1305 -- If pragma Detect_Blocking is active then Program_Error must be
1306 -- raised if this potentially blocking operation is called from a
1307 -- protected action.
1309 if System.Tasking.Detect_Blocking
1310 and then Self_Id.Common.Protected_Action_Nesting > 0
1312 raise Program_Error with "potentially blocking operation";
1315 if Parameters.Runtime_Traces then
1316 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1319 if Mode = Simple_Call or else Mode = Conditional_Call then
1321 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1324 -- This is an asynchronous call
1326 -- Abort must already be deferred by the compiler-generated code.
1327 -- Without this, an abort that occurs between the time that this
1328 -- call is made and the time that the abortable part's cleanup
1329 -- handler is set up might miss the cleanup handler and leave the
1332 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1334 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1335 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
1336 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1337 Entry_Call.Next := null;
1338 Entry_Call.Mode := Mode;
1339 Entry_Call.Cancellation_Attempted := False;
1340 Entry_Call.State := Not_Yet_Abortable;
1341 Entry_Call.E := Entry_Index (E);
1342 Entry_Call.Prio := Get_Priority (Self_Id);
1343 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1344 Entry_Call.Called_Task := Acceptor;
1345 Entry_Call.Called_PO := Null_Address;
1346 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1347 Entry_Call.With_Abort := True;
1353 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1354 STPO.Write_Lock (Self_Id);
1355 Utilities.Exit_One_ATC_Level (Self_Id);
1356 STPO.Unlock (Self_Id);
1362 Initialization.Undefer_Abort (Self_Id);
1364 if Parameters.Runtime_Traces then
1365 Send_Trace_Info (E_Missed, Acceptor);
1368 raise Tasking_Error;
1371 -- The following is special for async. entry calls.
1372 -- If the call was not queued abortably, we need to wait until
1373 -- it is before proceeding with the abortable part.
1375 -- Wait_Until_Abortable can be called unconditionally here,
1376 -- but it is expensive.
1378 if Entry_Call.State < Was_Abortable then
1379 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1386 -- Note: following assignment needs to be atomic
1388 Rendezvous_Successful := Entry_Call.State = Done;
1390 end Task_Entry_Call;
1392 -----------------------
1393 -- Task_Entry_Caller --
1394 -----------------------
1396 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1397 Self_Id : constant Task_Id := STPO.Self;
1398 Entry_Call : Entry_Call_Link;
1401 Entry_Call := Self_Id.Common.Call;
1403 for Depth in 1 .. D loop
1404 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1405 pragma Assert (Entry_Call /= null);
1408 return Entry_Call.Self;
1409 end Task_Entry_Caller;
1411 --------------------------
1412 -- Timed_Selective_Wait --
1413 --------------------------
1415 procedure Timed_Selective_Wait
1416 (Open_Accepts : Accept_List_Access;
1417 Select_Mode : Select_Modes;
1418 Uninterpreted_Data : out System.Address;
1421 Index : out Select_Index)
1423 Self_Id : constant Task_Id := STPO.Self;
1424 Treatment : Select_Treatment;
1425 Entry_Call : Entry_Call_Link;
1427 Selection : Select_Index;
1428 Open_Alternative : Boolean;
1429 Timedout : Boolean := False;
1430 Yielded : Boolean := True;
1433 pragma Assert (Select_Mode = Delay_Mode);
1435 Initialization.Defer_Abort (Self_Id);
1437 -- If we are aborted here, the effect will be pending
1443 STPO.Write_Lock (Self_Id);
1445 if not Self_Id.Callable then
1446 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1448 pragma Assert (Self_Id.Pending_Action);
1450 STPO.Unlock (Self_Id);
1456 Initialization.Undefer_Abort (Self_Id);
1458 -- Should never get here ???
1460 pragma Assert (False);
1461 raise Standard'Abort_Signal;
1464 Uninterpreted_Data := Null_Address;
1466 pragma Assert (Open_Accepts /= null);
1468 Queuing.Select_Task_Entry_Call
1469 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1471 -- Determine the kind and disposition of the select
1473 Treatment := Default_Treatment (Select_Mode);
1474 Self_Id.Chosen_Index := No_Rendezvous;
1476 if Open_Alternative then
1477 if Entry_Call /= null then
1478 if Open_Accepts (Selection).Null_Body then
1479 Treatment := Accept_Alternative_Completed;
1482 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1483 Treatment := Accept_Alternative_Selected;
1486 Self_Id.Chosen_Index := Selection;
1488 elsif Treatment = No_Alternative_Open then
1489 Treatment := Accept_Alternative_Open;
1493 -- Handle the select according to the disposition selected above
1496 when Accept_Alternative_Selected =>
1497 -- Ready to rendezvous
1498 -- In this case the accept body is not Null_Body. Defer abort
1499 -- until it gets into the accept body.
1501 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1502 Initialization.Defer_Abort (Self_Id);
1503 STPO.Unlock (Self_Id);
1505 when Accept_Alternative_Completed =>
1506 -- Rendezvous is over
1508 if Parameters.Runtime_Traces then
1509 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1512 STPO.Unlock (Self_Id);
1513 Caller := Entry_Call.Self;
1515 STPO.Write_Lock (Caller);
1516 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1517 STPO.Unlock (Caller);
1519 when Accept_Alternative_Open =>
1523 Self_Id.Open_Accepts := Open_Accepts;
1525 -- Wait for a normal call and a pending action until the
1526 -- Wakeup_Time is reached.
1528 Self_Id.Common.State := Acceptor_Sleep;
1530 -- Try to remove calls to Sleep in the loop below by letting the
1531 -- caller a chance of getting ready immediately, using Unlock
1532 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1540 if Self_Id.Open_Accepts /= null then
1547 Write_Lock (Self_Id);
1550 -- Check if this task has been aborted while the lock was released
1552 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1553 Self_Id.Open_Accepts := null;
1557 exit when Self_Id.Open_Accepts = null;
1560 Sleep (Self_Id, Acceptor_Sleep);
1562 if Parameters.Runtime_Traces then
1563 Send_Trace_Info (WT_Select,
1565 Integer (Open_Accepts'Length),
1569 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1570 Acceptor_Sleep, Timedout, Yielded);
1574 Self_Id.Open_Accepts := null;
1576 if Parameters.Runtime_Traces then
1577 Send_Trace_Info (E_Timeout);
1582 Self_Id.Common.State := Runnable;
1584 -- Self_Id.Common.Call should already be updated by the Caller if
1585 -- not aborted. It might also be ready to do rendezvous even if
1586 -- this wakes up due to an abort. Therefore, if the call is not
1587 -- empty we need to do the rendezvous if the accept body is not
1590 if Self_Id.Chosen_Index /= No_Rendezvous
1591 and then Self_Id.Common.Call /= null
1592 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1594 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1596 pragma Assert (Self_Id.Deferral_Level = 1);
1598 Initialization.Defer_Abort_Nestable (Self_Id);
1600 -- Leave abort deferred until the accept body
1603 STPO.Unlock (Self_Id);
1605 when No_Alternative_Open =>
1606 -- In this case, Index will be No_Rendezvous on return. We sleep
1607 -- for the time we need to.
1608 -- Wait for a signal or timeout. A wakeup can be made
1609 -- for several reasons:
1610 -- 1) Delay is expired
1611 -- 2) Pending_Action needs to be checked
1612 -- (Abort, Priority change)
1613 -- 3) Spurious wakeup
1615 Self_Id.Open_Accepts := null;
1616 Self_Id.Common.State := Acceptor_Sleep;
1618 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Sleep,
1621 Self_Id.Common.State := Runnable;
1623 STPO.Unlock (Self_Id);
1626 -- Should never get here
1627 pragma Assert (False);
1639 -- Caller has been chosen
1641 -- Self_Id.Common.Call should already be updated by the Caller
1643 -- Self_Id.Chosen_Index should either be updated by the Caller
1644 -- or by Test_Selective_Wait
1646 Index := Self_Id.Chosen_Index;
1647 Initialization.Undefer_Abort_Nestable (Self_Id);
1649 -- Start rendezvous, if not already completed
1650 end Timed_Selective_Wait;
1652 ---------------------------
1653 -- Timed_Task_Entry_Call --
1654 ---------------------------
1656 procedure Timed_Task_Entry_Call
1657 (Acceptor : Task_Id;
1658 E : Task_Entry_Index;
1659 Uninterpreted_Data : System.Address;
1662 Rendezvous_Successful : out Boolean)
1664 Self_Id : constant Task_Id := STPO.Self;
1666 Entry_Call : Entry_Call_Link;
1669 pragma Unreferenced (Yielded);
1672 -- If pragma Detect_Blocking is active then Program_Error must be
1673 -- raised if this potentially blocking operation is called from a
1674 -- protected action.
1676 if System.Tasking.Detect_Blocking
1677 and then Self_Id.Common.Protected_Action_Nesting > 0
1679 raise Program_Error with "potentially blocking operation";
1682 Initialization.Defer_Abort (Self_Id);
1683 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1686 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1687 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
1689 if Parameters.Runtime_Traces then
1690 Send_Trace_Info (WT_Call, Acceptor,
1691 Entry_Index (E), Timeout);
1694 Level := Self_Id.ATC_Nesting_Level;
1695 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1696 Entry_Call.Next := null;
1697 Entry_Call.Mode := Timed_Call;
1698 Entry_Call.Cancellation_Attempted := False;
1700 -- If this is a call made inside of an abort deferred region,
1701 -- the call should be never abortable.
1703 if Self_Id.Deferral_Level > 1 then
1704 Entry_Call.State := Never_Abortable;
1706 Entry_Call.State := Now_Abortable;
1709 Entry_Call.E := Entry_Index (E);
1710 Entry_Call.Prio := Get_Priority (Self_Id);
1711 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1712 Entry_Call.Called_Task := Acceptor;
1713 Entry_Call.Called_PO := Null_Address;
1714 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1715 Entry_Call.With_Abort := True;
1717 -- Note: the caller will undefer abort on return (see WARNING above)
1723 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1724 STPO.Write_Lock (Self_Id);
1725 Utilities.Exit_One_ATC_Level (Self_Id);
1726 STPO.Unlock (Self_Id);
1732 Initialization.Undefer_Abort (Self_Id);
1734 if Parameters.Runtime_Traces then
1735 Send_Trace_Info (E_Missed, Acceptor);
1737 raise Tasking_Error;
1740 Write_Lock (Self_Id);
1741 Entry_Calls.Wait_For_Completion_With_Timeout
1742 (Entry_Call, Timeout, Mode, Yielded);
1749 -- ??? Do we need to yield in case Yielded is False
1751 Rendezvous_Successful := Entry_Call.State = Done;
1752 Initialization.Undefer_Abort (Self_Id);
1753 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1754 end Timed_Task_Entry_Call;
1760 procedure Wait_For_Call (Self_Id : Task_Id) is
1762 Self_Id.Common.State := Acceptor_Sleep;
1764 -- Try to remove calls to Sleep in the loop below by letting the caller
1765 -- a chance of getting ready immediately, using Unlock & Yield.
1766 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1774 if Self_Id.Open_Accepts /= null then
1781 Write_Lock (Self_Id);
1784 -- Check if this task has been aborted while the lock was released
1786 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1787 Self_Id.Open_Accepts := null;
1791 exit when Self_Id.Open_Accepts = null;
1792 Sleep (Self_Id, Acceptor_Sleep);
1795 Self_Id.Common.State := Runnable;
1798 end System.Tasking.Rendezvous;