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-2017, 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 make entry calls
101 -- to the Interrupt_Manager task, which violates the general rule about
102 -- top-level runtime system calls from abort-deferred regions. It is not
103 -- that this is unsafe, but when it occurs in "normal" programs it usually
104 -- means either the user is trying to do a potentially blocking operation
105 -- from within a protected object, or there is a runtime system/compiler
106 -- error that has failed to undefer an earlier abort deferral. Thus, for
107 -- debugging it may be wise to modify the above renamings to the
108 -- non-nestable forms.
110 procedure Local_Complete_Rendezvous
(Ex
: Ada
.Exceptions
.Exception_Id
);
111 -- Internal version of Complete_Rendezvous, used to implement
112 -- Complete_Rendezvous and Exceptional_Complete_Rendezvous.
113 -- Should be called holding no locks, generally with abort
116 procedure Boost_Priority
(Call
: Entry_Call_Link
; Acceptor
: Task_Id
);
117 pragma Inline
(Boost_Priority
);
118 -- Call this only with abort deferred and holding lock of Acceptor
120 procedure Call_Synchronous
122 E
: Task_Entry_Index
;
123 Uninterpreted_Data
: System
.Address
;
125 Rendezvous_Successful
: out Boolean);
126 pragma Inline
(Call_Synchronous
);
127 -- This call is used to make a simple or conditional entry call.
128 -- Called from Call_Simple and Task_Entry_Call.
130 procedure Setup_For_Rendezvous_With_Body
131 (Entry_Call
: Entry_Call_Link
;
133 pragma Inline
(Setup_For_Rendezvous_With_Body
);
134 -- Call this only with abort deferred and holding lock of Acceptor. When
135 -- a rendezvous selected (ready for rendezvous) we need to save previous
136 -- caller and adjust the priority. Also we need to make this call not
137 -- Abortable (Cancellable) since the rendezvous has already been started.
139 procedure Wait_For_Call
(Self_Id
: Task_Id
);
140 pragma Inline
(Wait_For_Call
);
141 -- Call this only with abort deferred and holding lock of Self_Id. An
142 -- accepting task goes into Sleep by calling this routine waiting for a
143 -- call from the caller or waiting for an abort. Make sure Self_Id is
144 -- locked before calling this routine.
150 procedure Accept_Call
151 (E
: Task_Entry_Index
;
152 Uninterpreted_Data
: out System
.Address
)
154 Self_Id
: constant Task_Id
:= STPO
.Self
;
155 Caller
: Task_Id
:= null;
156 Open_Accepts
: aliased Accept_List
(1 .. 1);
157 Entry_Call
: Entry_Call_Link
;
160 Initialization
.Defer_Abort
(Self_Id
);
166 STPO
.Write_Lock
(Self_Id
);
168 if not Self_Id
.Callable
then
169 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
171 pragma Assert
(Self_Id
.Pending_Action
);
173 STPO
.Unlock
(Self_Id
);
179 Initialization
.Undefer_Abort
(Self_Id
);
181 -- Should never get here ???
183 pragma Assert
(False);
184 raise Standard
'Abort_Signal;
187 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
189 if Entry_Call
/= null then
190 Caller
:= Entry_Call
.Self
;
191 Setup_For_Rendezvous_With_Body
(Entry_Call
, Self_Id
);
192 Uninterpreted_Data
:= Entry_Call
.Uninterpreted_Data
;
197 Open_Accepts
(1).Null_Body
:= False;
198 Open_Accepts
(1).S
:= E
;
199 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
201 -- Wait for normal call
203 if Parameters
.Runtime_Traces
then
204 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
208 (Debug
.Trace
(Self_Id
, "Accept_Call: wait", 'R'));
209 Wait_For_Call
(Self_Id
);
211 pragma Assert
(Self_Id
.Open_Accepts
= null);
213 if Self_Id
.Common
.Call
/= null then
214 Caller
:= Self_Id
.Common
.Call
.Self
;
215 Uninterpreted_Data
:=
216 Caller
.Entry_Calls
(Caller
.ATC_Nesting_Level
).Uninterpreted_Data
;
218 -- Case of an aborted task
220 Uninterpreted_Data
:= System
.Null_Address
;
224 -- Self_Id.Common.Call should already be updated by the Caller. On
225 -- return, we will start the rendezvous.
227 STPO
.Unlock
(Self_Id
);
233 Initialization
.Undefer_Abort
(Self_Id
);
235 if Parameters
.Runtime_Traces
then
236 Send_Trace_Info
(M_Accept_Complete
, Caller
, Entry_Index
(E
));
244 procedure Accept_Trivial
(E
: Task_Entry_Index
) is
245 Self_Id
: constant Task_Id
:= STPO
.Self
;
246 Caller
: Task_Id
:= null;
247 Open_Accepts
: aliased Accept_List
(1 .. 1);
248 Entry_Call
: Entry_Call_Link
;
251 Initialization
.Defer_Abort_Nestable
(Self_Id
);
257 STPO
.Write_Lock
(Self_Id
);
259 if not Self_Id
.Callable
then
260 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
262 pragma Assert
(Self_Id
.Pending_Action
);
264 STPO
.Unlock
(Self_Id
);
270 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
272 -- Should never get here ???
274 pragma Assert
(False);
275 raise Standard
'Abort_Signal;
278 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
280 if Entry_Call
= null then
282 -- Need to wait for entry call
284 Open_Accepts
(1).Null_Body
:= True;
285 Open_Accepts
(1).S
:= E
;
286 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
288 if Parameters
.Runtime_Traces
then
289 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
293 (Debug
.Trace
(Self_Id
, "Accept_Trivial: wait", 'R'));
295 Wait_For_Call
(Self_Id
);
297 pragma Assert
(Self_Id
.Open_Accepts
= null);
299 -- No need to do anything special here for pending abort.
300 -- Abort_Signal will be raised by Undefer on exit.
302 STPO
.Unlock
(Self_Id
);
304 -- Found caller already waiting
307 pragma Assert
(Entry_Call
.State
< Done
);
309 STPO
.Unlock
(Self_Id
);
310 Caller
:= Entry_Call
.Self
;
312 STPO
.Write_Lock
(Caller
);
313 Initialization
.Wakeup_Entry_Caller
(Self_Id
, Entry_Call
, Done
);
314 STPO
.Unlock
(Caller
);
317 if Parameters
.Runtime_Traces
then
318 Send_Trace_Info
(M_Accept_Complete
);
320 -- Fake one, since there is (???) no way to know that the rendezvous
323 Send_Trace_Info
(M_RDV_Complete
);
330 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
337 procedure Boost_Priority
(Call
: Entry_Call_Link
; Acceptor
: Task_Id
) is
338 Caller
: constant Task_Id
:= Call
.Self
;
339 Caller_Prio
: constant System
.Any_Priority
:= Get_Priority
(Caller
);
340 Acceptor_Prio
: constant System
.Any_Priority
:= Get_Priority
(Acceptor
);
342 if Caller_Prio
> Acceptor_Prio
then
343 Call
.Acceptor_Prev_Priority
:= Acceptor_Prio
;
344 Set_Priority
(Acceptor
, Caller_Prio
);
346 Call
.Acceptor_Prev_Priority
:= Priority_Not_Boosted
;
354 procedure Call_Simple
356 E
: Task_Entry_Index
;
357 Uninterpreted_Data
: System
.Address
)
359 Rendezvous_Successful
: Boolean;
360 pragma Unreferenced
(Rendezvous_Successful
);
363 -- If pragma Detect_Blocking is active then Program_Error must be
364 -- raised if this potentially blocking operation is called from a
367 if System
.Tasking
.Detect_Blocking
368 and then STPO
.Self
.Common
.Protected_Action_Nesting
> 0
370 raise Program_Error
with
371 "potentially blocking operation";
375 (Acceptor
, E
, Uninterpreted_Data
, Simple_Call
, Rendezvous_Successful
);
378 ----------------------
379 -- Call_Synchronous --
380 ----------------------
382 procedure Call_Synchronous
384 E
: Task_Entry_Index
;
385 Uninterpreted_Data
: System
.Address
;
387 Rendezvous_Successful
: out Boolean)
389 Self_Id
: constant Task_Id
:= STPO
.Self
;
391 Entry_Call
: Entry_Call_Link
;
394 pragma Assert
(Mode
/= Asynchronous_Call
);
396 Local_Defer_Abort
(Self_Id
);
397 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
+ 1;
399 (Debug
.Trace
(Self_Id
, "CS: entered ATC level: " &
400 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
401 Level
:= Self_Id
.ATC_Nesting_Level
;
402 Entry_Call
:= Self_Id
.Entry_Calls
(Level
)'Access;
403 Entry_Call
.Next
:= null;
404 Entry_Call
.Mode
:= Mode
;
405 Entry_Call
.Cancellation_Attempted
:= False;
407 if Parameters
.Runtime_Traces
then
408 Send_Trace_Info
(W_Call
, Acceptor
, Entry_Index
(E
));
411 -- If this is a call made inside of an abort deferred region,
412 -- the call should be never abortable.
415 (if Self_Id
.Deferral_Level
> 1
419 Entry_Call
.E
:= Entry_Index
(E
);
420 Entry_Call
.Prio
:= Get_Priority
(Self_Id
);
421 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
422 Entry_Call
.Called_Task
:= Acceptor
;
423 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
424 Entry_Call
.With_Abort
:= True;
426 -- Note: the caller will undefer abort on return (see WARNING above)
432 if not Task_Do_Or_Queue
(Self_Id
, Entry_Call
) then
433 STPO
.Write_Lock
(Self_Id
);
434 Utilities
.Exit_One_ATC_Level
(Self_Id
);
435 STPO
.Unlock
(Self_Id
);
441 if Parameters
.Runtime_Traces
then
442 Send_Trace_Info
(E_Missed
, Acceptor
);
445 Local_Undefer_Abort
(Self_Id
);
449 STPO
.Write_Lock
(Self_Id
);
451 (Debug
.Trace
(Self_Id
, "Call_Synchronous: wait", 'R'));
452 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
454 (Debug
.Trace
(Self_Id
, "Call_Synchronous: done waiting", 'R'));
455 Rendezvous_Successful
:= Entry_Call
.State
= Done
;
456 STPO
.Unlock
(Self_Id
);
462 Local_Undefer_Abort
(Self_Id
);
463 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
464 end Call_Synchronous
;
470 function Callable
(T
: Task_Id
) return Boolean is
472 Self_Id
: constant Task_Id
:= STPO
.Self
;
475 Initialization
.Defer_Abort_Nestable
(Self_Id
);
482 Result
:= T
.Callable
;
489 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
493 ----------------------------
494 -- Cancel_Task_Entry_Call --
495 ----------------------------
497 procedure Cancel_Task_Entry_Call
(Cancelled
: out Boolean) is
499 Entry_Calls
.Try_To_Cancel_Entry_Call
(Cancelled
);
500 end Cancel_Task_Entry_Call
;
502 -------------------------
503 -- Complete_Rendezvous --
504 -------------------------
506 procedure Complete_Rendezvous
is
508 Local_Complete_Rendezvous
(Ada
.Exceptions
.Null_Id
);
509 end Complete_Rendezvous
;
511 -------------------------------------
512 -- Exceptional_Complete_Rendezvous --
513 -------------------------------------
515 procedure Exceptional_Complete_Rendezvous
516 (Ex
: Ada
.Exceptions
.Exception_Id
)
518 procedure Internal_Reraise
;
519 pragma No_Return
(Internal_Reraise
);
520 pragma Import
(C
, Internal_Reraise
, "__gnat_reraise");
523 Local_Complete_Rendezvous
(Ex
);
526 -- ??? Do we need to give precedence to Program_Error that might be
527 -- raised due to failure of finalization, over Tasking_Error from
528 -- failure of requeue?
529 end Exceptional_Complete_Rendezvous
;
531 -------------------------------
532 -- Local_Complete_Rendezvous --
533 -------------------------------
535 procedure Local_Complete_Rendezvous
(Ex
: Ada
.Exceptions
.Exception_Id
) is
536 Self_Id
: constant Task_Id
:= STPO
.Self
;
537 Entry_Call
: Entry_Call_Link
:= Self_Id
.Common
.Call
;
539 Called_PO
: STPE
.Protection_Entries_Access
;
540 Acceptor_Prev_Priority
: Integer;
542 Ceiling_Violation
: Boolean;
544 use type Ada
.Exceptions
.Exception_Id
;
545 procedure Transfer_Occurrence
546 (Target
: Ada
.Exceptions
.Exception_Occurrence_Access
;
547 Source
: Ada
.Exceptions
.Exception_Occurrence
);
548 pragma Import
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
551 -- The deferral level is critical here, since we want to raise an
552 -- exception or allow abort to take place, if there is an exception or
556 (Debug
.Trace
(Self_Id
, "Local_Complete_Rendezvous", 'R'));
558 if Ex
= Ada
.Exceptions
.Null_Id
then
560 -- The call came from normal end-of-rendezvous, so abort is not yet
563 if Parameters
.Runtime_Traces
then
564 Send_Trace_Info
(M_RDV_Complete
, Entry_Call
.Self
);
567 Initialization
.Defer_Abort
(Self_Id
);
569 elsif ZCX_By_Default
then
571 -- With ZCX, aborts are not automatically deferred in handlers
573 Initialization
.Defer_Abort
(Self_Id
);
576 -- We need to clean up any accepts which Self may have been serving when
579 if Ex
= Standard
'Abort_Signal'Identity then
584 while Entry_Call /= null loop
585 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
587 -- All forms of accept make sure that the acceptor is not
588 -- completed, before accepting further calls, so that we
589 -- can be sure that no further calls are made after the
590 -- current calls are purged.
592 Caller := Entry_Call.Self;
594 -- Take write lock. This follows the lock precedence rule that
595 -- Caller may be locked while holding lock of Acceptor. Complete
596 -- the call abnormally, with exception.
598 STPO.Write_Lock (Caller);
599 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
600 STPO.Unlock (Caller);
601 Entry_Call := Entry_Call.Acceptor_Prev_Call;
609 Caller := Entry_Call.Self;
611 if Entry_Call.Needs_Requeue then
613 -- We dare not lock Self_Id at the same time as Caller, for fear
616 Entry_Call.Needs_Requeue := False;
617 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
619 if Entry_Call.Called_Task /= null then
621 -- Requeue to another task entry
627 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
632 Initialization.Undefer_Abort (Self_Id);
641 -- Requeue to a protected entry
643 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
644 STPE.Lock_Entries_With_Status (Called_PO, Ceiling_Violation);
646 if Ceiling_Violation then
647 pragma Assert (Ex = Ada.Exceptions.Null_Id);
648 Entry_Call.Exception_To_Raise := Program_Error'Identity;
654 STPO.Write_Lock (Caller);
655 Initialization.Wakeup_Entry_Caller
656 (Self_Id, Entry_Call, Done);
657 STPO.Unlock (Caller);
664 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
665 POO.PO_Service_Entries (Self_Id, Called_PO);
669 Entry_Calls.Reset_Priority
670 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
673 -- The call does not need to be requeued
675 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
676 Entry_Call.Exception_To_Raise := Ex;
682 STPO.Write_Lock (Caller);
684 -- Done with Caller locked to make sure that Wakeup is not lost
686 if Ex /= Ada.Exceptions.Null_Id then
688 (Caller.Common.Compiler_Data.Current_Excep'Access,
689 Self_Id.Common.Compiler_Data.Current_Excep);
692 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
693 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
695 STPO.Unlock (Caller);
701 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
705 Initialization.Undefer_Abort (Self_Id);
706 end Local_Complete_Rendezvous;
708 -------------------------------------
709 -- Requeue_Protected_To_Task_Entry --
710 -------------------------------------
712 procedure Requeue_Protected_To_Task_Entry
713 (Object : STPE.Protection_Entries_Access;
715 E : Task_Entry_Index;
716 With_Abort : Boolean)
718 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
720 pragma Assert (STPO.Self.Deferral_Level > 0);
722 Entry_Call.E := Entry_Index (E);
723 Entry_Call.Called_Task := Acceptor;
724 Entry_Call.Called_PO := Null_Address;
725 Entry_Call.With_Abort := With_Abort;
726 Object.Call_In_Progress := null;
727 end Requeue_Protected_To_Task_Entry;
729 ------------------------
730 -- Requeue_Task_Entry --
731 ------------------------
733 procedure Requeue_Task_Entry
735 E : Task_Entry_Index;
736 With_Abort : Boolean)
738 Self_Id : constant Task_Id := STPO.Self;
739 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
741 Initialization.Defer_Abort (Self_Id);
742 Entry_Call.Needs_Requeue := True;
743 Entry_Call.With_Abort := With_Abort;
744 Entry_Call.E := Entry_Index (E);
745 Entry_Call.Called_Task := Acceptor;
746 Initialization.Undefer_Abort (Self_Id);
747 end Requeue_Task_Entry;
753 procedure Selective_Wait
754 (Open_Accepts : Accept_List_Access;
755 Select_Mode : Select_Modes;
756 Uninterpreted_Data : out System.Address;
757 Index : out Select_Index)
759 Self_Id : constant Task_Id := STPO.Self;
760 Entry_Call : Entry_Call_Link;
761 Treatment : Select_Treatment;
763 Selection : Select_Index;
764 Open_Alternative : Boolean;
767 Initialization.Defer_Abort (Self_Id);
773 STPO.Write_Lock (Self_Id);
775 if not Self_Id.Callable then
776 pragma Assert (Self_Id.Pending_ATC_Level = 0);
778 pragma Assert (Self_Id.Pending_Action);
780 STPO.Unlock (Self_Id);
786 -- ??? In some cases abort is deferred more than once. Need to
787 -- figure out why this happens.
789 if Self_Id.Deferral_Level > 1 then
790 Self_Id.Deferral_Level := 1;
793 Initialization.Undefer_Abort (Self_Id);
795 -- Should never get here ???
797 pragma Assert (False);
798 raise Standard'Abort_Signal;
801 pragma Assert (Open_Accepts /= null);
803 Uninterpreted_Data := Null_Address;
805 Queuing.Select_Task_Entry_Call
806 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
808 -- Determine the kind and disposition of the select
810 Treatment := Default_Treatment (Select_Mode);
811 Self_Id.Chosen_Index := No_Rendezvous;
813 if Open_Alternative then
814 if Entry_Call /= null then
815 if Open_Accepts (Selection).Null_Body then
816 Treatment := Accept_Alternative_Completed;
818 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
819 Treatment := Accept_Alternative_Selected;
822 Self_Id.Chosen_Index := Selection;
824 elsif Treatment = No_Alternative_Open then
825 Treatment := Accept_Alternative_Open;
829 -- Handle the select according to the disposition selected above
832 when Accept_Alternative_Selected =>
834 -- Ready to rendezvous
836 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
838 -- In this case the accept body is not Null_Body. Defer abort
839 -- until it gets into the accept body. The compiler has inserted
840 -- a call to Abort_Undefer as part of the entry expansion.
842 pragma Assert (Self_Id.Deferral_Level = 1);
844 Initialization.Defer_Abort_Nestable (Self_Id);
845 STPO.Unlock (Self_Id);
847 when Accept_Alternative_Completed =>
849 -- Accept body is null, so rendezvous is over immediately
851 if Parameters.Runtime_Traces then
852 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
855 STPO.Unlock (Self_Id);
856 Caller := Entry_Call.Self;
858 STPO.Write_Lock (Caller);
859 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
860 STPO.Unlock (Caller);
862 when Accept_Alternative_Open =>
866 Self_Id.Open_Accepts := Open_Accepts;
868 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R
'));
870 if Parameters.Runtime_Traces then
871 Send_Trace_Info (W_Select, Self_Id,
872 Integer (Open_Accepts'Length));
875 Wait_For_Call (Self_Id);
877 pragma Assert (Self_Id.Open_Accepts = null);
879 -- Self_Id.Common.Call should already be updated by the Caller if
880 -- not aborted. It might also be ready to do rendezvous even if
881 -- this wakes up due to an abort. Therefore, if the call is not
882 -- empty we need to do the rendezvous if the accept body is not
885 -- Aren't the first two conditions below redundant???
887 if Self_Id.Chosen_Index /= No_Rendezvous
888 and then Self_Id.Common.Call /= null
889 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
891 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
894 (Self_Id.Deferral_Level = 1
896 (Self_Id.Deferral_Level = 0
897 and then not Restrictions.Abort_Allowed));
899 Initialization.Defer_Abort_Nestable (Self_Id);
901 -- Leave abort deferred until the accept body
902 -- The compiler has inserted a call to Abort_Undefer as part of
903 -- the entry expansion.
906 STPO.Unlock (Self_Id);
908 when Else_Selected =>
909 pragma Assert (Self_Id.Open_Accepts = null);
911 if Parameters.Runtime_Traces then
912 Send_Trace_Info (M_Select_Else);
915 STPO.Unlock (Self_Id);
917 when Terminate_Selected =>
919 -- Terminate alternative is open
921 Self_Id.Open_Accepts := Open_Accepts;
922 Self_Id.Common.State := Acceptor_Sleep;
924 -- Notify ancestors that this task is on a terminate alternative
926 STPO.Unlock (Self_Id);
927 Utilities.Make_Passive (Self_Id, Task_Completed => False);
928 STPO.Write_Lock (Self_Id);
930 -- Wait for normal entry call or termination
932 Wait_For_Call (Self_Id);
934 pragma Assert (Self_Id.Open_Accepts = null);
936 if Self_Id.Terminate_Alternative then
938 -- An entry call should have reset this to False, so we must be
939 -- aborted. We cannot be in an async. select, since that is not
940 -- legal, so the abort must be of the entire task. Therefore,
941 -- we do not need to cancel the terminate alternative. The
942 -- cleanup will be done in Complete_Master.
944 pragma Assert (Self_Id.Pending_ATC_Level = 0);
945 pragma Assert (Self_Id.Awake_Count = 0);
947 STPO.Unlock (Self_Id);
953 Index := Self_Id.Chosen_Index;
954 Initialization.Undefer_Abort_Nestable (Self_Id);
956 if Self_Id.Pending_Action then
957 Initialization.Do_Pending_Action (Self_Id);
963 -- Self_Id.Common.Call and Self_Id.Chosen_Index
964 -- should already be updated by the Caller.
966 if Self_Id.Chosen_Index /= No_Rendezvous
967 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
969 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
971 pragma Assert (Self_Id.Deferral_Level = 1);
973 -- We need an extra defer here, to keep abort
974 -- deferred until we get into the accept body
975 -- The compiler has inserted a call to Abort_Undefer as part
976 -- of the entry expansion.
978 Initialization.Defer_Abort_Nestable (Self_Id);
982 STPO.Unlock (Self_Id);
984 when No_Alternative_Open =>
986 -- In this case, Index will be No_Rendezvous on return, which
987 -- should cause a Program_Error if it is not a Delay_Mode.
989 -- If delay alternative exists (Delay_Mode) we should suspend
990 -- until the delay expires.
992 Self_Id.Open_Accepts := null;
994 if Select_Mode = Delay_Mode then
995 Self_Id.Common.State := Delay_Sleep;
999 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
1000 Sleep (Self_Id, Delay_Sleep);
1003 Self_Id.Common.State := Runnable;
1004 STPO.Unlock (Self_Id);
1007 STPO.Unlock (Self_Id);
1013 Initialization.Undefer_Abort (Self_Id);
1014 raise Program_Error with
1015 "entry call not a delay mode";
1023 -- Caller has been chosen
1025 -- Self_Id.Common.Call should already be updated by the Caller.
1027 -- Self_Id.Chosen_Index should either be updated by the Caller
1028 -- or by Test_Selective_Wait.
1030 -- On return, we sill start rendezvous unless the accept body is
1031 -- null. In the latter case, we will have already completed the RV.
1033 Index := Self_Id.Chosen_Index;
1034 Initialization.Undefer_Abort_Nestable (Self_Id);
1037 ------------------------------------
1038 -- Setup_For_Rendezvous_With_Body --
1039 ------------------------------------
1041 procedure Setup_For_Rendezvous_With_Body
1042 (Entry_Call : Entry_Call_Link;
1043 Acceptor : Task_Id) is
1045 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1046 Acceptor.Common.Call := Entry_Call;
1048 if Entry_Call.State = Now_Abortable then
1049 Entry_Call.State := Was_Abortable;
1052 Boost_Priority (Entry_Call, Acceptor);
1053 end Setup_For_Rendezvous_With_Body;
1059 function Task_Count (E : Task_Entry_Index) return Natural is
1060 Self_Id : constant Task_Id := STPO.Self;
1061 Return_Count : Natural;
1064 Initialization.Defer_Abort (Self_Id);
1070 STPO.Write_Lock (Self_Id);
1071 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1072 STPO.Unlock (Self_Id);
1078 Initialization.Undefer_Abort (Self_Id);
1080 return Return_Count;
1083 ----------------------
1084 -- Task_Do_Or_Queue --
1085 ----------------------
1087 function Task_Do_Or_Queue
1089 Entry_Call : Entry_Call_Link) return Boolean
1091 E : constant Task_Entry_Index :=
1092 Task_Entry_Index (Entry_Call.E);
1093 Old_State : constant Entry_Call_State := Entry_Call.State;
1094 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1095 Parent : constant Task_Id := Acceptor.Common.Parent;
1096 Null_Body : Boolean;
1099 -- Find out whether Entry_Call can be accepted immediately
1101 -- If the Acceptor is not callable, return False.
1102 -- If the rendezvous can start, initiate it.
1103 -- If the accept-body is trivial, also complete the rendezvous.
1104 -- If the acceptor is not ready, enqueue the call.
1106 -- This should have a special case for Accept_Call and Accept_Trivial,
1107 -- so that we don't have the loop setup overhead, below.
1109 -- The call state Done is used here and elsewhere to include both the
1110 -- case of normal successful completion, and the case of an exception
1111 -- being raised. The difference is that if an exception is raised no one
1112 -- will pay attention to the fact that State = Done. Instead the
1113 -- exception will be raised in Undefer_Abort, and control will skip past
1114 -- the place where we normally would resume from an entry call.
1116 pragma Assert (not Queuing.Onqueue (Entry_Call));
1118 -- We rely that the call is off-queue for protection, that the caller
1119 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1120 -- record for another call. We rely on the Caller's lock for call State
1123 -- If Acceptor.Terminate_Alternative is True, we need to lock Parent and
1124 -- Acceptor, in that order; otherwise, we only need a lock on Acceptor.
1125 -- However, we can't check Acceptor.Terminate_Alternative until Acceptor
1126 -- is locked. Therefore, we need to lock both. Attempts to avoid locking
1127 -- Parent tend to result in race conditions. It would work to unlock
1128 -- Parent immediately upon finding Acceptor.Terminate_Alternative to be
1129 -- False, but that violates the rule of properly nested locking (see
1132 STPO.Write_Lock (Parent);
1133 STPO.Write_Lock (Acceptor);
1135 -- If the acceptor is not callable, abort the call and return False
1137 if not Acceptor.Callable then
1138 STPO.Unlock (Acceptor);
1139 STPO.Unlock (Parent);
1141 pragma Assert (Entry_Call.State < Done);
1143 -- In case we are not the caller, set up the caller
1144 -- to raise Tasking_Error when it wakes up.
1146 STPO.Write_Lock (Entry_Call.Self);
1147 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1148 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1149 STPO.Unlock (Entry_Call.Self);
1154 -- Try to serve the call immediately
1156 if Acceptor.Open_Accepts /= null then
1157 for J in Acceptor.Open_Accepts'Range loop
1158 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1160 -- Commit acceptor to rendezvous with us
1162 Acceptor.Chosen_Index := J;
1163 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1164 Acceptor.Open_Accepts := null;
1166 -- Prevent abort while call is being served
1168 if Entry_Call.State = Now_Abortable then
1169 Entry_Call.State := Was_Abortable;
1172 if Acceptor.Terminate_Alternative then
1174 -- Cancel terminate alternative. See matching code in
1175 -- Selective_Wait and Vulnerable_Complete_Master.
1177 Acceptor.Terminate_Alternative := False;
1178 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1180 if Acceptor.Awake_Count = 1 then
1182 -- Notify parent that acceptor is awake
1184 pragma Assert (Parent.Awake_Count > 0);
1186 Parent.Awake_Count := Parent.Awake_Count + 1;
1188 if Parent.Common.State = Master_Completion_Sleep
1189 and then Acceptor.Master_of_Task = Parent.Master_Within
1191 Parent.Common.Wait_Count :=
1192 Parent.Common.Wait_Count + 1;
1199 -- Rendezvous is over immediately
1201 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1202 STPO.Unlock (Acceptor);
1203 STPO.Unlock (Parent);
1205 STPO.Write_Lock (Entry_Call.Self);
1206 Initialization.Wakeup_Entry_Caller
1207 (Self_ID, Entry_Call, Done);
1208 STPO.Unlock (Entry_Call.Self);
1211 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1213 -- For terminate_alternative, acceptor may not be asleep
1214 -- yet, so we skip the wakeup
1216 if Acceptor.Common.State /= Runnable then
1217 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1220 STPO.Unlock (Acceptor);
1221 STPO.Unlock (Parent);
1228 -- The acceptor is accepting, but not this entry
1231 -- If the acceptor was ready to accept this call,
1232 -- we would not have gotten this far, so now we should
1233 -- (re)enqueue the call, if the mode permits that.
1235 -- If the call is timed, it may have timed out before the requeue,
1236 -- in the unusual case where the current accept has taken longer than
1237 -- the given delay. In that case the requeue is cancelled, and the
1238 -- outer timed call will be aborted.
1240 if Entry_Call.Mode = Conditional_Call
1242 (Entry_Call.Mode = Timed_Call
1243 and then Entry_Call.With_Abort
1244 and then Entry_Call.Cancellation_Attempted)
1246 STPO.Unlock (Acceptor);
1247 STPO.Unlock (Parent);
1249 STPO.Write_Lock (Entry_Call.Self);
1251 pragma Assert (Entry_Call.State >= Was_Abortable);
1253 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1254 STPO.Unlock (Entry_Call.Self);
1257 -- Timed_Call, Simple_Call, or Asynchronous_Call
1259 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1261 -- Update abortability of call
1263 pragma Assert (Old_State < Done);
1266 New_State (Entry_Call.With_Abort, Entry_Call.State);
1268 STPO.Unlock (Acceptor);
1269 STPO.Unlock (Parent);
1271 if Old_State /= Entry_Call.State
1272 and then Entry_Call.State = Now_Abortable
1273 and then Entry_Call.Mode /= Simple_Call
1274 and then Entry_Call.Self /= Self_ID
1276 -- Asynchronous_Call or Conditional_Call
1279 -- Because of ATCB lock ordering rule
1281 STPO.Write_Lock (Entry_Call.Self);
1283 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1285 -- Caller may not yet have reached wait-point
1287 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1290 STPO.Unlock (Entry_Call.Self);
1295 end Task_Do_Or_Queue;
1297 ---------------------
1298 -- Task_Entry_Call --
1299 ---------------------
1301 procedure Task_Entry_Call
1302 (Acceptor : Task_Id;
1303 E : Task_Entry_Index;
1304 Uninterpreted_Data : System.Address;
1306 Rendezvous_Successful : out Boolean)
1308 Self_Id : constant Task_Id := STPO.Self;
1309 Entry_Call : Entry_Call_Link;
1312 -- If pragma Detect_Blocking is active then Program_Error must be
1313 -- raised if this potentially blocking operation is called from a
1314 -- protected action.
1316 if System.Tasking.Detect_Blocking
1317 and then Self_Id.Common.Protected_Action_Nesting > 0
1319 raise Program_Error with
1320 "potentially blocking operation";
1323 if Parameters.Runtime_Traces then
1324 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1327 if Mode = Simple_Call or else Mode = Conditional_Call then
1329 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1332 -- This is an asynchronous call
1334 -- Abort must already be deferred by the compiler-generated code.
1335 -- Without this, an abort that occurs between the time that this
1336 -- call is made and the time that the abortable part's cleanup
1337 -- handler is set up might miss the cleanup handler and leave the
1340 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1342 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1343 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1344 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1345 Entry_Call.Next := null;
1346 Entry_Call.Mode := Mode;
1347 Entry_Call.Cancellation_Attempted := False;
1348 Entry_Call.State := Not_Yet_Abortable;
1349 Entry_Call.E := Entry_Index (E);
1350 Entry_Call.Prio := Get_Priority (Self_Id);
1351 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1352 Entry_Call.Called_Task := Acceptor;
1353 Entry_Call.Called_PO := Null_Address;
1354 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1355 Entry_Call.With_Abort := True;
1361 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1362 STPO.Write_Lock (Self_Id);
1363 Utilities.Exit_One_ATC_Level (Self_Id);
1364 STPO.Unlock (Self_Id);
1370 Initialization.Undefer_Abort (Self_Id);
1372 if Parameters.Runtime_Traces then
1373 Send_Trace_Info (E_Missed, Acceptor);
1376 raise Tasking_Error;
1379 -- The following is special for async. entry calls. If the call was
1380 -- not queued abortably, we need to wait until it is before
1381 -- proceeding with the abortable part.
1383 -- Wait_Until_Abortable can be called unconditionally here, but it is
1386 if Entry_Call.State < Was_Abortable then
1387 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1394 -- Note: following assignment needs to be atomic
1396 Rendezvous_Successful := Entry_Call.State = Done;
1398 end Task_Entry_Call;
1400 -----------------------
1401 -- Task_Entry_Caller --
1402 -----------------------
1404 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1405 Self_Id : constant Task_Id := STPO.Self;
1406 Entry_Call : Entry_Call_Link;
1409 Entry_Call := Self_Id.Common.Call;
1411 for Depth in 1 .. D loop
1412 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1413 pragma Assert (Entry_Call /= null);
1416 return Entry_Call.Self;
1417 end Task_Entry_Caller;
1419 --------------------------
1420 -- Timed_Selective_Wait --
1421 --------------------------
1423 procedure Timed_Selective_Wait
1424 (Open_Accepts : Accept_List_Access;
1425 Select_Mode : Select_Modes;
1426 Uninterpreted_Data : out System.Address;
1429 Index : out Select_Index)
1431 Self_Id : constant Task_Id := STPO.Self;
1432 Treatment : Select_Treatment;
1433 Entry_Call : Entry_Call_Link;
1435 Selection : Select_Index;
1436 Open_Alternative : Boolean;
1437 Timedout : Boolean := False;
1438 Yielded : Boolean := True;
1441 pragma Assert (Select_Mode = Delay_Mode);
1443 Initialization.Defer_Abort (Self_Id);
1445 -- If we are aborted here, the effect will be pending
1451 STPO.Write_Lock (Self_Id);
1453 if not Self_Id.Callable then
1454 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1456 pragma Assert (Self_Id.Pending_Action);
1458 STPO.Unlock (Self_Id);
1464 Initialization.Undefer_Abort (Self_Id);
1466 -- Should never get here ???
1468 pragma Assert (False);
1469 raise Standard'Abort_Signal;
1472 Uninterpreted_Data := Null_Address;
1474 pragma Assert (Open_Accepts /= null);
1476 Queuing.Select_Task_Entry_Call
1477 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1479 -- Determine the kind and disposition of the select
1481 Treatment := Default_Treatment (Select_Mode);
1482 Self_Id.Chosen_Index := No_Rendezvous;
1484 if Open_Alternative then
1485 if Entry_Call /= null then
1486 if Open_Accepts (Selection).Null_Body then
1487 Treatment := Accept_Alternative_Completed;
1490 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1491 Treatment := Accept_Alternative_Selected;
1494 Self_Id.Chosen_Index := Selection;
1496 elsif Treatment = No_Alternative_Open then
1497 Treatment := Accept_Alternative_Open;
1501 -- Handle the select according to the disposition selected above
1504 when Accept_Alternative_Selected =>
1506 -- Ready to rendezvous. In this case the accept body is not
1507 -- Null_Body. Defer abort until it gets into the accept body.
1509 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1510 Initialization.Defer_Abort_Nestable (Self_Id);
1511 STPO.Unlock (Self_Id);
1513 when Accept_Alternative_Completed =>
1515 -- Rendezvous is over
1517 if Parameters.Runtime_Traces then
1518 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1521 STPO.Unlock (Self_Id);
1522 Caller := Entry_Call.Self;
1524 STPO.Write_Lock (Caller);
1525 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1526 STPO.Unlock (Caller);
1528 when Accept_Alternative_Open =>
1532 Self_Id.Open_Accepts := Open_Accepts;
1534 -- Wait for a normal call and a pending action until the
1535 -- Wakeup_Time is reached.
1537 Self_Id.Common.State := Acceptor_Delay_Sleep;
1539 -- Try to remove calls to Sleep in the loop below by letting the
1540 -- caller a chance of getting ready immediately, using Unlock
1541 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1549 if Self_Id.Open_Accepts /= null then
1556 Write_Lock (Self_Id);
1559 -- Check if this task has been aborted while the lock was released
1561 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1562 Self_Id.Open_Accepts := null;
1566 exit when Self_Id.Open_Accepts = null;
1569 Sleep (Self_Id, Acceptor_Delay_Sleep);
1571 if Parameters.Runtime_Traces then
1572 Send_Trace_Info (WT_Select,
1574 Integer (Open_Accepts'Length),
1578 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1579 Acceptor_Delay_Sleep, Timedout, Yielded);
1583 Self_Id.Open_Accepts := null;
1585 if Parameters.Runtime_Traces then
1586 Send_Trace_Info (E_Timeout);
1591 Self_Id.Common.State := Runnable;
1593 -- Self_Id.Common.Call should already be updated by the Caller if
1594 -- not aborted. It might also be ready to do rendezvous even if
1595 -- this wakes up due to an abort. Therefore, if the call is not
1596 -- empty we need to do the rendezvous if the accept body is not
1599 if Self_Id.Chosen_Index /= No_Rendezvous
1600 and then Self_Id.Common.Call /= null
1601 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1603 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1605 pragma Assert (Self_Id.Deferral_Level = 1);
1607 Initialization.Defer_Abort_Nestable (Self_Id);
1609 -- Leave abort deferred until the accept body
1612 STPO.Unlock (Self_Id);
1614 when No_Alternative_Open =>
1616 -- In this case, Index will be No_Rendezvous on return. We sleep
1617 -- for the time we need to.
1619 -- Wait for a signal or timeout. A wakeup can be made
1620 -- for several reasons:
1621 -- 1) Delay is expired
1622 -- 2) Pending_Action needs to be checked
1623 -- (Abort, Priority change)
1624 -- 3) Spurious wakeup
1626 Self_Id.Open_Accepts := null;
1627 Self_Id.Common.State := Acceptor_Delay_Sleep;
1629 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Delay_Sleep,
1632 Self_Id.Common.State := Runnable;
1634 STPO.Unlock (Self_Id);
1638 -- Should never get here
1640 pragma Assert (False);
1652 -- Caller has been chosen
1654 -- Self_Id.Common.Call should already be updated by the Caller
1656 -- Self_Id.Chosen_Index should either be updated by the Caller
1657 -- or by Test_Selective_Wait
1659 Index := Self_Id.Chosen_Index;
1660 Initialization.Undefer_Abort_Nestable (Self_Id);
1662 -- Start rendezvous, if not already completed
1663 end Timed_Selective_Wait;
1665 ---------------------------
1666 -- Timed_Task_Entry_Call --
1667 ---------------------------
1669 procedure Timed_Task_Entry_Call
1670 (Acceptor : Task_Id;
1671 E : Task_Entry_Index;
1672 Uninterpreted_Data : System.Address;
1675 Rendezvous_Successful : out Boolean)
1677 Self_Id : constant Task_Id := STPO.Self;
1679 Entry_Call : Entry_Call_Link;
1682 pragma Unreferenced (Yielded);
1685 -- If pragma Detect_Blocking is active then Program_Error must be
1686 -- raised if this potentially blocking operation is called from a
1687 -- protected action.
1689 if System.Tasking.Detect_Blocking
1690 and then Self_Id.Common.Protected_Action_Nesting > 0
1692 raise Program_Error with
1693 "potentially blocking operation";
1696 Initialization.Defer_Abort (Self_Id);
1697 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1700 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1701 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1703 if Parameters.Runtime_Traces then
1704 Send_Trace_Info (WT_Call, Acceptor,
1705 Entry_Index (E), Timeout);
1708 Level := Self_Id.ATC_Nesting_Level;
1709 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1710 Entry_Call.Next := null;
1711 Entry_Call.Mode := Timed_Call;
1712 Entry_Call.Cancellation_Attempted := False;
1714 -- If this is a call made inside of an abort deferred region,
1715 -- the call should be never abortable.
1718 (if Self_Id.Deferral_Level > 1
1719 then Never_Abortable
1720 else Now_Abortable);
1722 Entry_Call.E := Entry_Index (E);
1723 Entry_Call.Prio := Get_Priority (Self_Id);
1724 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1725 Entry_Call.Called_Task := Acceptor;
1726 Entry_Call.Called_PO := Null_Address;
1727 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1728 Entry_Call.With_Abort := True;
1730 -- Note: the caller will undefer abort on return (see WARNING above)
1736 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1737 STPO.Write_Lock (Self_Id);
1738 Utilities.Exit_One_ATC_Level (Self_Id);
1739 STPO.Unlock (Self_Id);
1745 Initialization.Undefer_Abort (Self_Id);
1747 if Parameters.Runtime_Traces then
1748 Send_Trace_Info (E_Missed, Acceptor);
1750 raise Tasking_Error;
1753 Write_Lock (Self_Id);
1754 Entry_Calls.Wait_For_Completion_With_Timeout
1755 (Entry_Call, Timeout, Mode, Yielded);
1762 -- ??? Do we need to yield in case Yielded is False
1764 Rendezvous_Successful := Entry_Call.State = Done;
1765 Initialization.Undefer_Abort (Self_Id);
1766 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1767 end Timed_Task_Entry_Call;
1773 procedure Wait_For_Call (Self_Id : Task_Id) is
1775 Self_Id.Common.State := Acceptor_Sleep;
1777 -- Try to remove calls to Sleep in the loop below by letting the caller
1778 -- a chance of getting ready immediately, using Unlock & Yield.
1779 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1787 if Self_Id.Open_Accepts /= null then
1794 Write_Lock (Self_Id);
1797 -- Check if this task has been aborted while the lock was released
1799 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1800 Self_Id.Open_Accepts := null;
1804 exit when Self_Id.Open_Accepts = null;
1805 Sleep (Self_Id, Acceptor_Sleep);
1808 Self_Id.Common.State := Runnable;
1811 end System.Tasking.Rendezvous;