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;
395 pragma Unreferenced
(Rendezvous_Successful
);
398 -- If pragma Detect_Blocking is active then Program_Error must be
399 -- raised if this potentially blocking operation is called from a
402 if System
.Tasking
.Detect_Blocking
403 and then STPO
.Self
.Common
.Protected_Action_Nesting
> 0
405 Ada
.Exceptions
.Raise_Exception
406 (Program_Error
'Identity, "potentially blocking operation");
410 (Acceptor
, E
, Uninterpreted_Data
, Simple_Call
, Rendezvous_Successful
);
413 ----------------------
414 -- Call_Synchronous --
415 ----------------------
417 procedure Call_Synchronous
419 E
: Task_Entry_Index
;
420 Uninterpreted_Data
: System
.Address
;
422 Rendezvous_Successful
: out Boolean)
424 Self_Id
: constant Task_Id
:= STPO
.Self
;
426 Entry_Call
: Entry_Call_Link
;
429 pragma Assert
(Mode
/= Asynchronous_Call
);
431 Local_Defer_Abort
(Self_Id
);
432 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
+ 1;
434 (Debug
.Trace
(Self_Id
, "CS: entered ATC level: " &
435 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
436 Level
:= Self_Id
.ATC_Nesting_Level
;
437 Entry_Call
:= Self_Id
.Entry_Calls
(Level
)'Access;
438 Entry_Call
.Next
:= null;
439 Entry_Call
.Mode
:= Mode
;
440 Entry_Call
.Cancellation_Attempted
:= False;
442 if Parameters
.Runtime_Traces
then
443 Send_Trace_Info
(W_Call
, Acceptor
, Entry_Index
(E
));
446 -- If this is a call made inside of an abort deferred region,
447 -- the call should be never abortable.
449 if Self_Id
.Deferral_Level
> 1 then
450 Entry_Call
.State
:= Never_Abortable
;
452 Entry_Call
.State
:= Now_Abortable
;
455 Entry_Call
.E
:= Entry_Index
(E
);
456 Entry_Call
.Prio
:= Get_Priority
(Self_Id
);
457 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
458 Entry_Call
.Called_Task
:= Acceptor
;
459 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
460 Entry_Call
.With_Abort
:= True;
462 -- Note: the caller will undefer abort on return (see WARNING above)
468 if not Task_Do_Or_Queue
(Self_Id
, Entry_Call
) then
469 STPO
.Write_Lock
(Self_Id
);
470 Utilities
.Exit_One_ATC_Level
(Self_Id
);
471 STPO
.Unlock
(Self_Id
);
477 if Parameters
.Runtime_Traces
then
478 Send_Trace_Info
(E_Missed
, Acceptor
);
481 Local_Undefer_Abort
(Self_Id
);
485 STPO
.Write_Lock
(Self_Id
);
487 (Debug
.Trace
(Self_Id
, "Call_Synchronous: wait", 'R'));
488 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
490 (Debug
.Trace
(Self_Id
, "Call_Synchronous: done waiting", 'R'));
491 Rendezvous_Successful
:= Entry_Call
.State
= Done
;
492 STPO
.Unlock
(Self_Id
);
498 Local_Undefer_Abort
(Self_Id
);
499 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
500 end Call_Synchronous
;
506 function Callable
(T
: Task_Id
) return Boolean is
508 Self_Id
: constant Task_Id
:= STPO
.Self
;
511 Initialization
.Defer_Abort_Nestable
(Self_Id
);
518 Result
:= T
.Callable
;
525 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
529 ----------------------------
530 -- Cancel_Task_Entry_Call --
531 ----------------------------
533 procedure Cancel_Task_Entry_Call
(Cancelled
: out Boolean) is
535 Entry_Calls
.Try_To_Cancel_Entry_Call
(Cancelled
);
536 end Cancel_Task_Entry_Call
;
538 -------------------------
539 -- Complete_Rendezvous --
540 -------------------------
542 procedure Complete_Rendezvous
is
544 Exceptional_Complete_Rendezvous
(Ada
.Exceptions
.Null_Id
);
545 end Complete_Rendezvous
;
547 -------------------------------------
548 -- Exceptional_Complete_Rendezvous --
549 -------------------------------------
551 procedure Exceptional_Complete_Rendezvous
552 (Ex
: Ada
.Exceptions
.Exception_Id
)
554 Self_Id
: constant Task_Id
:= STPO
.Self
;
555 Entry_Call
: Entry_Call_Link
:= Self_Id
.Common
.Call
;
557 Called_PO
: STPE
.Protection_Entries_Access
;
558 Acceptor_Prev_Priority
: Integer;
560 Exception_To_Raise
: Ada
.Exceptions
.Exception_Id
:= Ex
;
561 Ceiling_Violation
: Boolean;
563 use type Ada
.Exceptions
.Exception_Id
;
564 procedure Internal_Reraise
;
565 pragma Import
(C
, Internal_Reraise
, "__gnat_reraise");
567 procedure Transfer_Occurrence
568 (Target
: Ada
.Exceptions
.Exception_Occurrence_Access
;
569 Source
: Ada
.Exceptions
.Exception_Occurrence
);
570 pragma Import
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
572 use type STPE
.Protection_Entries_Access
;
575 -- Consider phasing out Complete_Rendezvous in favor
576 -- of direct call to this with Ada.Exceptions.Null_ID.
577 -- See code expansion examples for Accept_Call and Selective_Wait.
578 -- Also consider putting an explicit re-raise after this call, in
579 -- the generated code. That way we could eliminate the
580 -- code here that reraises the exception.
582 -- The deferral level is critical here,
583 -- since we want to raise an exception or allow abort to take
584 -- place, if there is an exception or abort pending.
587 (Debug
.Trace
(Self_Id
, "Exceptional_Complete_Rendezvous", 'R'));
589 if Ex
= Ada
.Exceptions
.Null_Id
then
590 -- The call came from normal end-of-rendezvous,
591 -- so abort is not yet deferred.
593 if Parameters
.Runtime_Traces
then
594 Send_Trace_Info
(M_RDV_Complete
, Entry_Call
.Self
);
597 Initialization
.Defer_Abort_Nestable
(Self_Id
);
600 -- We need to clean up any accepts which Self may have
601 -- been serving when it was aborted.
603 if Ex
= Standard
'Abort_Signal'Identity then
608 while Entry_Call /= null loop
609 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
611 -- All forms of accept make sure that the acceptor is not
612 -- completed, before accepting further calls, so that we
613 -- can be sure that no further calls are made after the
614 -- current calls are purged.
616 Caller := Entry_Call.Self;
618 -- Take write lock. This follows the lock precedence rule that
619 -- Caller may be locked while holding lock of Acceptor.
620 -- Complete the call abnormally, with exception.
622 STPO.Write_Lock (Caller);
623 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
624 STPO.Unlock (Caller);
625 Entry_Call := Entry_Call.Acceptor_Prev_Call;
633 Caller := Entry_Call.Self;
635 if Entry_Call.Needs_Requeue then
636 -- We dare not lock Self_Id at the same time as Caller,
637 -- for fear of deadlock.
639 Entry_Call.Needs_Requeue := False;
640 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
642 if Entry_Call.Called_Task /= null then
643 -- Requeue to another task entry
649 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
654 Initialization.Undefer_Abort (Self_Id);
663 -- Requeue to a protected entry
665 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
666 STPE.Lock_Entries (Called_PO, Ceiling_Violation);
668 if Ceiling_Violation then
669 pragma Assert (Ex = Ada.Exceptions.Null_Id);
671 Exception_To_Raise := Program_Error'Identity;
672 Entry_Call.Exception_To_Raise := Exception_To_Raise;
678 STPO.Write_Lock (Caller);
679 Initialization.Wakeup_Entry_Caller
680 (Self_Id, Entry_Call, Done);
681 STPO.Unlock (Caller);
688 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
689 POO.PO_Service_Entries (Self_Id, Called_PO);
693 Entry_Calls.Reset_Priority
694 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
697 -- The call does not need to be requeued
699 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
700 Entry_Call.Exception_To_Raise := Ex;
706 STPO.Write_Lock (Caller);
708 -- Done with Caller locked to make sure that Wakeup is not lost
710 if Ex /= Ada.Exceptions.Null_Id then
712 (Caller.Common.Compiler_Data.Current_Excep'Access,
713 Self_Id.Common.Compiler_Data.Current_Excep);
716 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
717 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
719 STPO.Unlock (Caller);
725 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
729 Initialization.Undefer_Abort (Self_Id);
731 if Exception_To_Raise /= Ada.Exceptions.Null_Id then
735 -- ??? Do we need to give precedence to Program_Error that might be
736 -- raised due to failure of finalization, over Tasking_Error from
737 -- failure of requeue?
738 end Exceptional_Complete_Rendezvous;
740 -------------------------------------
741 -- Requeue_Protected_To_Task_Entry --
742 -------------------------------------
744 procedure Requeue_Protected_To_Task_Entry
745 (Object : STPE.Protection_Entries_Access;
747 E : Task_Entry_Index;
748 With_Abort : Boolean)
750 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
752 pragma Assert (STPO.Self.Deferral_Level > 0);
754 Entry_Call.E := Entry_Index (E);
755 Entry_Call.Called_Task := Acceptor;
756 Entry_Call.Called_PO := Null_Address;
757 Entry_Call.With_Abort := With_Abort;
758 Object.Call_In_Progress := null;
759 end Requeue_Protected_To_Task_Entry;
761 ------------------------
762 -- Requeue_Task_Entry --
763 ------------------------
765 procedure Requeue_Task_Entry
767 E : Task_Entry_Index;
768 With_Abort : Boolean)
770 Self_Id : constant Task_Id := STPO.Self;
771 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
774 Initialization.Defer_Abort (Self_Id);
775 Entry_Call.Needs_Requeue := True;
776 Entry_Call.With_Abort := With_Abort;
777 Entry_Call.E := Entry_Index (E);
778 Entry_Call.Called_Task := Acceptor;
779 Initialization.Undefer_Abort (Self_Id);
780 end Requeue_Task_Entry;
786 procedure Selective_Wait
787 (Open_Accepts : Accept_List_Access;
788 Select_Mode : Select_Modes;
789 Uninterpreted_Data : out System.Address;
790 Index : out Select_Index)
792 Self_Id : constant Task_Id := STPO.Self;
793 Entry_Call : Entry_Call_Link;
794 Treatment : Select_Treatment;
796 Selection : Select_Index;
797 Open_Alternative : Boolean;
800 Initialization.Defer_Abort (Self_Id);
806 STPO.Write_Lock (Self_Id);
808 if not Self_Id.Callable then
809 pragma Assert (Self_Id.Pending_ATC_Level = 0);
811 pragma Assert (Self_Id.Pending_Action);
813 STPO.Unlock (Self_Id);
819 -- ??? In some cases abort is deferred more than once. Need to
820 -- figure out why this happens.
822 if Self_Id.Deferral_Level > 1 then
823 Self_Id.Deferral_Level := 1;
826 Initialization.Undefer_Abort (Self_Id);
828 -- Should never get here ???
830 pragma Assert (False);
831 raise Standard'Abort_Signal;
834 pragma Assert (Open_Accepts /= null);
836 Uninterpreted_Data := Null_Address;
838 Queuing.Select_Task_Entry_Call
839 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
841 -- Determine the kind and disposition of the select
843 Treatment := Default_Treatment (Select_Mode);
844 Self_Id.Chosen_Index := No_Rendezvous;
846 if Open_Alternative then
847 if Entry_Call /= null then
848 if Open_Accepts (Selection).Null_Body then
849 Treatment := Accept_Alternative_Completed;
851 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
852 Treatment := Accept_Alternative_Selected;
855 Self_Id.Chosen_Index := Selection;
857 elsif Treatment = No_Alternative_Open then
858 Treatment := Accept_Alternative_Open;
862 -- Handle the select according to the disposition selected above
865 when Accept_Alternative_Selected =>
866 -- Ready to rendezvous
868 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
870 -- In this case the accept body is not Null_Body. Defer abort
871 -- until it gets into the accept body.
873 pragma Assert (Self_Id.Deferral_Level = 1);
875 Initialization.Defer_Abort_Nestable (Self_Id);
876 STPO.Unlock (Self_Id);
878 when Accept_Alternative_Completed =>
880 -- Accept body is null, so rendezvous is over immediately
882 if Parameters.Runtime_Traces then
883 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
886 STPO.Unlock (Self_Id);
887 Caller := Entry_Call.Self;
889 STPO.Write_Lock (Caller);
890 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
891 STPO.Unlock (Caller);
893 when Accept_Alternative_Open =>
897 Self_Id.Open_Accepts := Open_Accepts;
899 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R
'));
901 if Parameters.Runtime_Traces then
902 Send_Trace_Info (W_Select, Self_Id,
903 Integer (Open_Accepts'Length));
906 Wait_For_Call (Self_Id);
908 pragma Assert (Self_Id.Open_Accepts = null);
910 -- Self_Id.Common.Call should already be updated by the Caller if
911 -- not aborted. It might also be ready to do rendezvous even if
912 -- this wakes up due to an abort. Therefore, if the call is not
913 -- empty we need to do the rendezvous if the accept body is not
916 -- Aren't the first two conditions below redundant???
918 if Self_Id.Chosen_Index /= No_Rendezvous
919 and then Self_Id.Common.Call /= null
920 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
922 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
925 (Self_Id.Deferral_Level = 1
927 (Self_Id.Deferral_Level = 0
928 and then not Restrictions.Abort_Allowed));
930 Initialization.Defer_Abort_Nestable (Self_Id);
932 -- Leave abort deferred until the accept body
935 STPO.Unlock (Self_Id);
937 when Else_Selected =>
938 pragma Assert (Self_Id.Open_Accepts = null);
940 if Parameters.Runtime_Traces then
941 Send_Trace_Info (M_Select_Else);
944 STPO.Unlock (Self_Id);
946 when Terminate_Selected =>
947 -- Terminate alternative is open
949 Self_Id.Open_Accepts := Open_Accepts;
950 Self_Id.Common.State := Acceptor_Sleep;
952 -- Notify ancestors that this task is on a terminate alternative
954 STPO.Unlock (Self_Id);
955 Utilities.Make_Passive (Self_Id, Task_Completed => False);
956 STPO.Write_Lock (Self_Id);
958 -- Wait for normal entry call or termination
960 Wait_For_Call (Self_Id);
962 pragma Assert (Self_Id.Open_Accepts = null);
964 if Self_Id.Terminate_Alternative then
965 -- An entry call should have reset this to False,
966 -- so we must be aborted.
967 -- We cannot be in an async. select, since that
968 -- is not legal, so the abort must be of the entire
969 -- task. Therefore, we do not need to cancel the
970 -- terminate alternative. The cleanup will be done
971 -- in Complete_Master.
973 pragma Assert (Self_Id.Pending_ATC_Level = 0);
974 pragma Assert (Self_Id.Awake_Count = 0);
976 STPO.Unlock (Self_Id);
982 Index := Self_Id.Chosen_Index;
983 Initialization.Undefer_Abort_Nestable (Self_Id);
985 if Self_Id.Pending_Action then
986 Initialization.Do_Pending_Action (Self_Id);
992 -- Self_Id.Common.Call and Self_Id.Chosen_Index
993 -- should already be updated by the Caller.
995 if Self_Id.Chosen_Index /= No_Rendezvous
996 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
998 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1000 pragma Assert (Self_Id.Deferral_Level = 1);
1002 -- We need an extra defer here, to keep abort
1003 -- deferred until we get into the accept body
1005 Initialization.Defer_Abort_Nestable (Self_Id);
1009 STPO.Unlock (Self_Id);
1011 when No_Alternative_Open =>
1012 -- In this case, Index will be No_Rendezvous on return, which
1013 -- should cause a Program_Error if it is not a Delay_Mode.
1015 -- If delay alternative exists (Delay_Mode) we should suspend
1016 -- until the delay expires.
1018 Self_Id.Open_Accepts := null;
1020 if Select_Mode = Delay_Mode then
1021 Self_Id.Common.State := Delay_Sleep;
1025 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
1026 Sleep (Self_Id, Delay_Sleep);
1029 Self_Id.Common.State := Runnable;
1030 STPO.Unlock (Self_Id);
1033 STPO.Unlock (Self_Id);
1039 Initialization.Undefer_Abort (Self_Id);
1040 Ada.Exceptions.Raise_Exception
1041 (Program_Error'Identity, "Entry call not a delay mode");
1049 -- Caller has been chosen.
1050 -- Self_Id.Common.Call should already be updated by the Caller.
1051 -- Self_Id.Chosen_Index should either be updated by the Caller
1052 -- or by Test_Selective_Wait.
1053 -- On return, we sill start rendezvous unless the accept body is
1054 -- null. In the latter case, we will have already completed the RV.
1056 Index := Self_Id.Chosen_Index;
1057 Initialization.Undefer_Abort_Nestable (Self_Id);
1060 ------------------------------------
1061 -- Setup_For_Rendezvous_With_Body --
1062 ------------------------------------
1064 procedure Setup_For_Rendezvous_With_Body
1065 (Entry_Call : Entry_Call_Link;
1066 Acceptor : Task_Id) is
1068 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1069 Acceptor.Common.Call := Entry_Call;
1071 if Entry_Call.State = Now_Abortable then
1072 Entry_Call.State := Was_Abortable;
1075 Boost_Priority (Entry_Call, Acceptor);
1076 end Setup_For_Rendezvous_With_Body;
1082 function Task_Count (E : Task_Entry_Index) return Natural is
1083 Self_Id : constant Task_Id := STPO.Self;
1084 Return_Count : Natural;
1087 Initialization.Defer_Abort (Self_Id);
1093 STPO.Write_Lock (Self_Id);
1094 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1095 STPO.Unlock (Self_Id);
1101 Initialization.Undefer_Abort (Self_Id);
1103 -- Call Yield to let other tasks get a chance to run as this is a
1104 -- potential dispatching point.
1106 Yield (Do_Yield => False);
1107 return Return_Count;
1110 ----------------------
1111 -- Task_Do_Or_Queue --
1112 ----------------------
1114 function Task_Do_Or_Queue
1116 Entry_Call : Entry_Call_Link) return Boolean
1118 E : constant Task_Entry_Index :=
1119 Task_Entry_Index (Entry_Call.E);
1120 Old_State : constant Entry_Call_State := Entry_Call.State;
1121 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1122 Parent : constant Task_Id := Acceptor.Common.Parent;
1123 Parent_Locked : Boolean := False;
1124 Null_Body : Boolean;
1127 -- Find out whether Entry_Call can be accepted immediately
1129 -- If the Acceptor is not callable, return False.
1130 -- If the rendezvous can start, initiate it.
1131 -- If the accept-body is trivial, also complete the rendezvous.
1132 -- If the acceptor is not ready, enqueue the call.
1134 -- This should have a special case for Accept_Call and Accept_Trivial,
1135 -- so that we don't have the loop setup overhead, below.
1137 -- The call state Done is used here and elsewhere to include both the
1138 -- case of normal successful completion, and the case of an exception
1139 -- being raised. The difference is that if an exception is raised no one
1140 -- will pay attention to the fact that State = Done. Instead the
1141 -- exception will be raised in Undefer_Abort, and control will skip past
1142 -- the place where we normally would resume from an entry call.
1144 pragma Assert (not Queuing.Onqueue (Entry_Call));
1146 -- We rely that the call is off-queue for protection, that the caller
1147 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1148 -- record for another call.
1149 -- We rely on the Caller's lock for call State mod's.
1151 -- We can't lock Acceptor.Parent while holding Acceptor,
1152 -- so lock it in advance if we expect to need to lock it.
1154 if Acceptor.Terminate_Alternative then
1155 STPO.Write_Lock (Parent);
1156 Parent_Locked := True;
1159 STPO.Write_Lock (Acceptor);
1161 -- If the acceptor is not callable, abort the call and return False
1163 if not Acceptor.Callable then
1164 STPO.Unlock (Acceptor);
1166 if Parent_Locked then
1167 STPO.Unlock (Parent);
1170 pragma Assert (Entry_Call.State < Done);
1172 -- In case we are not the caller, set up the caller
1173 -- to raise Tasking_Error when it wakes up.
1175 STPO.Write_Lock (Entry_Call.Self);
1176 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1177 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1178 STPO.Unlock (Entry_Call.Self);
1183 -- Try to serve the call immediately
1185 if Acceptor.Open_Accepts /= null then
1186 for J in Acceptor.Open_Accepts'Range loop
1187 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1189 -- Commit acceptor to rendezvous with us
1191 Acceptor.Chosen_Index := J;
1192 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1193 Acceptor.Open_Accepts := null;
1195 -- Prevent abort while call is being served
1197 if Entry_Call.State = Now_Abortable then
1198 Entry_Call.State := Was_Abortable;
1201 if Acceptor.Terminate_Alternative then
1203 -- Cancel terminate alternative. See matching code in
1204 -- Selective_Wait and Vulnerable_Complete_Master.
1206 Acceptor.Terminate_Alternative := False;
1207 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1209 if Acceptor.Awake_Count = 1 then
1211 -- Notify parent that acceptor is awake
1213 pragma Assert (Parent.Awake_Count > 0);
1215 Parent.Awake_Count := Parent.Awake_Count + 1;
1217 if Parent.Common.State = Master_Completion_Sleep
1218 and then Acceptor.Master_of_Task = Parent.Master_Within
1220 Parent.Common.Wait_Count :=
1221 Parent.Common.Wait_Count + 1;
1228 -- Rendezvous is over immediately
1230 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1231 STPO.Unlock (Acceptor);
1233 if Parent_Locked then
1234 STPO.Unlock (Parent);
1237 STPO.Write_Lock (Entry_Call.Self);
1238 Initialization.Wakeup_Entry_Caller
1239 (Self_ID, Entry_Call, Done);
1240 STPO.Unlock (Entry_Call.Self);
1243 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1245 -- For terminate_alternative, acceptor may not be asleep
1246 -- yet, so we skip the wakeup
1248 if Acceptor.Common.State /= Runnable then
1249 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1252 STPO.Unlock (Acceptor);
1254 if Parent_Locked then
1255 STPO.Unlock (Parent);
1263 -- The acceptor is accepting, but not this entry
1266 -- If the acceptor was ready to accept this call,
1267 -- we would not have gotten this far, so now we should
1268 -- (re)enqueue the call, if the mode permits that.
1270 if Entry_Call.Mode /= Conditional_Call
1271 or else not Entry_Call.With_Abort
1273 -- Timed_Call, Simple_Call, or Asynchronous_Call
1275 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1277 -- Update abortability of call
1279 pragma Assert (Old_State < Done);
1282 New_State (Entry_Call.With_Abort, Entry_Call.State);
1284 STPO.Unlock (Acceptor);
1286 if Parent_Locked then
1287 STPO.Unlock (Parent);
1290 if Old_State /= Entry_Call.State
1291 and then Entry_Call.State = Now_Abortable
1292 and then Entry_Call.Mode > Simple_Call
1293 and then Entry_Call.Self /= Self_ID
1295 -- Asynchronous_Call or Conditional_Call
1298 -- Because of ATCB lock ordering rule
1300 STPO.Write_Lock (Entry_Call.Self);
1302 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1304 -- Caller may not yet have reached wait-point
1306 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1309 STPO.Unlock (Entry_Call.Self);
1313 -- Conditional_Call and With_Abort
1315 STPO.Unlock (Acceptor);
1317 if Parent_Locked then
1318 STPO.Unlock (Parent);
1321 STPO.Write_Lock (Entry_Call.Self);
1323 pragma Assert (Entry_Call.State >= Was_Abortable);
1325 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1326 STPO.Unlock (Entry_Call.Self);
1330 end Task_Do_Or_Queue;
1332 ---------------------
1333 -- Task_Entry_Call --
1334 ---------------------
1336 procedure Task_Entry_Call
1337 (Acceptor : Task_Id;
1338 E : Task_Entry_Index;
1339 Uninterpreted_Data : System.Address;
1341 Rendezvous_Successful : out Boolean)
1343 Self_Id : constant Task_Id := STPO.Self;
1344 Entry_Call : Entry_Call_Link;
1347 -- If pragma Detect_Blocking is active then Program_Error must be
1348 -- raised if this potentially blocking operation is called from a
1349 -- protected action.
1351 if System.Tasking.Detect_Blocking
1352 and then Self_Id.Common.Protected_Action_Nesting > 0
1354 Ada.Exceptions.Raise_Exception
1355 (Program_Error'Identity, "potentially blocking operation");
1358 if Parameters.Runtime_Traces then
1359 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1362 if Mode = Simple_Call or else Mode = Conditional_Call then
1364 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1367 -- This is an asynchronous call
1369 -- Abort must already be deferred by the compiler-generated code.
1370 -- Without this, an abort that occurs between the time that this
1371 -- call is made and the time that the abortable part's cleanup
1372 -- handler is set up might miss the cleanup handler and leave the
1375 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1377 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1378 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1379 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1380 Entry_Call.Next := null;
1381 Entry_Call.Mode := Mode;
1382 Entry_Call.Cancellation_Attempted := False;
1383 Entry_Call.State := Not_Yet_Abortable;
1384 Entry_Call.E := Entry_Index (E);
1385 Entry_Call.Prio := Get_Priority (Self_Id);
1386 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1387 Entry_Call.Called_Task := Acceptor;
1388 Entry_Call.Called_PO := Null_Address;
1389 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1390 Entry_Call.With_Abort := True;
1396 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1397 STPO.Write_Lock (Self_Id);
1398 Utilities.Exit_One_ATC_Level (Self_Id);
1399 STPO.Unlock (Self_Id);
1405 Initialization.Undefer_Abort (Self_Id);
1407 if Parameters.Runtime_Traces then
1408 Send_Trace_Info (E_Missed, Acceptor);
1411 raise Tasking_Error;
1414 -- The following is special for async. entry calls.
1415 -- If the call was not queued abortably, we need to wait until
1416 -- it is before proceeding with the abortable part.
1418 -- Wait_Until_Abortable can be called unconditionally here,
1419 -- but it is expensive.
1421 if Entry_Call.State < Was_Abortable then
1422 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1429 -- Note: following assignment needs to be atomic
1431 Rendezvous_Successful := Entry_Call.State = Done;
1433 end Task_Entry_Call;
1435 -----------------------
1436 -- Task_Entry_Caller --
1437 -----------------------
1439 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1440 Self_Id : constant Task_Id := STPO.Self;
1441 Entry_Call : Entry_Call_Link;
1444 Entry_Call := Self_Id.Common.Call;
1446 for Depth in 1 .. D loop
1447 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1448 pragma Assert (Entry_Call /= null);
1451 return Entry_Call.Self;
1452 end Task_Entry_Caller;
1454 --------------------------
1455 -- Timed_Selective_Wait --
1456 --------------------------
1458 procedure Timed_Selective_Wait
1459 (Open_Accepts : Accept_List_Access;
1460 Select_Mode : Select_Modes;
1461 Uninterpreted_Data : out System.Address;
1464 Index : out Select_Index)
1466 Self_Id : constant Task_Id := STPO.Self;
1467 Treatment : Select_Treatment;
1468 Entry_Call : Entry_Call_Link;
1470 Selection : Select_Index;
1471 Open_Alternative : Boolean;
1472 Timedout : Boolean := False;
1473 Yielded : Boolean := True;
1476 pragma Assert (Select_Mode = Delay_Mode);
1478 Initialization.Defer_Abort (Self_Id);
1480 -- If we are aborted here, the effect will be pending
1486 STPO.Write_Lock (Self_Id);
1488 if not Self_Id.Callable then
1489 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1491 pragma Assert (Self_Id.Pending_Action);
1493 STPO.Unlock (Self_Id);
1499 Initialization.Undefer_Abort (Self_Id);
1501 -- Should never get here ???
1503 pragma Assert (False);
1504 raise Standard'Abort_Signal;
1507 Uninterpreted_Data := Null_Address;
1509 pragma Assert (Open_Accepts /= null);
1511 Queuing.Select_Task_Entry_Call
1512 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1514 -- Determine the kind and disposition of the select
1516 Treatment := Default_Treatment (Select_Mode);
1517 Self_Id.Chosen_Index := No_Rendezvous;
1519 if Open_Alternative then
1520 if Entry_Call /= null then
1521 if Open_Accepts (Selection).Null_Body then
1522 Treatment := Accept_Alternative_Completed;
1525 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1526 Treatment := Accept_Alternative_Selected;
1529 Self_Id.Chosen_Index := Selection;
1531 elsif Treatment = No_Alternative_Open then
1532 Treatment := Accept_Alternative_Open;
1536 -- Handle the select according to the disposition selected above
1539 when Accept_Alternative_Selected =>
1540 -- Ready to rendezvous
1541 -- In this case the accept body is not Null_Body. Defer abort
1542 -- until it gets into the accept body.
1544 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1545 Initialization.Defer_Abort (Self_Id);
1546 STPO.Unlock (Self_Id);
1548 when Accept_Alternative_Completed =>
1549 -- Rendezvous is over
1551 if Parameters.Runtime_Traces then
1552 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1555 STPO.Unlock (Self_Id);
1556 Caller := Entry_Call.Self;
1558 STPO.Write_Lock (Caller);
1559 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1560 STPO.Unlock (Caller);
1562 when Accept_Alternative_Open =>
1566 Self_Id.Open_Accepts := Open_Accepts;
1568 -- Wait for a normal call and a pending action until the
1569 -- Wakeup_Time is reached.
1571 Self_Id.Common.State := Acceptor_Sleep;
1573 -- Try to remove calls to Sleep in the loop below by letting the
1574 -- caller a chance of getting ready immediately, using Unlock
1575 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1583 if Self_Id.Open_Accepts /= null then
1590 Write_Lock (Self_Id);
1593 -- Check if this task has been aborted while the lock was released
1595 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1596 Self_Id.Open_Accepts := null;
1600 exit when Self_Id.Open_Accepts = null;
1603 Sleep (Self_Id, Acceptor_Sleep);
1605 if Parameters.Runtime_Traces then
1606 Send_Trace_Info (WT_Select,
1608 Integer (Open_Accepts'Length),
1612 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1613 Acceptor_Sleep, Timedout, Yielded);
1617 Self_Id.Open_Accepts := null;
1619 if Parameters.Runtime_Traces then
1620 Send_Trace_Info (E_Timeout);
1625 Self_Id.Common.State := Runnable;
1627 -- Self_Id.Common.Call should already be updated by the Caller if
1628 -- not aborted. It might also be ready to do rendezvous even if
1629 -- this wakes up due to an abort. Therefore, if the call is not
1630 -- empty we need to do the rendezvous if the accept body is not
1633 if Self_Id.Chosen_Index /= No_Rendezvous
1634 and then Self_Id.Common.Call /= null
1635 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1637 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1639 pragma Assert (Self_Id.Deferral_Level = 1);
1641 Initialization.Defer_Abort_Nestable (Self_Id);
1643 -- Leave abort deferred until the accept body
1646 STPO.Unlock (Self_Id);
1648 when No_Alternative_Open =>
1649 -- In this case, Index will be No_Rendezvous on return. We sleep
1650 -- for the time we need to.
1651 -- Wait for a signal or timeout. A wakeup can be made
1652 -- for several reasons:
1653 -- 1) Delay is expired
1654 -- 2) Pending_Action needs to be checked
1655 -- (Abort, Priority change)
1656 -- 3) Spurious wakeup
1658 Self_Id.Open_Accepts := null;
1659 Self_Id.Common.State := Acceptor_Sleep;
1661 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Sleep,
1664 Self_Id.Common.State := Runnable;
1666 STPO.Unlock (Self_Id);
1669 -- Should never get here
1670 pragma Assert (False);
1682 -- Caller has been chosen
1684 -- Self_Id.Common.Call should already be updated by the Caller
1686 -- Self_Id.Chosen_Index should either be updated by the Caller
1687 -- or by Test_Selective_Wait
1689 Index := Self_Id.Chosen_Index;
1690 Initialization.Undefer_Abort_Nestable (Self_Id);
1692 -- Start rendezvous, if not already completed
1693 end Timed_Selective_Wait;
1695 ---------------------------
1696 -- Timed_Task_Entry_Call --
1697 ---------------------------
1699 procedure Timed_Task_Entry_Call
1700 (Acceptor : Task_Id;
1701 E : Task_Entry_Index;
1702 Uninterpreted_Data : System.Address;
1705 Rendezvous_Successful : out Boolean)
1707 Self_Id : constant Task_Id := STPO.Self;
1709 Entry_Call : Entry_Call_Link;
1712 pragma Unreferenced (Yielded);
1715 -- If pragma Detect_Blocking is active then Program_Error must be
1716 -- raised if this potentially blocking operation is called from a
1717 -- protected action.
1719 if System.Tasking.Detect_Blocking
1720 and then Self_Id.Common.Protected_Action_Nesting > 0
1722 Ada.Exceptions.Raise_Exception
1723 (Program_Error'Identity, "potentially blocking operation");
1726 Initialization.Defer_Abort (Self_Id);
1727 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1730 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1731 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1733 if Parameters.Runtime_Traces then
1734 Send_Trace_Info (WT_Call, Acceptor,
1735 Entry_Index (E), Timeout);
1738 Level := Self_Id.ATC_Nesting_Level;
1739 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1740 Entry_Call.Next := null;
1741 Entry_Call.Mode := Timed_Call;
1742 Entry_Call.Cancellation_Attempted := False;
1744 -- If this is a call made inside of an abort deferred region,
1745 -- the call should be never abortable.
1747 if Self_Id.Deferral_Level > 1 then
1748 Entry_Call.State := Never_Abortable;
1750 Entry_Call.State := Now_Abortable;
1753 Entry_Call.E := Entry_Index (E);
1754 Entry_Call.Prio := Get_Priority (Self_Id);
1755 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1756 Entry_Call.Called_Task := Acceptor;
1757 Entry_Call.Called_PO := Null_Address;
1758 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1759 Entry_Call.With_Abort := True;
1761 -- Note: the caller will undefer abort on return (see WARNING above)
1767 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1768 STPO.Write_Lock (Self_Id);
1769 Utilities.Exit_One_ATC_Level (Self_Id);
1770 STPO.Unlock (Self_Id);
1776 Initialization.Undefer_Abort (Self_Id);
1778 if Parameters.Runtime_Traces then
1779 Send_Trace_Info (E_Missed, Acceptor);
1781 raise Tasking_Error;
1784 Write_Lock (Self_Id);
1785 Entry_Calls.Wait_For_Completion_With_Timeout
1786 (Entry_Call, Timeout, Mode, Yielded);
1793 -- ??? Do we need to yield in case Yielded is False
1795 Rendezvous_Successful := Entry_Call.State = Done;
1796 Initialization.Undefer_Abort (Self_Id);
1797 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1798 end Timed_Task_Entry_Call;
1804 procedure Wait_For_Call (Self_Id : Task_Id) is
1806 Self_Id.Common.State := Acceptor_Sleep;
1808 -- Try to remove calls to Sleep in the loop below by letting the caller
1809 -- a chance of getting ready immediately, using Unlock & Yield.
1810 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1818 if Self_Id.Open_Accepts /= null then
1825 Write_Lock (Self_Id);
1828 -- Check if this task has been aborted while the lock was released
1830 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1831 Self_Id.Open_Accepts := null;
1835 exit when Self_Id.Open_Accepts = null;
1836 Sleep (Self_Id, Acceptor_Sleep);
1839 Self_Id.Common.State := Runnable;
1842 end System.Tasking.Rendezvous;