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-2007, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 with System.Task_Primitives.Operations;
35 -- used for Get_Priority
43 with System.Tasking.Entry_Calls;
44 -- Used for Wait_For_Completion
45 -- Wait_For_Completion_With_Timeout
46 -- Wait_Until_Abortable
48 with System.Tasking.Initialization;
49 -- used for Defer_Abort
53 with System.Tasking.Queuing;
56 -- Select_Task_Entry_Call
59 with System.Tasking.Utilities;
60 -- used for Check_Exception
62 -- Wakeup_Entry_Caller
65 with System.Tasking.Protected_Objects.Operations;
66 -- used for PO_Do_Or_Queue
70 with System.Tasking.Debug;
73 with System.Restrictions;
74 -- used for Abort_Allowed
76 with System.Parameters;
77 -- used for Single_Lock
80 with System.Traces.Tasking;
81 -- used for Send_Trace_Info
83 package body System.Tasking.Rendezvous is
85 package STPO renames System.Task_Primitives.Operations;
86 package POO renames Protected_Objects.Operations;
87 package POE renames Protected_Objects.Entries;
90 use Task_Primitives.Operations;
92 use System.Traces.Tasking;
94 type Select_Treatment is (
95 Accept_Alternative_Selected, -- alternative with non-null body
96 Accept_Alternative_Completed, -- alternative with null body
99 Accept_Alternative_Open,
100 No_Alternative_Open);
106 Default_Treatment : constant array (Select_Modes) of Select_Treatment :=
107 (Simple_Mode => No_Alternative_Open,
108 Else_Mode => Else_Selected,
109 Terminate_Mode => Terminate_Selected,
110 Delay_Mode => No_Alternative_Open);
112 New_State : constant array (Boolean, Entry_Call_State)
113 of Entry_Call_State :=
115 (Never_Abortable => Never_Abortable,
116 Not_Yet_Abortable => Now_Abortable,
117 Was_Abortable => Now_Abortable,
118 Now_Abortable => Now_Abortable,
120 Cancelled => Cancelled),
122 (Never_Abortable => Never_Abortable,
123 Not_Yet_Abortable => Not_Yet_Abortable,
124 Was_Abortable => Was_Abortable,
125 Now_Abortable => Now_Abortable,
127 Cancelled => Cancelled)
130 -----------------------
131 -- Local Subprograms --
132 -----------------------
134 procedure Local_Defer_Abort (Self_Id : Task_Id) renames
135 System.Tasking.Initialization.Defer_Abort_Nestable;
137 procedure Local_Undefer_Abort (Self_Id : Task_Id) renames
138 System.Tasking.Initialization.Undefer_Abort_Nestable;
140 -- Florist defers abort around critical sections that
141 -- make entry calls to the Interrupt_Manager task, which
142 -- violates the general rule about top-level runtime system
143 -- calls from abort-deferred regions. It is not that this is
144 -- unsafe, but when it occurs in "normal" programs it usually
145 -- means either the user is trying to do a potentially blocking
146 -- operation from within a protected object, or there is a
147 -- runtime system/compiler error that has failed to undefer
148 -- an earlier abort deferral. Thus, for debugging it may be
149 -- wise to modify the above renamings to the non-nestable forms.
151 procedure Boost_Priority (Call : Entry_Call_Link; Acceptor : Task_Id);
152 pragma Inline (Boost_Priority);
153 -- Call this only with abort deferred and holding lock of Acceptor
155 procedure Call_Synchronous
157 E : Task_Entry_Index;
158 Uninterpreted_Data : System.Address;
160 Rendezvous_Successful : out Boolean);
161 pragma Inline (Call_Synchronous);
162 -- This call is used to make a simple or conditional entry call.
163 -- Called from Call_Simple and Task_Entry_Call.
165 procedure Setup_For_Rendezvous_With_Body
166 (Entry_Call : Entry_Call_Link;
168 pragma Inline (Setup_For_Rendezvous_With_Body);
169 -- Call this only with abort deferred and holding lock of Acceptor.
170 -- When a rendezvous selected (ready for rendezvous) we need to save
171 -- previous caller and adjust the priority. Also we need to make
172 -- this call not Abortable (Cancellable) since the rendezvous has
173 -- already been started.
175 procedure Wait_For_Call (Self_Id : Task_Id);
176 pragma Inline (Wait_For_Call);
177 -- Call this only with abort deferred and holding lock of Self_Id.
178 -- An accepting task goes into Sleep by calling this routine
179 -- waiting for a call from the caller or waiting for an abort.
180 -- Make sure Self_Id is locked before calling this routine.
186 procedure Accept_Call
187 (E : Task_Entry_Index;
188 Uninterpreted_Data : out System.Address)
190 Self_Id : constant Task_Id := STPO.Self;
191 Caller : Task_Id := null;
192 Open_Accepts : aliased Accept_List (1 .. 1);
193 Entry_Call : Entry_Call_Link;
196 Initialization.Defer_Abort (Self_Id);
202 STPO.Write_Lock (Self_Id);
204 if not Self_Id.Callable then
205 pragma Assert (Self_Id.Pending_ATC_Level = 0);
207 pragma Assert (Self_Id.Pending_Action);
209 STPO.Unlock (Self_Id);
215 Initialization.Undefer_Abort (Self_Id);
217 -- Should never get here ???
219 pragma Assert (False);
220 raise Standard'Abort_Signal;
223 Queuing.Dequeue_Head (Self_Id.Entry_Queues (E), Entry_Call);
225 if Entry_Call /= null then
226 Caller := Entry_Call.Self;
227 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
228 Uninterpreted_Data := Entry_Call.Uninterpreted_Data;
233 Open_Accepts (1).Null_Body := False;
234 Open_Accepts (1).S := E;
235 Self_Id.Open_Accepts := Open_Accepts'Unrestricted_Access;
237 -- Wait for normal call
239 if Parameters.Runtime_Traces then
240 Send_Trace_Info (W_Accept, Self_Id, Integer (Open_Accepts'Length));
244 (Debug.Trace (Self_Id, "Accept_Call: wait", 'R'));
245 Wait_For_Call (Self_Id);
247 pragma Assert (Self_Id.Open_Accepts = null);
249 if Self_Id.Common.Call /= null then
250 Caller := Self_Id.Common.Call.Self;
251 Uninterpreted_Data :=
252 Caller.Entry_Calls (Caller.ATC_Nesting_Level).Uninterpreted_Data;
254 -- Case of an aborted task
256 Uninterpreted_Data := System.Null_Address;
260 -- Self_Id.Common.Call should already be updated by the Caller
261 -- On return, we will start the rendezvous.
263 STPO.Unlock (Self_Id);
269 Initialization.Undefer_Abort (Self_Id);
271 if Parameters.Runtime_Traces then
272 Send_Trace_Info (M_Accept_Complete, Caller, Entry_Index (E));
280 procedure Accept_Trivial (E : Task_Entry_Index) is
281 Self_Id : constant Task_Id := STPO.Self;
282 Caller : Task_Id := null;
283 Open_Accepts : aliased Accept_List (1 .. 1);
284 Entry_Call : Entry_Call_Link;
287 Initialization.Defer_Abort_Nestable (Self_Id);
293 STPO.Write_Lock (Self_Id);
295 if not Self_Id.Callable then
296 pragma Assert (Self_Id.Pending_ATC_Level = 0);
298 pragma Assert (Self_Id.Pending_Action);
300 STPO.Unlock (Self_Id);
306 Initialization.Undefer_Abort_Nestable (Self_Id);
308 -- Should never get here ???
310 pragma Assert (False);
311 raise Standard'Abort_Signal;
314 Queuing.Dequeue_Head (Self_Id.Entry_Queues (E), Entry_Call);
316 if Entry_Call = null then
317 -- Need to wait for entry call
319 Open_Accepts (1).Null_Body := True;
320 Open_Accepts (1).S := E;
321 Self_Id.Open_Accepts := Open_Accepts'Unrestricted_Access;
323 if Parameters.Runtime_Traces then
324 Send_Trace_Info (W_Accept, Self_Id, Integer (Open_Accepts'Length));
328 (Debug.Trace (Self_Id, "Accept_Trivial: wait", 'R'));
330 Wait_For_Call (Self_Id);
332 pragma Assert (Self_Id.Open_Accepts = null);
334 -- No need to do anything special here for pending abort.
335 -- Abort_Signal will be raised by Undefer on exit.
337 STPO.Unlock (Self_Id);
339 else -- found caller already waiting
340 pragma Assert (Entry_Call.State < Done);
342 STPO.Unlock (Self_Id);
343 Caller := Entry_Call.Self;
345 STPO.Write_Lock (Caller);
346 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
347 STPO.Unlock (Caller);
350 if Parameters.Runtime_Traces then
351 Send_Trace_Info (M_Accept_Complete);
353 -- Fake one, since there is (???) no way
354 -- to know that the rendezvous is over
356 Send_Trace_Info (M_RDV_Complete);
363 Initialization.Undefer_Abort_Nestable (Self_Id);
370 procedure Boost_Priority (Call : Entry_Call_Link; Acceptor : Task_Id) is
371 Caller : constant Task_Id := Call.Self;
372 Caller_Prio : constant System.Any_Priority := Get_Priority (Caller);
373 Acceptor_Prio : constant System.Any_Priority := Get_Priority (Acceptor);
376 if Caller_Prio > Acceptor_Prio then
377 Call.Acceptor_Prev_Priority := Acceptor_Prio;
378 Set_Priority (Acceptor, Caller_Prio);
381 Call.Acceptor_Prev_Priority := Priority_Not_Boosted;
389 procedure Call_Simple
391 E : Task_Entry_Index;
392 Uninterpreted_Data : System.Address)
394 Rendezvous_Successful : Boolean;
397 -- If pragma Detect_Blocking is active then Program_Error must be
398 -- raised if this potentially blocking operation is called from a
401 if System.Tasking.Detect_Blocking
402 and then STPO.Self.Common.Protected_Action_Nesting > 0
404 Ada.Exceptions.Raise_Exception
405 (Program_Error'Identity, "potentially blocking operation");
409 (Acceptor, E, Uninterpreted_Data, Simple_Call, Rendezvous_Successful);
412 ----------------------
413 -- Call_Synchronous --
414 ----------------------
416 procedure Call_Synchronous
418 E : Task_Entry_Index;
419 Uninterpreted_Data : System.Address;
421 Rendezvous_Successful : out Boolean)
423 Self_Id : constant Task_Id := STPO.Self;
425 Entry_Call : Entry_Call_Link;
428 pragma Assert (Mode /= Asynchronous_Call);
430 Local_Defer_Abort (Self_Id);
431 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
433 (Debug.Trace (Self_Id, "CS: entered ATC level: " &
434 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
435 Level := Self_Id.ATC_Nesting_Level;
436 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
437 Entry_Call.Next := null;
438 Entry_Call.Mode := Mode;
439 Entry_Call.Cancellation_Attempted := False;
441 if Parameters.Runtime_Traces then
442 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
445 -- If this is a call made inside of an abort deferred region,
446 -- the call should be never abortable.
448 if Self_Id.Deferral_Level > 1 then
449 Entry_Call.State := Never_Abortable;
451 Entry_Call.State := Now_Abortable;
454 Entry_Call.E := Entry_Index (E);
455 Entry_Call.Prio := Get_Priority (Self_Id);
456 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
457 Entry_Call.Called_Task := Acceptor;
458 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
459 Entry_Call.With_Abort := True;
461 -- Note: the caller will undefer abort on return (see WARNING above)
467 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
468 STPO.Write_Lock (Self_Id);
469 Utilities.Exit_One_ATC_Level (Self_Id);
470 STPO.Unlock (Self_Id);
476 if Parameters.Runtime_Traces then
477 Send_Trace_Info (E_Missed, Acceptor);
480 Local_Undefer_Abort (Self_Id);
484 STPO.Write_Lock (Self_Id);
486 (Debug.Trace (Self_Id, "Call_Synchronous: wait", 'R'));
487 Entry_Calls.Wait_For_Completion (Entry_Call);
489 (Debug.Trace (Self_Id, "Call_Synchronous: done waiting", 'R'));
490 Rendezvous_Successful := Entry_Call.State = Done;
491 STPO.Unlock (Self_Id);
497 Local_Undefer_Abort (Self_Id);
498 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
499 end Call_Synchronous;
505 function Callable (T : Task_Id) return Boolean is
507 Self_Id : constant Task_Id := STPO.Self;
510 Initialization.Defer_Abort_Nestable (Self_Id);
517 Result := T.Callable;
524 Initialization.Undefer_Abort_Nestable (Self_Id);
528 ----------------------------
529 -- Cancel_Task_Entry_Call --
530 ----------------------------
532 procedure Cancel_Task_Entry_Call (Cancelled : out Boolean) is
534 Entry_Calls.Try_To_Cancel_Entry_Call (Cancelled);
535 end Cancel_Task_Entry_Call;
537 -------------------------
538 -- Complete_Rendezvous --
539 -------------------------
541 procedure Complete_Rendezvous is
543 Exceptional_Complete_Rendezvous (Ada.Exceptions.Null_Id);
544 end Complete_Rendezvous;
546 -------------------------------------
547 -- Exceptional_Complete_Rendezvous --
548 -------------------------------------
550 procedure Exceptional_Complete_Rendezvous
551 (Ex : Ada.Exceptions.Exception_Id)
553 Self_Id : constant Task_Id := STPO.Self;
554 Entry_Call : Entry_Call_Link := Self_Id.Common.Call;
556 Called_PO : STPE.Protection_Entries_Access;
557 Acceptor_Prev_Priority : Integer;
559 Exception_To_Raise : Ada.Exceptions.Exception_Id := Ex;
560 Ceiling_Violation : Boolean;
562 use type Ada.Exceptions.Exception_Id;
563 procedure Internal_Reraise;
564 pragma Import (C, Internal_Reraise, "__gnat_reraise");
566 procedure Transfer_Occurrence
567 (Target : Ada.Exceptions.Exception_Occurrence_Access;
568 Source : Ada.Exceptions.Exception_Occurrence);
569 pragma Import (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
571 use type STPE.Protection_Entries_Access;
574 -- Consider phasing out Complete_Rendezvous in favor
575 -- of direct call to this with Ada.Exceptions.Null_ID.
576 -- See code expansion examples for Accept_Call and Selective_Wait.
577 -- Also consider putting an explicit re-raise after this call, in
578 -- the generated code. That way we could eliminate the
579 -- code here that reraises the exception.
581 -- The deferral level is critical here,
582 -- since we want to raise an exception or allow abort to take
583 -- place, if there is an exception or abort pending.
586 (Debug.Trace (Self_Id, "Exceptional_Complete_Rendezvous", 'R'));
588 if Ex = Ada.Exceptions.Null_Id then
589 -- The call came from normal end-of-rendezvous,
590 -- so abort is not yet deferred.
592 if Parameters.Runtime_Traces then
593 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
596 Initialization.Defer_Abort_Nestable (Self_Id);
599 -- We need to clean up any accepts which Self may have
600 -- been serving when it was aborted.
602 if Ex = Standard'Abort_Signal'Identity then
607 while Entry_Call /= null loop
608 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
610 -- All forms of accept make sure that the acceptor is not
611 -- completed, before accepting further calls, so that we
612 -- can be sure that no further calls are made after the
613 -- current calls are purged.
615 Caller := Entry_Call.Self;
617 -- Take write lock. This follows the lock precedence rule that
618 -- Caller may be locked while holding lock of Acceptor.
619 -- Complete the call abnormally, with exception.
621 STPO.Write_Lock (Caller);
622 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
623 STPO.Unlock (Caller);
624 Entry_Call := Entry_Call.Acceptor_Prev_Call;
632 Caller := Entry_Call.Self;
634 if Entry_Call.Needs_Requeue then
635 -- We dare not lock Self_Id at the same time as Caller,
636 -- for fear of deadlock.
638 Entry_Call.Needs_Requeue := False;
639 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
641 if Entry_Call.Called_Task /= null then
642 -- Requeue to another task entry
648 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
653 Initialization.Undefer_Abort (Self_Id);
662 -- Requeue to a protected entry
664 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
665 STPE.Lock_Entries (Called_PO, Ceiling_Violation);
667 if Ceiling_Violation then
668 pragma Assert (Ex = Ada.Exceptions.Null_Id);
670 Exception_To_Raise := Program_Error'Identity;
671 Entry_Call.Exception_To_Raise := Exception_To_Raise;
677 STPO.Write_Lock (Caller);
678 Initialization.Wakeup_Entry_Caller
679 (Self_Id, Entry_Call, Done);
680 STPO.Unlock (Caller);
687 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
688 POO.PO_Service_Entries (Self_Id, Called_PO);
692 Entry_Calls.Reset_Priority
693 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
696 -- The call does not need to be requeued
698 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
699 Entry_Call.Exception_To_Raise := Ex;
705 STPO.Write_Lock (Caller);
707 -- Done with Caller locked to make sure that Wakeup is not lost
709 if Ex /= Ada.Exceptions.Null_Id then
711 (Caller.Common.Compiler_Data.Current_Excep'Access,
712 Self_Id.Common.Compiler_Data.Current_Excep);
715 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
716 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
718 STPO.Unlock (Caller);
724 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
728 Initialization.Undefer_Abort (Self_Id);
730 if Exception_To_Raise /= Ada.Exceptions.Null_Id then
734 -- ??? Do we need to give precedence to Program_Error that might be
735 -- raised due to failure of finalization, over Tasking_Error from
736 -- failure of requeue?
737 end Exceptional_Complete_Rendezvous;
739 -------------------------------------
740 -- Requeue_Protected_To_Task_Entry --
741 -------------------------------------
743 procedure Requeue_Protected_To_Task_Entry
744 (Object : STPE.Protection_Entries_Access;
746 E : Task_Entry_Index;
747 With_Abort : Boolean)
749 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
751 pragma Assert (STPO.Self.Deferral_Level > 0);
753 Entry_Call.E := Entry_Index (E);
754 Entry_Call.Called_Task := Acceptor;
755 Entry_Call.Called_PO := Null_Address;
756 Entry_Call.With_Abort := With_Abort;
757 Object.Call_In_Progress := null;
758 end Requeue_Protected_To_Task_Entry;
760 ------------------------
761 -- Requeue_Task_Entry --
762 ------------------------
764 procedure Requeue_Task_Entry
766 E : Task_Entry_Index;
767 With_Abort : Boolean)
769 Self_Id : constant Task_Id := STPO.Self;
770 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
773 Initialization.Defer_Abort (Self_Id);
774 Entry_Call.Needs_Requeue := True;
775 Entry_Call.With_Abort := With_Abort;
776 Entry_Call.E := Entry_Index (E);
777 Entry_Call.Called_Task := Acceptor;
778 Initialization.Undefer_Abort (Self_Id);
779 end Requeue_Task_Entry;
785 procedure Selective_Wait
786 (Open_Accepts : Accept_List_Access;
787 Select_Mode : Select_Modes;
788 Uninterpreted_Data : out System.Address;
789 Index : out Select_Index)
791 Self_Id : constant Task_Id := STPO.Self;
792 Entry_Call : Entry_Call_Link;
793 Treatment : Select_Treatment;
795 Selection : Select_Index;
796 Open_Alternative : Boolean;
799 Initialization.Defer_Abort (Self_Id);
805 STPO.Write_Lock (Self_Id);
807 if not Self_Id.Callable then
808 pragma Assert (Self_Id.Pending_ATC_Level = 0);
810 pragma Assert (Self_Id.Pending_Action);
812 STPO.Unlock (Self_Id);
818 -- ??? In some cases abort is deferred more than once. Need to
819 -- figure out why this happens.
821 if Self_Id.Deferral_Level > 1 then
822 Self_Id.Deferral_Level := 1;
825 Initialization.Undefer_Abort (Self_Id);
827 -- Should never get here ???
829 pragma Assert (False);
830 raise Standard'Abort_Signal;
833 pragma Assert (Open_Accepts /= null);
835 Uninterpreted_Data := Null_Address;
837 Queuing.Select_Task_Entry_Call
838 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
840 -- Determine the kind and disposition of the select
842 Treatment := Default_Treatment (Select_Mode);
843 Self_Id.Chosen_Index := No_Rendezvous;
845 if Open_Alternative then
846 if Entry_Call /= null then
847 if Open_Accepts (Selection).Null_Body then
848 Treatment := Accept_Alternative_Completed;
850 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
851 Treatment := Accept_Alternative_Selected;
854 Self_Id.Chosen_Index := Selection;
856 elsif Treatment = No_Alternative_Open then
857 Treatment := Accept_Alternative_Open;
861 -- Handle the select according to the disposition selected above
864 when Accept_Alternative_Selected =>
865 -- Ready to rendezvous
867 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
869 -- In this case the accept body is not Null_Body. Defer abort
870 -- until it gets into the accept body.
872 pragma Assert (Self_Id.Deferral_Level = 1);
874 Initialization.Defer_Abort_Nestable (Self_Id);
875 STPO.Unlock (Self_Id);
877 when Accept_Alternative_Completed =>
879 -- Accept body is null, so rendezvous is over immediately
881 if Parameters.Runtime_Traces then
882 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
885 STPO.Unlock (Self_Id);
886 Caller := Entry_Call.Self;
888 STPO.Write_Lock (Caller);
889 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
890 STPO.Unlock (Caller);
892 when Accept_Alternative_Open =>
896 Self_Id.Open_Accepts := Open_Accepts;
898 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R'));
900 if Parameters.Runtime_Traces then
901 Send_Trace_Info (W_Select, Self_Id,
902 Integer (Open_Accepts'Length));
905 Wait_For_Call (Self_Id);
907 pragma Assert (Self_Id.Open_Accepts = null);
909 -- Self_Id.Common.Call should already be updated by the Caller if
910 -- not aborted. It might also be ready to do rendezvous even if
911 -- this wakes up due to an abort. Therefore, if the call is not
912 -- empty we need to do the rendezvous if the accept body is not
915 -- Aren't the first two conditions below redundant???
917 if Self_Id.Chosen_Index /= No_Rendezvous
918 and then Self_Id.Common.Call /= null
919 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
921 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
924 (Self_Id.Deferral_Level = 1
926 (Self_Id.Deferral_Level = 0
927 and then not Restrictions.Abort_Allowed));
929 Initialization.Defer_Abort_Nestable (Self_Id);
931 -- Leave abort deferred until the accept body
934 STPO.Unlock (Self_Id);
936 when Else_Selected =>
937 pragma Assert (Self_Id.Open_Accepts = null);
939 if Parameters.Runtime_Traces then
940 Send_Trace_Info (M_Select_Else);
943 STPO.Unlock (Self_Id);
945 when Terminate_Selected =>
946 -- Terminate alternative is open
948 Self_Id.Open_Accepts := Open_Accepts;
949 Self_Id.Common.State := Acceptor_Sleep;
951 -- Notify ancestors that this task is on a terminate alternative
953 STPO.Unlock (Self_Id);
954 Utilities.Make_Passive (Self_Id, Task_Completed => False);
955 STPO.Write_Lock (Self_Id);
957 -- Wait for normal entry call or termination
959 Wait_For_Call (Self_Id);
961 pragma Assert (Self_Id.Open_Accepts = null);
963 if Self_Id.Terminate_Alternative then
964 -- An entry call should have reset this to False,
965 -- so we must be aborted.
966 -- We cannot be in an async. select, since that
967 -- is not legal, so the abort must be of the entire
968 -- task. Therefore, we do not need to cancel the
969 -- terminate alternative. The cleanup will be done
970 -- in Complete_Master.
972 pragma Assert (Self_Id.Pending_ATC_Level = 0);
973 pragma Assert (Self_Id.Awake_Count = 0);
975 STPO.Unlock (Self_Id);
981 Index := Self_Id.Chosen_Index;
982 Initialization.Undefer_Abort_Nestable (Self_Id);
984 if Self_Id.Pending_Action then
985 Initialization.Do_Pending_Action (Self_Id);
991 -- Self_Id.Common.Call and Self_Id.Chosen_Index
992 -- should already be updated by the Caller.
994 if Self_Id.Chosen_Index /= No_Rendezvous
995 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
997 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
999 pragma Assert (Self_Id.Deferral_Level = 1);
1001 -- We need an extra defer here, to keep abort
1002 -- deferred until we get into the accept body
1004 Initialization.Defer_Abort_Nestable (Self_Id);
1008 STPO.Unlock (Self_Id);
1010 when No_Alternative_Open =>
1011 -- In this case, Index will be No_Rendezvous on return, which
1012 -- should cause a Program_Error if it is not a Delay_Mode.
1014 -- If delay alternative exists (Delay_Mode) we should suspend
1015 -- until the delay expires.
1017 Self_Id.Open_Accepts := null;
1019 if Select_Mode = Delay_Mode then
1020 Self_Id.Common.State := Delay_Sleep;
1024 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
1025 Sleep (Self_Id, Delay_Sleep);
1028 Self_Id.Common.State := Runnable;
1029 STPO.Unlock (Self_Id);
1032 STPO.Unlock (Self_Id);
1038 Initialization.Undefer_Abort (Self_Id);
1039 Ada.Exceptions.Raise_Exception
1040 (Program_Error'Identity, "Entry call not a delay mode");
1048 -- Caller has been chosen.
1049 -- Self_Id.Common.Call should already be updated by the Caller.
1050 -- Self_Id.Chosen_Index should either be updated by the Caller
1051 -- or by Test_Selective_Wait.
1052 -- On return, we sill start rendezvous unless the accept body is
1053 -- null. In the latter case, we will have already completed the RV.
1055 Index := Self_Id.Chosen_Index;
1056 Initialization.Undefer_Abort_Nestable (Self_Id);
1059 ------------------------------------
1060 -- Setup_For_Rendezvous_With_Body --
1061 ------------------------------------
1063 procedure Setup_For_Rendezvous_With_Body
1064 (Entry_Call : Entry_Call_Link;
1065 Acceptor : Task_Id) is
1067 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1068 Acceptor.Common.Call := Entry_Call;
1070 if Entry_Call.State = Now_Abortable then
1071 Entry_Call.State := Was_Abortable;
1074 Boost_Priority (Entry_Call, Acceptor);
1075 end Setup_For_Rendezvous_With_Body;
1081 function Task_Count (E : Task_Entry_Index) return Natural is
1082 Self_Id : constant Task_Id := STPO.Self;
1083 Return_Count : Natural;
1086 Initialization.Defer_Abort (Self_Id);
1092 STPO.Write_Lock (Self_Id);
1093 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1094 STPO.Unlock (Self_Id);
1100 Initialization.Undefer_Abort (Self_Id);
1102 -- Call Yield to let other tasks get a chance to run as this is a
1103 -- potential dispatching point.
1105 Yield (Do_Yield => False);
1106 return Return_Count;
1109 ----------------------
1110 -- Task_Do_Or_Queue --
1111 ----------------------
1113 function Task_Do_Or_Queue
1115 Entry_Call : Entry_Call_Link) return Boolean
1117 E : constant Task_Entry_Index :=
1118 Task_Entry_Index (Entry_Call.E);
1119 Old_State : constant Entry_Call_State := Entry_Call.State;
1120 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1121 Parent : constant Task_Id := Acceptor.Common.Parent;
1122 Parent_Locked : Boolean := False;
1123 Null_Body : Boolean;
1126 -- Find out whether Entry_Call can be accepted immediately
1128 -- If the Acceptor is not callable, return False.
1129 -- If the rendezvous can start, initiate it.
1130 -- If the accept-body is trivial, also complete the rendezvous.
1131 -- If the acceptor is not ready, enqueue the call.
1133 -- This should have a special case for Accept_Call and Accept_Trivial,
1134 -- so that we don't have the loop setup overhead, below.
1136 -- The call state Done is used here and elsewhere to include both the
1137 -- case of normal successful completion, and the case of an exception
1138 -- being raised. The difference is that if an exception is raised no one
1139 -- will pay attention to the fact that State = Done. Instead the
1140 -- exception will be raised in Undefer_Abort, and control will skip past
1141 -- the place where we normally would resume from an entry call.
1143 pragma Assert (not Queuing.Onqueue (Entry_Call));
1145 -- We rely that the call is off-queue for protection, that the caller
1146 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1147 -- record for another call.
1148 -- We rely on the Caller's lock for call State mod's.
1150 -- We can't lock Acceptor.Parent while holding Acceptor,
1151 -- so lock it in advance if we expect to need to lock it.
1153 if Acceptor.Terminate_Alternative then
1154 STPO.Write_Lock (Parent);
1155 Parent_Locked := True;
1158 STPO.Write_Lock (Acceptor);
1160 -- If the acceptor is not callable, abort the call and return False
1162 if not Acceptor.Callable then
1163 STPO.Unlock (Acceptor);
1165 if Parent_Locked then
1166 STPO.Unlock (Parent);
1169 pragma Assert (Entry_Call.State < Done);
1171 -- In case we are not the caller, set up the caller
1172 -- to raise Tasking_Error when it wakes up.
1174 STPO.Write_Lock (Entry_Call.Self);
1175 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1176 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1177 STPO.Unlock (Entry_Call.Self);
1182 -- Try to serve the call immediately
1184 if Acceptor.Open_Accepts /= null then
1185 for J in Acceptor.Open_Accepts'Range loop
1186 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1188 -- Commit acceptor to rendezvous with us
1190 Acceptor.Chosen_Index := J;
1191 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1192 Acceptor.Open_Accepts := null;
1194 -- Prevent abort while call is being served
1196 if Entry_Call.State = Now_Abortable then
1197 Entry_Call.State := Was_Abortable;
1200 if Acceptor.Terminate_Alternative then
1202 -- Cancel terminate alternative. See matching code in
1203 -- Selective_Wait and Vulnerable_Complete_Master.
1205 Acceptor.Terminate_Alternative := False;
1206 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1208 if Acceptor.Awake_Count = 1 then
1210 -- Notify parent that acceptor is awake
1212 pragma Assert (Parent.Awake_Count > 0);
1214 Parent.Awake_Count := Parent.Awake_Count + 1;
1216 if Parent.Common.State = Master_Completion_Sleep
1217 and then Acceptor.Master_of_Task = Parent.Master_Within
1219 Parent.Common.Wait_Count :=
1220 Parent.Common.Wait_Count + 1;
1227 -- Rendezvous is over immediately
1229 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1230 STPO.Unlock (Acceptor);
1232 if Parent_Locked then
1233 STPO.Unlock (Parent);
1236 STPO.Write_Lock (Entry_Call.Self);
1237 Initialization.Wakeup_Entry_Caller
1238 (Self_ID, Entry_Call, Done);
1239 STPO.Unlock (Entry_Call.Self);
1242 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1244 -- For terminate_alternative, acceptor may not be asleep
1245 -- yet, so we skip the wakeup
1247 if Acceptor.Common.State /= Runnable then
1248 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1251 STPO.Unlock (Acceptor);
1253 if Parent_Locked then
1254 STPO.Unlock (Parent);
1262 -- The acceptor is accepting, but not this entry
1265 -- If the acceptor was ready to accept this call,
1266 -- we would not have gotten this far, so now we should
1267 -- (re)enqueue the call, if the mode permits that.
1269 if Entry_Call.Mode /= Conditional_Call
1270 or else not Entry_Call.With_Abort
1272 -- Timed_Call, Simple_Call, or Asynchronous_Call
1274 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1276 -- Update abortability of call
1278 pragma Assert (Old_State < Done);
1281 New_State (Entry_Call.With_Abort, Entry_Call.State);
1283 STPO.Unlock (Acceptor);
1285 if Parent_Locked then
1286 STPO.Unlock (Parent);
1289 if Old_State /= Entry_Call.State
1290 and then Entry_Call.State = Now_Abortable
1291 and then Entry_Call.Mode > Simple_Call
1292 and then Entry_Call.Self /= Self_ID
1294 -- Asynchronous_Call or Conditional_Call
1297 -- Because of ATCB lock ordering rule
1299 STPO.Write_Lock (Entry_Call.Self);
1301 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1303 -- Caller may not yet have reached wait-point
1305 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1308 STPO.Unlock (Entry_Call.Self);
1312 -- Conditional_Call and With_Abort
1314 STPO.Unlock (Acceptor);
1316 if Parent_Locked then
1317 STPO.Unlock (Parent);
1320 STPO.Write_Lock (Entry_Call.Self);
1322 pragma Assert (Entry_Call.State >= Was_Abortable);
1324 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1325 STPO.Unlock (Entry_Call.Self);
1329 end Task_Do_Or_Queue;
1331 ---------------------
1332 -- Task_Entry_Call --
1333 ---------------------
1335 procedure Task_Entry_Call
1336 (Acceptor : Task_Id;
1337 E : Task_Entry_Index;
1338 Uninterpreted_Data : System.Address;
1340 Rendezvous_Successful : out Boolean)
1342 Self_Id : constant Task_Id := STPO.Self;
1343 Entry_Call : Entry_Call_Link;
1346 -- If pragma Detect_Blocking is active then Program_Error must be
1347 -- raised if this potentially blocking operation is called from a
1348 -- protected action.
1350 if System.Tasking.Detect_Blocking
1351 and then Self_Id.Common.Protected_Action_Nesting > 0
1353 Ada.Exceptions.Raise_Exception
1354 (Program_Error'Identity, "potentially blocking operation");
1357 if Parameters.Runtime_Traces then
1358 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1361 if Mode = Simple_Call or else Mode = Conditional_Call then
1363 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1366 -- This is an asynchronous call
1368 -- Abort must already be deferred by the compiler-generated code.
1369 -- Without this, an abort that occurs between the time that this
1370 -- call is made and the time that the abortable part's cleanup
1371 -- handler is set up might miss the cleanup handler and leave the
1374 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1376 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1377 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
1378 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1379 Entry_Call.Next := null;
1380 Entry_Call.Mode := Mode;
1381 Entry_Call.Cancellation_Attempted := False;
1382 Entry_Call.State := Not_Yet_Abortable;
1383 Entry_Call.E := Entry_Index (E);
1384 Entry_Call.Prio := Get_Priority (Self_Id);
1385 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1386 Entry_Call.Called_Task := Acceptor;
1387 Entry_Call.Called_PO := Null_Address;
1388 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1389 Entry_Call.With_Abort := True;
1395 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1396 STPO.Write_Lock (Self_Id);
1397 Utilities.Exit_One_ATC_Level (Self_Id);
1398 STPO.Unlock (Self_Id);
1404 Initialization.Undefer_Abort (Self_Id);
1406 if Parameters.Runtime_Traces then
1407 Send_Trace_Info (E_Missed, Acceptor);
1410 raise Tasking_Error;
1413 -- The following is special for async. entry calls.
1414 -- If the call was not queued abortably, we need to wait until
1415 -- it is before proceeding with the abortable part.
1417 -- Wait_Until_Abortable can be called unconditionally here,
1418 -- but it is expensive.
1420 if Entry_Call.State < Was_Abortable then
1421 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1428 -- Note: following assignment needs to be atomic
1430 Rendezvous_Successful := Entry_Call.State = Done;
1432 end Task_Entry_Call;
1434 -----------------------
1435 -- Task_Entry_Caller --
1436 -----------------------
1438 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1439 Self_Id : constant Task_Id := STPO.Self;
1440 Entry_Call : Entry_Call_Link;
1443 Entry_Call := Self_Id.Common.Call;
1445 for Depth in 1 .. D loop
1446 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1447 pragma Assert (Entry_Call /= null);
1450 return Entry_Call.Self;
1451 end Task_Entry_Caller;
1453 --------------------------
1454 -- Timed_Selective_Wait --
1455 --------------------------
1457 procedure Timed_Selective_Wait
1458 (Open_Accepts : Accept_List_Access;
1459 Select_Mode : Select_Modes;
1460 Uninterpreted_Data : out System.Address;
1463 Index : out Select_Index)
1465 Self_Id : constant Task_Id := STPO.Self;
1466 Treatment : Select_Treatment;
1467 Entry_Call : Entry_Call_Link;
1469 Selection : Select_Index;
1470 Open_Alternative : Boolean;
1471 Timedout : Boolean := False;
1472 Yielded : Boolean := True;
1475 pragma Assert (Select_Mode = Delay_Mode);
1477 Initialization.Defer_Abort (Self_Id);
1479 -- If we are aborted here, the effect will be pending
1485 STPO.Write_Lock (Self_Id);
1487 if not Self_Id.Callable then
1488 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1490 pragma Assert (Self_Id.Pending_Action);
1492 STPO.Unlock (Self_Id);
1498 Initialization.Undefer_Abort (Self_Id);
1500 -- Should never get here ???
1502 pragma Assert (False);
1503 raise Standard'Abort_Signal;
1506 Uninterpreted_Data := Null_Address;
1508 pragma Assert (Open_Accepts /= null);
1510 Queuing.Select_Task_Entry_Call
1511 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1513 -- Determine the kind and disposition of the select
1515 Treatment := Default_Treatment (Select_Mode);
1516 Self_Id.Chosen_Index := No_Rendezvous;
1518 if Open_Alternative then
1519 if Entry_Call /= null then
1520 if Open_Accepts (Selection).Null_Body then
1521 Treatment := Accept_Alternative_Completed;
1524 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1525 Treatment := Accept_Alternative_Selected;
1528 Self_Id.Chosen_Index := Selection;
1530 elsif Treatment = No_Alternative_Open then
1531 Treatment := Accept_Alternative_Open;
1535 -- Handle the select according to the disposition selected above
1538 when Accept_Alternative_Selected =>
1539 -- Ready to rendezvous
1540 -- In this case the accept body is not Null_Body. Defer abort
1541 -- until it gets into the accept body.
1543 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1544 Initialization.Defer_Abort (Self_Id);
1545 STPO.Unlock (Self_Id);
1547 when Accept_Alternative_Completed =>
1548 -- Rendezvous is over
1550 if Parameters.Runtime_Traces then
1551 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1554 STPO.Unlock (Self_Id);
1555 Caller := Entry_Call.Self;
1557 STPO.Write_Lock (Caller);
1558 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1559 STPO.Unlock (Caller);
1561 when Accept_Alternative_Open =>
1565 Self_Id.Open_Accepts := Open_Accepts;
1567 -- Wait for a normal call and a pending action until the
1568 -- Wakeup_Time is reached.
1570 Self_Id.Common.State := Acceptor_Sleep;
1572 -- Try to remove calls to Sleep in the loop below by letting the
1573 -- caller a chance of getting ready immediately, using Unlock
1574 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1582 if Self_Id.Open_Accepts /= null then
1589 Write_Lock (Self_Id);
1592 -- Check if this task has been aborted while the lock was released
1594 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1595 Self_Id.Open_Accepts := null;
1599 exit when Self_Id.Open_Accepts = null;
1602 Sleep (Self_Id, Acceptor_Sleep);
1604 if Parameters.Runtime_Traces then
1605 Send_Trace_Info (WT_Select,
1607 Integer (Open_Accepts'Length),
1611 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1612 Acceptor_Sleep, Timedout, Yielded);
1616 Self_Id.Open_Accepts := null;
1618 if Parameters.Runtime_Traces then
1619 Send_Trace_Info (E_Timeout);
1624 Self_Id.Common.State := Runnable;
1626 -- Self_Id.Common.Call should already be updated by the Caller if
1627 -- not aborted. It might also be ready to do rendezvous even if
1628 -- this wakes up due to an abort. Therefore, if the call is not
1629 -- empty we need to do the rendezvous if the accept body is not
1632 if Self_Id.Chosen_Index /= No_Rendezvous
1633 and then Self_Id.Common.Call /= null
1634 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1636 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1638 pragma Assert (Self_Id.Deferral_Level = 1);
1640 Initialization.Defer_Abort_Nestable (Self_Id);
1642 -- Leave abort deferred until the accept body
1645 STPO.Unlock (Self_Id);
1647 when No_Alternative_Open =>
1648 -- In this case, Index will be No_Rendezvous on return. We sleep
1649 -- for the time we need to.
1650 -- Wait for a signal or timeout. A wakeup can be made
1651 -- for several reasons:
1652 -- 1) Delay is expired
1653 -- 2) Pending_Action needs to be checked
1654 -- (Abort, Priority change)
1655 -- 3) Spurious wakeup
1657 Self_Id.Open_Accepts := null;
1658 Self_Id.Common.State := Acceptor_Sleep;
1660 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Sleep,
1663 Self_Id.Common.State := Runnable;
1665 STPO.Unlock (Self_Id);
1668 -- Should never get here
1669 pragma Assert (False);
1681 -- Caller has been chosen
1683 -- Self_Id.Common.Call should already be updated by the Caller
1685 -- Self_Id.Chosen_Index should either be updated by the Caller
1686 -- or by Test_Selective_Wait
1688 Index := Self_Id.Chosen_Index;
1689 Initialization.Undefer_Abort_Nestable (Self_Id);
1691 -- Start rendezvous, if not already completed
1692 end Timed_Selective_Wait;
1694 ---------------------------
1695 -- Timed_Task_Entry_Call --
1696 ---------------------------
1698 procedure Timed_Task_Entry_Call
1699 (Acceptor : Task_Id;
1700 E : Task_Entry_Index;
1701 Uninterpreted_Data : System.Address;
1704 Rendezvous_Successful : out Boolean)
1706 Self_Id : constant Task_Id := STPO.Self;
1708 Entry_Call : Entry_Call_Link;
1712 -- If pragma Detect_Blocking is active then Program_Error must be
1713 -- raised if this potentially blocking operation is called from a
1714 -- protected action.
1716 if System.Tasking.Detect_Blocking
1717 and then Self_Id.Common.Protected_Action_Nesting > 0
1719 Ada.Exceptions.Raise_Exception
1720 (Program_Error'Identity, "potentially blocking operation");
1723 Initialization.Defer_Abort (Self_Id);
1724 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1727 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1728 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A'));
1730 if Parameters.Runtime_Traces then
1731 Send_Trace_Info (WT_Call, Acceptor,
1732 Entry_Index (E), Timeout);
1735 Level := Self_Id.ATC_Nesting_Level;
1736 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1737 Entry_Call.Next := null;
1738 Entry_Call.Mode := Timed_Call;
1739 Entry_Call.Cancellation_Attempted := False;
1741 -- If this is a call made inside of an abort deferred region,
1742 -- the call should be never abortable.
1744 if Self_Id.Deferral_Level > 1 then
1745 Entry_Call.State := Never_Abortable;
1747 Entry_Call.State := Now_Abortable;
1750 Entry_Call.E := Entry_Index (E);
1751 Entry_Call.Prio := Get_Priority (Self_Id);
1752 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1753 Entry_Call.Called_Task := Acceptor;
1754 Entry_Call.Called_PO := Null_Address;
1755 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1756 Entry_Call.With_Abort := True;
1758 -- Note: the caller will undefer abort on return (see WARNING above)
1764 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1765 STPO.Write_Lock (Self_Id);
1766 Utilities.Exit_One_ATC_Level (Self_Id);
1767 STPO.Unlock (Self_Id);
1773 Initialization.Undefer_Abort (Self_Id);
1775 if Parameters.Runtime_Traces then
1776 Send_Trace_Info (E_Missed, Acceptor);
1778 raise Tasking_Error;
1781 Write_Lock (Self_Id);
1782 Entry_Calls.Wait_For_Completion_With_Timeout
1783 (Entry_Call, Timeout, Mode, Yielded);
1790 -- ??? Do we need to yield in case Yielded is False
1792 Rendezvous_Successful := Entry_Call.State = Done;
1793 Initialization.Undefer_Abort (Self_Id);
1794 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1795 end Timed_Task_Entry_Call;
1801 procedure Wait_For_Call (Self_Id : Task_Id) is
1803 Self_Id.Common.State := Acceptor_Sleep;
1805 -- Try to remove calls to Sleep in the loop below by letting the caller
1806 -- a chance of getting ready immediately, using Unlock & Yield.
1807 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1815 if Self_Id.Open_Accepts /= null then
1822 Write_Lock (Self_Id);
1825 -- Check if this task has been aborted while the lock was released
1827 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1828 Self_Id.Open_Accepts := null;
1832 exit when Self_Id.Open_Accepts = null;
1833 Sleep (Self_Id, Acceptor_Sleep);
1836 Self_Id.Common.State := Runnable;
1839 end System.Tasking.Rendezvous;