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-2014, 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");
550 use type STPE
.Protection_Entries_Access
;
553 -- The deferral level is critical here, since we want to raise an
554 -- exception or allow abort to take place, if there is an exception or
558 (Debug
.Trace
(Self_Id
, "Local_Complete_Rendezvous", 'R'));
560 if Ex
= Ada
.Exceptions
.Null_Id
then
562 -- The call came from normal end-of-rendezvous, so abort is not yet
565 if Parameters
.Runtime_Traces
then
566 Send_Trace_Info
(M_RDV_Complete
, Entry_Call
.Self
);
569 Initialization
.Defer_Abort
(Self_Id
);
571 elsif ZCX_By_Default
then
573 -- With ZCX, aborts are not automatically deferred in handlers
575 Initialization
.Defer_Abort
(Self_Id
);
578 -- We need to clean up any accepts which Self may have been serving when
581 if Ex
= Standard
'Abort_Signal'Identity then
586 while Entry_Call /= null loop
587 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
589 -- All forms of accept make sure that the acceptor is not
590 -- completed, before accepting further calls, so that we
591 -- can be sure that no further calls are made after the
592 -- current calls are purged.
594 Caller := Entry_Call.Self;
596 -- Take write lock. This follows the lock precedence rule that
597 -- Caller may be locked while holding lock of Acceptor. Complete
598 -- the call abnormally, with exception.
600 STPO.Write_Lock (Caller);
601 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
602 STPO.Unlock (Caller);
603 Entry_Call := Entry_Call.Acceptor_Prev_Call;
611 Caller := Entry_Call.Self;
613 if Entry_Call.Needs_Requeue then
615 -- We dare not lock Self_Id at the same time as Caller, for fear
618 Entry_Call.Needs_Requeue := False;
619 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
621 if Entry_Call.Called_Task /= null then
623 -- Requeue to another task entry
629 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
634 Initialization.Undefer_Abort (Self_Id);
643 -- Requeue to a protected entry
645 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
646 STPE.Lock_Entries_With_Status (Called_PO, Ceiling_Violation);
648 if Ceiling_Violation then
649 pragma Assert (Ex = Ada.Exceptions.Null_Id);
650 Entry_Call.Exception_To_Raise := Program_Error'Identity;
656 STPO.Write_Lock (Caller);
657 Initialization.Wakeup_Entry_Caller
658 (Self_Id, Entry_Call, Done);
659 STPO.Unlock (Caller);
666 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
667 POO.PO_Service_Entries (Self_Id, Called_PO);
671 Entry_Calls.Reset_Priority
672 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
675 -- The call does not need to be requeued
677 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
678 Entry_Call.Exception_To_Raise := Ex;
684 STPO.Write_Lock (Caller);
686 -- Done with Caller locked to make sure that Wakeup is not lost
688 if Ex /= Ada.Exceptions.Null_Id then
690 (Caller.Common.Compiler_Data.Current_Excep'Access,
691 Self_Id.Common.Compiler_Data.Current_Excep);
694 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
695 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
697 STPO.Unlock (Caller);
703 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
707 Initialization.Undefer_Abort (Self_Id);
708 end Local_Complete_Rendezvous;
710 -------------------------------------
711 -- Requeue_Protected_To_Task_Entry --
712 -------------------------------------
714 procedure Requeue_Protected_To_Task_Entry
715 (Object : STPE.Protection_Entries_Access;
717 E : Task_Entry_Index;
718 With_Abort : Boolean)
720 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
722 pragma Assert (STPO.Self.Deferral_Level > 0);
724 Entry_Call.E := Entry_Index (E);
725 Entry_Call.Called_Task := Acceptor;
726 Entry_Call.Called_PO := Null_Address;
727 Entry_Call.With_Abort := With_Abort;
728 Object.Call_In_Progress := null;
729 end Requeue_Protected_To_Task_Entry;
731 ------------------------
732 -- Requeue_Task_Entry --
733 ------------------------
735 procedure Requeue_Task_Entry
737 E : Task_Entry_Index;
738 With_Abort : Boolean)
740 Self_Id : constant Task_Id := STPO.Self;
741 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
743 Initialization.Defer_Abort (Self_Id);
744 Entry_Call.Needs_Requeue := True;
745 Entry_Call.With_Abort := With_Abort;
746 Entry_Call.E := Entry_Index (E);
747 Entry_Call.Called_Task := Acceptor;
748 Initialization.Undefer_Abort (Self_Id);
749 end Requeue_Task_Entry;
755 procedure Selective_Wait
756 (Open_Accepts : Accept_List_Access;
757 Select_Mode : Select_Modes;
758 Uninterpreted_Data : out System.Address;
759 Index : out Select_Index)
761 Self_Id : constant Task_Id := STPO.Self;
762 Entry_Call : Entry_Call_Link;
763 Treatment : Select_Treatment;
765 Selection : Select_Index;
766 Open_Alternative : Boolean;
769 Initialization.Defer_Abort (Self_Id);
775 STPO.Write_Lock (Self_Id);
777 if not Self_Id.Callable then
778 pragma Assert (Self_Id.Pending_ATC_Level = 0);
780 pragma Assert (Self_Id.Pending_Action);
782 STPO.Unlock (Self_Id);
788 -- ??? In some cases abort is deferred more than once. Need to
789 -- figure out why this happens.
791 if Self_Id.Deferral_Level > 1 then
792 Self_Id.Deferral_Level := 1;
795 Initialization.Undefer_Abort (Self_Id);
797 -- Should never get here ???
799 pragma Assert (False);
800 raise Standard'Abort_Signal;
803 pragma Assert (Open_Accepts /= null);
805 Uninterpreted_Data := Null_Address;
807 Queuing.Select_Task_Entry_Call
808 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
810 -- Determine the kind and disposition of the select
812 Treatment := Default_Treatment (Select_Mode);
813 Self_Id.Chosen_Index := No_Rendezvous;
815 if Open_Alternative then
816 if Entry_Call /= null then
817 if Open_Accepts (Selection).Null_Body then
818 Treatment := Accept_Alternative_Completed;
820 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
821 Treatment := Accept_Alternative_Selected;
824 Self_Id.Chosen_Index := Selection;
826 elsif Treatment = No_Alternative_Open then
827 Treatment := Accept_Alternative_Open;
831 -- Handle the select according to the disposition selected above
834 when Accept_Alternative_Selected =>
836 -- Ready to rendezvous
838 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
840 -- In this case the accept body is not Null_Body. Defer abort
841 -- until it gets into the accept body. The compiler has inserted
842 -- a call to Abort_Undefer as part of the entry expansion.
844 pragma Assert (Self_Id.Deferral_Level = 1);
846 Initialization.Defer_Abort_Nestable (Self_Id);
847 STPO.Unlock (Self_Id);
849 when Accept_Alternative_Completed =>
851 -- Accept body is null, so rendezvous is over immediately
853 if Parameters.Runtime_Traces then
854 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
857 STPO.Unlock (Self_Id);
858 Caller := Entry_Call.Self;
860 STPO.Write_Lock (Caller);
861 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
862 STPO.Unlock (Caller);
864 when Accept_Alternative_Open =>
868 Self_Id.Open_Accepts := Open_Accepts;
870 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R
'));
872 if Parameters.Runtime_Traces then
873 Send_Trace_Info (W_Select, Self_Id,
874 Integer (Open_Accepts'Length));
877 Wait_For_Call (Self_Id);
879 pragma Assert (Self_Id.Open_Accepts = null);
881 -- Self_Id.Common.Call should already be updated by the Caller if
882 -- not aborted. It might also be ready to do rendezvous even if
883 -- this wakes up due to an abort. Therefore, if the call is not
884 -- empty we need to do the rendezvous if the accept body is not
887 -- Aren't the first two conditions below redundant???
889 if Self_Id.Chosen_Index /= No_Rendezvous
890 and then Self_Id.Common.Call /= null
891 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
893 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
896 (Self_Id.Deferral_Level = 1
898 (Self_Id.Deferral_Level = 0
899 and then not Restrictions.Abort_Allowed));
901 Initialization.Defer_Abort_Nestable (Self_Id);
903 -- Leave abort deferred until the accept body
904 -- The compiler has inserted a call to Abort_Undefer as part of
905 -- the entry expansion.
908 STPO.Unlock (Self_Id);
910 when Else_Selected =>
911 pragma Assert (Self_Id.Open_Accepts = null);
913 if Parameters.Runtime_Traces then
914 Send_Trace_Info (M_Select_Else);
917 STPO.Unlock (Self_Id);
919 when Terminate_Selected =>
921 -- Terminate alternative is open
923 Self_Id.Open_Accepts := Open_Accepts;
924 Self_Id.Common.State := Acceptor_Sleep;
926 -- Notify ancestors that this task is on a terminate alternative
928 STPO.Unlock (Self_Id);
929 Utilities.Make_Passive (Self_Id, Task_Completed => False);
930 STPO.Write_Lock (Self_Id);
932 -- Wait for normal entry call or termination
934 Wait_For_Call (Self_Id);
936 pragma Assert (Self_Id.Open_Accepts = null);
938 if Self_Id.Terminate_Alternative then
940 -- An entry call should have reset this to False, so we must be
941 -- aborted. We cannot be in an async. select, since that is not
942 -- legal, so the abort must be of the entire task. Therefore,
943 -- we do not need to cancel the terminate alternative. The
944 -- cleanup will be done in Complete_Master.
946 pragma Assert (Self_Id.Pending_ATC_Level = 0);
947 pragma Assert (Self_Id.Awake_Count = 0);
949 STPO.Unlock (Self_Id);
955 Index := Self_Id.Chosen_Index;
956 Initialization.Undefer_Abort_Nestable (Self_Id);
958 if Self_Id.Pending_Action then
959 Initialization.Do_Pending_Action (Self_Id);
965 -- Self_Id.Common.Call and Self_Id.Chosen_Index
966 -- should already be updated by the Caller.
968 if Self_Id.Chosen_Index /= No_Rendezvous
969 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
971 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
973 pragma Assert (Self_Id.Deferral_Level = 1);
975 -- We need an extra defer here, to keep abort
976 -- deferred until we get into the accept body
977 -- The compiler has inserted a call to Abort_Undefer as part
978 -- of the entry expansion.
980 Initialization.Defer_Abort_Nestable (Self_Id);
984 STPO.Unlock (Self_Id);
986 when No_Alternative_Open =>
988 -- In this case, Index will be No_Rendezvous on return, which
989 -- should cause a Program_Error if it is not a Delay_Mode.
991 -- If delay alternative exists (Delay_Mode) we should suspend
992 -- until the delay expires.
994 Self_Id.Open_Accepts := null;
996 if Select_Mode = Delay_Mode then
997 Self_Id.Common.State := Delay_Sleep;
1001 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
1002 Sleep (Self_Id, Delay_Sleep);
1005 Self_Id.Common.State := Runnable;
1006 STPO.Unlock (Self_Id);
1009 STPO.Unlock (Self_Id);
1015 Initialization.Undefer_Abort (Self_Id);
1016 raise Program_Error with
1017 "entry call not a delay mode";
1025 -- Caller has been chosen
1027 -- Self_Id.Common.Call should already be updated by the Caller.
1029 -- Self_Id.Chosen_Index should either be updated by the Caller
1030 -- or by Test_Selective_Wait.
1032 -- On return, we sill start rendezvous unless the accept body is
1033 -- null. In the latter case, we will have already completed the RV.
1035 Index := Self_Id.Chosen_Index;
1036 Initialization.Undefer_Abort_Nestable (Self_Id);
1039 ------------------------------------
1040 -- Setup_For_Rendezvous_With_Body --
1041 ------------------------------------
1043 procedure Setup_For_Rendezvous_With_Body
1044 (Entry_Call : Entry_Call_Link;
1045 Acceptor : Task_Id) is
1047 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1048 Acceptor.Common.Call := Entry_Call;
1050 if Entry_Call.State = Now_Abortable then
1051 Entry_Call.State := Was_Abortable;
1054 Boost_Priority (Entry_Call, Acceptor);
1055 end Setup_For_Rendezvous_With_Body;
1061 function Task_Count (E : Task_Entry_Index) return Natural is
1062 Self_Id : constant Task_Id := STPO.Self;
1063 Return_Count : Natural;
1066 Initialization.Defer_Abort (Self_Id);
1072 STPO.Write_Lock (Self_Id);
1073 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1074 STPO.Unlock (Self_Id);
1080 Initialization.Undefer_Abort (Self_Id);
1082 return Return_Count;
1085 ----------------------
1086 -- Task_Do_Or_Queue --
1087 ----------------------
1089 function Task_Do_Or_Queue
1091 Entry_Call : Entry_Call_Link) return Boolean
1093 E : constant Task_Entry_Index :=
1094 Task_Entry_Index (Entry_Call.E);
1095 Old_State : constant Entry_Call_State := Entry_Call.State;
1096 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1097 Parent : constant Task_Id := Acceptor.Common.Parent;
1098 Null_Body : Boolean;
1101 -- Find out whether Entry_Call can be accepted immediately
1103 -- If the Acceptor is not callable, return False.
1104 -- If the rendezvous can start, initiate it.
1105 -- If the accept-body is trivial, also complete the rendezvous.
1106 -- If the acceptor is not ready, enqueue the call.
1108 -- This should have a special case for Accept_Call and Accept_Trivial,
1109 -- so that we don't have the loop setup overhead, below.
1111 -- The call state Done is used here and elsewhere to include both the
1112 -- case of normal successful completion, and the case of an exception
1113 -- being raised. The difference is that if an exception is raised no one
1114 -- will pay attention to the fact that State = Done. Instead the
1115 -- exception will be raised in Undefer_Abort, and control will skip past
1116 -- the place where we normally would resume from an entry call.
1118 pragma Assert (not Queuing.Onqueue (Entry_Call));
1120 -- We rely that the call is off-queue for protection, that the caller
1121 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1122 -- record for another call. We rely on the Caller's lock for call State
1125 -- If Acceptor.Terminate_Alternative is True, we need to lock Parent and
1126 -- Acceptor, in that order; otherwise, we only need a lock on Acceptor.
1127 -- However, we can't check Acceptor.Terminate_Alternative until Acceptor
1128 -- is locked. Therefore, we need to lock both. Attempts to avoid locking
1129 -- Parent tend to result in race conditions. It would work to unlock
1130 -- Parent immediately upon finding Acceptor.Terminate_Alternative to be
1131 -- False, but that violates the rule of properly nested locking (see
1134 STPO.Write_Lock (Parent);
1135 STPO.Write_Lock (Acceptor);
1137 -- If the acceptor is not callable, abort the call and return False
1139 if not Acceptor.Callable then
1140 STPO.Unlock (Acceptor);
1141 STPO.Unlock (Parent);
1143 pragma Assert (Entry_Call.State < Done);
1145 -- In case we are not the caller, set up the caller
1146 -- to raise Tasking_Error when it wakes up.
1148 STPO.Write_Lock (Entry_Call.Self);
1149 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1150 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1151 STPO.Unlock (Entry_Call.Self);
1156 -- Try to serve the call immediately
1158 if Acceptor.Open_Accepts /= null then
1159 for J in Acceptor.Open_Accepts'Range loop
1160 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1162 -- Commit acceptor to rendezvous with us
1164 Acceptor.Chosen_Index := J;
1165 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1166 Acceptor.Open_Accepts := null;
1168 -- Prevent abort while call is being served
1170 if Entry_Call.State = Now_Abortable then
1171 Entry_Call.State := Was_Abortable;
1174 if Acceptor.Terminate_Alternative then
1176 -- Cancel terminate alternative. See matching code in
1177 -- Selective_Wait and Vulnerable_Complete_Master.
1179 Acceptor.Terminate_Alternative := False;
1180 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1182 if Acceptor.Awake_Count = 1 then
1184 -- Notify parent that acceptor is awake
1186 pragma Assert (Parent.Awake_Count > 0);
1188 Parent.Awake_Count := Parent.Awake_Count + 1;
1190 if Parent.Common.State = Master_Completion_Sleep
1191 and then Acceptor.Master_of_Task = Parent.Master_Within
1193 Parent.Common.Wait_Count :=
1194 Parent.Common.Wait_Count + 1;
1201 -- Rendezvous is over immediately
1203 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1204 STPO.Unlock (Acceptor);
1205 STPO.Unlock (Parent);
1207 STPO.Write_Lock (Entry_Call.Self);
1208 Initialization.Wakeup_Entry_Caller
1209 (Self_ID, Entry_Call, Done);
1210 STPO.Unlock (Entry_Call.Self);
1213 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1215 -- For terminate_alternative, acceptor may not be asleep
1216 -- yet, so we skip the wakeup
1218 if Acceptor.Common.State /= Runnable then
1219 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1222 STPO.Unlock (Acceptor);
1223 STPO.Unlock (Parent);
1230 -- The acceptor is accepting, but not this entry
1233 -- If the acceptor was ready to accept this call,
1234 -- we would not have gotten this far, so now we should
1235 -- (re)enqueue the call, if the mode permits that.
1237 -- If the call is timed, it may have timed out before the requeue,
1238 -- in the unusual case where the current accept has taken longer than
1239 -- the given delay. In that case the requeue is cancelled, and the
1240 -- outer timed call will be aborted.
1242 if Entry_Call.Mode = Conditional_Call
1244 (Entry_Call.Mode = Timed_Call
1245 and then Entry_Call.With_Abort
1246 and then Entry_Call.Cancellation_Attempted)
1248 STPO.Unlock (Acceptor);
1249 STPO.Unlock (Parent);
1251 STPO.Write_Lock (Entry_Call.Self);
1253 pragma Assert (Entry_Call.State >= Was_Abortable);
1255 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1256 STPO.Unlock (Entry_Call.Self);
1259 -- Timed_Call, Simple_Call, or Asynchronous_Call
1261 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1263 -- Update abortability of call
1265 pragma Assert (Old_State < Done);
1268 New_State (Entry_Call.With_Abort, Entry_Call.State);
1270 STPO.Unlock (Acceptor);
1271 STPO.Unlock (Parent);
1273 if Old_State /= Entry_Call.State
1274 and then Entry_Call.State = Now_Abortable
1275 and then Entry_Call.Mode /= Simple_Call
1276 and then Entry_Call.Self /= Self_ID
1278 -- Asynchronous_Call or Conditional_Call
1281 -- Because of ATCB lock ordering rule
1283 STPO.Write_Lock (Entry_Call.Self);
1285 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1287 -- Caller may not yet have reached wait-point
1289 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1292 STPO.Unlock (Entry_Call.Self);
1297 end Task_Do_Or_Queue;
1299 ---------------------
1300 -- Task_Entry_Call --
1301 ---------------------
1303 procedure Task_Entry_Call
1304 (Acceptor : Task_Id;
1305 E : Task_Entry_Index;
1306 Uninterpreted_Data : System.Address;
1308 Rendezvous_Successful : out Boolean)
1310 Self_Id : constant Task_Id := STPO.Self;
1311 Entry_Call : Entry_Call_Link;
1314 -- If pragma Detect_Blocking is active then Program_Error must be
1315 -- raised if this potentially blocking operation is called from a
1316 -- protected action.
1318 if System.Tasking.Detect_Blocking
1319 and then Self_Id.Common.Protected_Action_Nesting > 0
1321 raise Program_Error with
1322 "potentially blocking operation";
1325 if Parameters.Runtime_Traces then
1326 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1329 if Mode = Simple_Call or else Mode = Conditional_Call then
1331 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1334 -- This is an asynchronous call
1336 -- Abort must already be deferred by the compiler-generated code.
1337 -- Without this, an abort that occurs between the time that this
1338 -- call is made and the time that the abortable part's cleanup
1339 -- handler is set up might miss the cleanup handler and leave the
1342 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1344 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1345 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1346 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1347 Entry_Call.Next := null;
1348 Entry_Call.Mode := Mode;
1349 Entry_Call.Cancellation_Attempted := False;
1350 Entry_Call.State := Not_Yet_Abortable;
1351 Entry_Call.E := Entry_Index (E);
1352 Entry_Call.Prio := Get_Priority (Self_Id);
1353 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1354 Entry_Call.Called_Task := Acceptor;
1355 Entry_Call.Called_PO := Null_Address;
1356 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1357 Entry_Call.With_Abort := True;
1363 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1364 STPO.Write_Lock (Self_Id);
1365 Utilities.Exit_One_ATC_Level (Self_Id);
1366 STPO.Unlock (Self_Id);
1372 Initialization.Undefer_Abort (Self_Id);
1374 if Parameters.Runtime_Traces then
1375 Send_Trace_Info (E_Missed, Acceptor);
1378 raise Tasking_Error;
1381 -- The following is special for async. entry calls. If the call was
1382 -- not queued abortably, we need to wait until it is before
1383 -- proceeding with the abortable part.
1385 -- Wait_Until_Abortable can be called unconditionally here, but it is
1388 if Entry_Call.State < Was_Abortable then
1389 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1396 -- Note: following assignment needs to be atomic
1398 Rendezvous_Successful := Entry_Call.State = Done;
1400 end Task_Entry_Call;
1402 -----------------------
1403 -- Task_Entry_Caller --
1404 -----------------------
1406 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1407 Self_Id : constant Task_Id := STPO.Self;
1408 Entry_Call : Entry_Call_Link;
1411 Entry_Call := Self_Id.Common.Call;
1413 for Depth in 1 .. D loop
1414 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1415 pragma Assert (Entry_Call /= null);
1418 return Entry_Call.Self;
1419 end Task_Entry_Caller;
1421 --------------------------
1422 -- Timed_Selective_Wait --
1423 --------------------------
1425 procedure Timed_Selective_Wait
1426 (Open_Accepts : Accept_List_Access;
1427 Select_Mode : Select_Modes;
1428 Uninterpreted_Data : out System.Address;
1431 Index : out Select_Index)
1433 Self_Id : constant Task_Id := STPO.Self;
1434 Treatment : Select_Treatment;
1435 Entry_Call : Entry_Call_Link;
1437 Selection : Select_Index;
1438 Open_Alternative : Boolean;
1439 Timedout : Boolean := False;
1440 Yielded : Boolean := True;
1443 pragma Assert (Select_Mode = Delay_Mode);
1445 Initialization.Defer_Abort (Self_Id);
1447 -- If we are aborted here, the effect will be pending
1453 STPO.Write_Lock (Self_Id);
1455 if not Self_Id.Callable then
1456 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1458 pragma Assert (Self_Id.Pending_Action);
1460 STPO.Unlock (Self_Id);
1466 Initialization.Undefer_Abort (Self_Id);
1468 -- Should never get here ???
1470 pragma Assert (False);
1471 raise Standard'Abort_Signal;
1474 Uninterpreted_Data := Null_Address;
1476 pragma Assert (Open_Accepts /= null);
1478 Queuing.Select_Task_Entry_Call
1479 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1481 -- Determine the kind and disposition of the select
1483 Treatment := Default_Treatment (Select_Mode);
1484 Self_Id.Chosen_Index := No_Rendezvous;
1486 if Open_Alternative then
1487 if Entry_Call /= null then
1488 if Open_Accepts (Selection).Null_Body then
1489 Treatment := Accept_Alternative_Completed;
1492 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1493 Treatment := Accept_Alternative_Selected;
1496 Self_Id.Chosen_Index := Selection;
1498 elsif Treatment = No_Alternative_Open then
1499 Treatment := Accept_Alternative_Open;
1503 -- Handle the select according to the disposition selected above
1506 when Accept_Alternative_Selected =>
1508 -- Ready to rendezvous. In this case the accept body is not
1509 -- Null_Body. Defer abort until it gets into the accept body.
1511 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1512 Initialization.Defer_Abort_Nestable (Self_Id);
1513 STPO.Unlock (Self_Id);
1515 when Accept_Alternative_Completed =>
1517 -- Rendezvous is over
1519 if Parameters.Runtime_Traces then
1520 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1523 STPO.Unlock (Self_Id);
1524 Caller := Entry_Call.Self;
1526 STPO.Write_Lock (Caller);
1527 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1528 STPO.Unlock (Caller);
1530 when Accept_Alternative_Open =>
1534 Self_Id.Open_Accepts := Open_Accepts;
1536 -- Wait for a normal call and a pending action until the
1537 -- Wakeup_Time is reached.
1539 Self_Id.Common.State := Acceptor_Delay_Sleep;
1541 -- Try to remove calls to Sleep in the loop below by letting the
1542 -- caller a chance of getting ready immediately, using Unlock
1543 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1551 if Self_Id.Open_Accepts /= null then
1558 Write_Lock (Self_Id);
1561 -- Check if this task has been aborted while the lock was released
1563 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1564 Self_Id.Open_Accepts := null;
1568 exit when Self_Id.Open_Accepts = null;
1571 Sleep (Self_Id, Acceptor_Delay_Sleep);
1573 if Parameters.Runtime_Traces then
1574 Send_Trace_Info (WT_Select,
1576 Integer (Open_Accepts'Length),
1580 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1581 Acceptor_Delay_Sleep, Timedout, Yielded);
1585 Self_Id.Open_Accepts := null;
1587 if Parameters.Runtime_Traces then
1588 Send_Trace_Info (E_Timeout);
1593 Self_Id.Common.State := Runnable;
1595 -- Self_Id.Common.Call should already be updated by the Caller if
1596 -- not aborted. It might also be ready to do rendezvous even if
1597 -- this wakes up due to an abort. Therefore, if the call is not
1598 -- empty we need to do the rendezvous if the accept body is not
1601 if Self_Id.Chosen_Index /= No_Rendezvous
1602 and then Self_Id.Common.Call /= null
1603 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1605 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1607 pragma Assert (Self_Id.Deferral_Level = 1);
1609 Initialization.Defer_Abort_Nestable (Self_Id);
1611 -- Leave abort deferred until the accept body
1614 STPO.Unlock (Self_Id);
1616 when No_Alternative_Open =>
1618 -- In this case, Index will be No_Rendezvous on return. We sleep
1619 -- for the time we need to.
1621 -- Wait for a signal or timeout. A wakeup can be made
1622 -- for several reasons:
1623 -- 1) Delay is expired
1624 -- 2) Pending_Action needs to be checked
1625 -- (Abort, Priority change)
1626 -- 3) Spurious wakeup
1628 Self_Id.Open_Accepts := null;
1629 Self_Id.Common.State := Acceptor_Delay_Sleep;
1631 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Delay_Sleep,
1634 Self_Id.Common.State := Runnable;
1636 STPO.Unlock (Self_Id);
1640 -- Should never get here
1642 pragma Assert (False);
1654 -- Caller has been chosen
1656 -- Self_Id.Common.Call should already be updated by the Caller
1658 -- Self_Id.Chosen_Index should either be updated by the Caller
1659 -- or by Test_Selective_Wait
1661 Index := Self_Id.Chosen_Index;
1662 Initialization.Undefer_Abort_Nestable (Self_Id);
1664 -- Start rendezvous, if not already completed
1665 end Timed_Selective_Wait;
1667 ---------------------------
1668 -- Timed_Task_Entry_Call --
1669 ---------------------------
1671 procedure Timed_Task_Entry_Call
1672 (Acceptor : Task_Id;
1673 E : Task_Entry_Index;
1674 Uninterpreted_Data : System.Address;
1677 Rendezvous_Successful : out Boolean)
1679 Self_Id : constant Task_Id := STPO.Self;
1681 Entry_Call : Entry_Call_Link;
1684 pragma Unreferenced (Yielded);
1687 -- If pragma Detect_Blocking is active then Program_Error must be
1688 -- raised if this potentially blocking operation is called from a
1689 -- protected action.
1691 if System.Tasking.Detect_Blocking
1692 and then Self_Id.Common.Protected_Action_Nesting > 0
1694 raise Program_Error with
1695 "potentially blocking operation";
1698 Initialization.Defer_Abort (Self_Id);
1699 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1702 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1703 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1705 if Parameters.Runtime_Traces then
1706 Send_Trace_Info (WT_Call, Acceptor,
1707 Entry_Index (E), Timeout);
1710 Level := Self_Id.ATC_Nesting_Level;
1711 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1712 Entry_Call.Next := null;
1713 Entry_Call.Mode := Timed_Call;
1714 Entry_Call.Cancellation_Attempted := False;
1716 -- If this is a call made inside of an abort deferred region,
1717 -- the call should be never abortable.
1720 (if Self_Id.Deferral_Level > 1
1721 then Never_Abortable
1722 else Now_Abortable);
1724 Entry_Call.E := Entry_Index (E);
1725 Entry_Call.Prio := Get_Priority (Self_Id);
1726 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1727 Entry_Call.Called_Task := Acceptor;
1728 Entry_Call.Called_PO := Null_Address;
1729 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1730 Entry_Call.With_Abort := True;
1732 -- Note: the caller will undefer abort on return (see WARNING above)
1738 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1739 STPO.Write_Lock (Self_Id);
1740 Utilities.Exit_One_ATC_Level (Self_Id);
1741 STPO.Unlock (Self_Id);
1747 Initialization.Undefer_Abort (Self_Id);
1749 if Parameters.Runtime_Traces then
1750 Send_Trace_Info (E_Missed, Acceptor);
1752 raise Tasking_Error;
1755 Write_Lock (Self_Id);
1756 Entry_Calls.Wait_For_Completion_With_Timeout
1757 (Entry_Call, Timeout, Mode, Yielded);
1764 -- ??? Do we need to yield in case Yielded is False
1766 Rendezvous_Successful := Entry_Call.State = Done;
1767 Initialization.Undefer_Abort (Self_Id);
1768 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1769 end Timed_Task_Entry_Call;
1775 procedure Wait_For_Call (Self_Id : Task_Id) is
1777 Self_Id.Common.State := Acceptor_Sleep;
1779 -- Try to remove calls to Sleep in the loop below by letting the caller
1780 -- a chance of getting ready immediately, using Unlock & Yield.
1781 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1789 if Self_Id.Open_Accepts /= null then
1796 Write_Lock (Self_Id);
1799 -- Check if this task has been aborted while the lock was released
1801 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1802 Self_Id.Open_Accepts := null;
1806 exit when Self_Id.Open_Accepts = null;
1807 Sleep (Self_Id, Acceptor_Sleep);
1810 Self_Id.Common.State := Runnable;
1813 end System.Tasking.Rendezvous;