1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . R E N D E Z V O U S --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
32 with System
.Task_Primitives
.Operations
;
33 with System
.Tasking
.Entry_Calls
;
34 with System
.Tasking
.Initialization
;
35 with System
.Tasking
.Queuing
;
36 with System
.Tasking
.Utilities
;
37 with System
.Tasking
.Protected_Objects
.Operations
;
38 with System
.Tasking
.Debug
;
39 with System
.Restrictions
;
40 with System
.Parameters
;
41 with System
.Traces
.Tasking
;
43 package body System
.Tasking
.Rendezvous
is
45 package STPO
renames System
.Task_Primitives
.Operations
;
46 package POO
renames Protected_Objects
.Operations
;
47 package POE
renames Protected_Objects
.Entries
;
50 use Task_Primitives
.Operations
;
52 use System
.Traces
.Tasking
;
54 type Select_Treatment
is (
55 Accept_Alternative_Selected
, -- alternative with non-null body
56 Accept_Alternative_Completed
, -- alternative with null body
59 Accept_Alternative_Open
,
66 Default_Treatment
: constant array (Select_Modes
) of Select_Treatment
:=
67 (Simple_Mode
=> No_Alternative_Open
,
68 Else_Mode
=> Else_Selected
,
69 Terminate_Mode
=> Terminate_Selected
,
70 Delay_Mode
=> No_Alternative_Open
);
72 New_State
: constant array (Boolean, Entry_Call_State
)
73 of Entry_Call_State
:=
75 (Never_Abortable
=> Never_Abortable
,
76 Not_Yet_Abortable
=> Now_Abortable
,
77 Was_Abortable
=> Now_Abortable
,
78 Now_Abortable
=> Now_Abortable
,
80 Cancelled
=> Cancelled
),
82 (Never_Abortable
=> Never_Abortable
,
83 Not_Yet_Abortable
=> Not_Yet_Abortable
,
84 Was_Abortable
=> Was_Abortable
,
85 Now_Abortable
=> Now_Abortable
,
87 Cancelled
=> Cancelled
)
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Local_Defer_Abort
(Self_Id
: Task_Id
) renames
95 System
.Tasking
.Initialization
.Defer_Abort_Nestable
;
97 procedure Local_Undefer_Abort
(Self_Id
: Task_Id
) renames
98 System
.Tasking
.Initialization
.Undefer_Abort_Nestable
;
100 -- Florist defers abort around critical sections that
101 -- make entry calls to the Interrupt_Manager task, which
102 -- violates the general rule about top-level runtime system
103 -- calls from abort-deferred regions. It is not that this is
104 -- unsafe, but when it occurs in "normal" programs it usually
105 -- means either the user is trying to do a potentially blocking
106 -- operation from within a protected object, or there is a
107 -- runtime system/compiler error that has failed to undefer
108 -- an earlier abort deferral. Thus, for debugging it may be
109 -- wise to modify the above renamings to the non-nestable forms.
111 procedure Boost_Priority
(Call
: Entry_Call_Link
; Acceptor
: Task_Id
);
112 pragma Inline
(Boost_Priority
);
113 -- Call this only with abort deferred and holding lock of Acceptor
115 procedure Call_Synchronous
117 E
: Task_Entry_Index
;
118 Uninterpreted_Data
: System
.Address
;
120 Rendezvous_Successful
: out Boolean);
121 pragma Inline
(Call_Synchronous
);
122 -- This call is used to make a simple or conditional entry call.
123 -- Called from Call_Simple and Task_Entry_Call.
125 procedure Setup_For_Rendezvous_With_Body
126 (Entry_Call
: Entry_Call_Link
;
128 pragma Inline
(Setup_For_Rendezvous_With_Body
);
129 -- Call this only with abort deferred and holding lock of Acceptor.
130 -- When a rendezvous selected (ready for rendezvous) we need to save
131 -- previous caller and adjust the priority. Also we need to make
132 -- this call not Abortable (Cancellable) since the rendezvous has
133 -- already been started.
135 procedure Wait_For_Call
(Self_Id
: Task_Id
);
136 pragma Inline
(Wait_For_Call
);
137 -- Call this only with abort deferred and holding lock of Self_Id.
138 -- An accepting task goes into Sleep by calling this routine
139 -- waiting for a call from the caller or waiting for an abort.
140 -- Make sure Self_Id is locked before calling this routine.
146 procedure Accept_Call
147 (E
: Task_Entry_Index
;
148 Uninterpreted_Data
: out System
.Address
)
150 Self_Id
: constant Task_Id
:= STPO
.Self
;
151 Caller
: Task_Id
:= null;
152 Open_Accepts
: aliased Accept_List
(1 .. 1);
153 Entry_Call
: Entry_Call_Link
;
156 Initialization
.Defer_Abort
(Self_Id
);
162 STPO
.Write_Lock
(Self_Id
);
164 if not Self_Id
.Callable
then
165 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
167 pragma Assert
(Self_Id
.Pending_Action
);
169 STPO
.Unlock
(Self_Id
);
175 Initialization
.Undefer_Abort
(Self_Id
);
177 -- Should never get here ???
179 pragma Assert
(False);
180 raise Standard
'Abort_Signal;
183 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
185 if Entry_Call
/= null then
186 Caller
:= Entry_Call
.Self
;
187 Setup_For_Rendezvous_With_Body
(Entry_Call
, Self_Id
);
188 Uninterpreted_Data
:= Entry_Call
.Uninterpreted_Data
;
193 Open_Accepts
(1).Null_Body
:= False;
194 Open_Accepts
(1).S
:= E
;
195 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
197 -- Wait for normal call
199 if Parameters
.Runtime_Traces
then
200 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
204 (Debug
.Trace
(Self_Id
, "Accept_Call: wait", 'R'));
205 Wait_For_Call
(Self_Id
);
207 pragma Assert
(Self_Id
.Open_Accepts
= null);
209 if Self_Id
.Common
.Call
/= null then
210 Caller
:= Self_Id
.Common
.Call
.Self
;
211 Uninterpreted_Data
:=
212 Caller
.Entry_Calls
(Caller
.ATC_Nesting_Level
).Uninterpreted_Data
;
214 -- Case of an aborted task
216 Uninterpreted_Data
:= System
.Null_Address
;
220 -- Self_Id.Common.Call should already be updated by the Caller
221 -- On return, we will start the rendezvous.
223 STPO
.Unlock
(Self_Id
);
229 Initialization
.Undefer_Abort
(Self_Id
);
231 if Parameters
.Runtime_Traces
then
232 Send_Trace_Info
(M_Accept_Complete
, Caller
, Entry_Index
(E
));
240 procedure Accept_Trivial
(E
: Task_Entry_Index
) is
241 Self_Id
: constant Task_Id
:= STPO
.Self
;
242 Caller
: Task_Id
:= null;
243 Open_Accepts
: aliased Accept_List
(1 .. 1);
244 Entry_Call
: Entry_Call_Link
;
247 Initialization
.Defer_Abort_Nestable
(Self_Id
);
253 STPO
.Write_Lock
(Self_Id
);
255 if not Self_Id
.Callable
then
256 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
258 pragma Assert
(Self_Id
.Pending_Action
);
260 STPO
.Unlock
(Self_Id
);
266 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
268 -- Should never get here ???
270 pragma Assert
(False);
271 raise Standard
'Abort_Signal;
274 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
276 if Entry_Call
= null then
277 -- Need to wait for entry call
279 Open_Accepts
(1).Null_Body
:= True;
280 Open_Accepts
(1).S
:= E
;
281 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
283 if Parameters
.Runtime_Traces
then
284 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
288 (Debug
.Trace
(Self_Id
, "Accept_Trivial: wait", 'R'));
290 Wait_For_Call
(Self_Id
);
292 pragma Assert
(Self_Id
.Open_Accepts
= null);
294 -- No need to do anything special here for pending abort.
295 -- Abort_Signal will be raised by Undefer on exit.
297 STPO
.Unlock
(Self_Id
);
299 else -- found caller already waiting
300 pragma Assert
(Entry_Call
.State
< Done
);
302 STPO
.Unlock
(Self_Id
);
303 Caller
:= Entry_Call
.Self
;
305 STPO
.Write_Lock
(Caller
);
306 Initialization
.Wakeup_Entry_Caller
(Self_Id
, Entry_Call
, Done
);
307 STPO
.Unlock
(Caller
);
310 if Parameters
.Runtime_Traces
then
311 Send_Trace_Info
(M_Accept_Complete
);
313 -- Fake one, since there is (???) no way
314 -- to know that the rendezvous is over
316 Send_Trace_Info
(M_RDV_Complete
);
323 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
330 procedure Boost_Priority
(Call
: Entry_Call_Link
; Acceptor
: Task_Id
) is
331 Caller
: constant Task_Id
:= Call
.Self
;
332 Caller_Prio
: constant System
.Any_Priority
:= Get_Priority
(Caller
);
333 Acceptor_Prio
: constant System
.Any_Priority
:= Get_Priority
(Acceptor
);
336 if Caller_Prio
> Acceptor_Prio
then
337 Call
.Acceptor_Prev_Priority
:= Acceptor_Prio
;
338 Set_Priority
(Acceptor
, Caller_Prio
);
341 Call
.Acceptor_Prev_Priority
:= Priority_Not_Boosted
;
349 procedure Call_Simple
351 E
: Task_Entry_Index
;
352 Uninterpreted_Data
: System
.Address
)
354 Rendezvous_Successful
: Boolean;
355 pragma Unreferenced
(Rendezvous_Successful
);
358 -- If pragma Detect_Blocking is active then Program_Error must be
359 -- raised if this potentially blocking operation is called from a
362 if System
.Tasking
.Detect_Blocking
363 and then STPO
.Self
.Common
.Protected_Action_Nesting
> 0
365 raise Program_Error
with "potentially blocking operation";
369 (Acceptor
, E
, Uninterpreted_Data
, Simple_Call
, Rendezvous_Successful
);
372 ----------------------
373 -- Call_Synchronous --
374 ----------------------
376 procedure Call_Synchronous
378 E
: Task_Entry_Index
;
379 Uninterpreted_Data
: System
.Address
;
381 Rendezvous_Successful
: out Boolean)
383 Self_Id
: constant Task_Id
:= STPO
.Self
;
385 Entry_Call
: Entry_Call_Link
;
388 pragma Assert
(Mode
/= Asynchronous_Call
);
390 Local_Defer_Abort
(Self_Id
);
391 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
+ 1;
393 (Debug
.Trace
(Self_Id
, "CS: entered ATC level: " &
394 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
395 Level
:= Self_Id
.ATC_Nesting_Level
;
396 Entry_Call
:= Self_Id
.Entry_Calls
(Level
)'Access;
397 Entry_Call
.Next
:= null;
398 Entry_Call
.Mode
:= Mode
;
399 Entry_Call
.Cancellation_Attempted
:= False;
401 if Parameters
.Runtime_Traces
then
402 Send_Trace_Info
(W_Call
, Acceptor
, Entry_Index
(E
));
405 -- If this is a call made inside of an abort deferred region,
406 -- the call should be never abortable.
409 (if Self_Id
.Deferral_Level
> 1
413 Entry_Call
.E
:= Entry_Index
(E
);
414 Entry_Call
.Prio
:= Get_Priority
(Self_Id
);
415 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
416 Entry_Call
.Called_Task
:= Acceptor
;
417 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
418 Entry_Call
.With_Abort
:= True;
420 -- Note: the caller will undefer abort on return (see WARNING above)
426 if not Task_Do_Or_Queue
(Self_Id
, Entry_Call
) then
427 STPO
.Write_Lock
(Self_Id
);
428 Utilities
.Exit_One_ATC_Level
(Self_Id
);
429 STPO
.Unlock
(Self_Id
);
435 if Parameters
.Runtime_Traces
then
436 Send_Trace_Info
(E_Missed
, Acceptor
);
439 Local_Undefer_Abort
(Self_Id
);
443 STPO
.Write_Lock
(Self_Id
);
445 (Debug
.Trace
(Self_Id
, "Call_Synchronous: wait", 'R'));
446 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
448 (Debug
.Trace
(Self_Id
, "Call_Synchronous: done waiting", 'R'));
449 Rendezvous_Successful
:= Entry_Call
.State
= Done
;
450 STPO
.Unlock
(Self_Id
);
456 Local_Undefer_Abort
(Self_Id
);
457 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
458 end Call_Synchronous
;
464 function Callable
(T
: Task_Id
) return Boolean is
466 Self_Id
: constant Task_Id
:= STPO
.Self
;
469 Initialization
.Defer_Abort_Nestable
(Self_Id
);
476 Result
:= T
.Callable
;
483 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
487 ----------------------------
488 -- Cancel_Task_Entry_Call --
489 ----------------------------
491 procedure Cancel_Task_Entry_Call
(Cancelled
: out Boolean) is
493 Entry_Calls
.Try_To_Cancel_Entry_Call
(Cancelled
);
494 end Cancel_Task_Entry_Call
;
496 -------------------------
497 -- Complete_Rendezvous --
498 -------------------------
500 procedure Complete_Rendezvous
is
502 Exceptional_Complete_Rendezvous
(Ada
.Exceptions
.Null_Id
);
503 end Complete_Rendezvous
;
505 -------------------------------------
506 -- Exceptional_Complete_Rendezvous --
507 -------------------------------------
509 procedure Exceptional_Complete_Rendezvous
510 (Ex
: Ada
.Exceptions
.Exception_Id
)
512 Self_Id
: constant Task_Id
:= STPO
.Self
;
513 Entry_Call
: Entry_Call_Link
:= Self_Id
.Common
.Call
;
515 Called_PO
: STPE
.Protection_Entries_Access
;
516 Acceptor_Prev_Priority
: Integer;
518 Exception_To_Raise
: Ada
.Exceptions
.Exception_Id
:= Ex
;
519 Ceiling_Violation
: Boolean;
521 use type Ada
.Exceptions
.Exception_Id
;
522 procedure Internal_Reraise
;
523 pragma Import
(C
, Internal_Reraise
, "__gnat_reraise");
525 procedure Transfer_Occurrence
526 (Target
: Ada
.Exceptions
.Exception_Occurrence_Access
;
527 Source
: Ada
.Exceptions
.Exception_Occurrence
);
528 pragma Import
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
530 use type STPE
.Protection_Entries_Access
;
533 -- Consider phasing out Complete_Rendezvous in favor
534 -- of direct call to this with Ada.Exceptions.Null_ID.
535 -- See code expansion examples for Accept_Call and Selective_Wait.
536 -- Also consider putting an explicit re-raise after this call, in
537 -- the generated code. That way we could eliminate the
538 -- code here that reraises the exception.
540 -- The deferral level is critical here,
541 -- since we want to raise an exception or allow abort to take
542 -- place, if there is an exception or abort pending.
545 (Debug
.Trace
(Self_Id
, "Exceptional_Complete_Rendezvous", 'R'));
547 if Ex
= Ada
.Exceptions
.Null_Id
then
548 -- The call came from normal end-of-rendezvous,
549 -- so abort is not yet deferred.
551 if Parameters
.Runtime_Traces
then
552 Send_Trace_Info
(M_RDV_Complete
, Entry_Call
.Self
);
555 Initialization
.Defer_Abort_Nestable
(Self_Id
);
558 -- We need to clean up any accepts which Self may have
559 -- been serving when it was aborted.
561 if Ex
= Standard
'Abort_Signal'Identity then
566 while Entry_Call /= null loop
567 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
569 -- All forms of accept make sure that the acceptor is not
570 -- completed, before accepting further calls, so that we
571 -- can be sure that no further calls are made after the
572 -- current calls are purged.
574 Caller := Entry_Call.Self;
576 -- Take write lock. This follows the lock precedence rule that
577 -- Caller may be locked while holding lock of Acceptor.
578 -- Complete the call abnormally, with exception.
580 STPO.Write_Lock (Caller);
581 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
582 STPO.Unlock (Caller);
583 Entry_Call := Entry_Call.Acceptor_Prev_Call;
591 Caller := Entry_Call.Self;
593 if Entry_Call.Needs_Requeue then
594 -- We dare not lock Self_Id at the same time as Caller,
595 -- for fear of deadlock.
597 Entry_Call.Needs_Requeue := False;
598 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
600 if Entry_Call.Called_Task /= null then
601 -- Requeue to another task entry
607 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
612 Initialization.Undefer_Abort (Self_Id);
621 -- Requeue to a protected entry
623 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
624 STPE.Lock_Entries (Called_PO, Ceiling_Violation);
626 if Ceiling_Violation then
627 pragma Assert (Ex = Ada.Exceptions.Null_Id);
629 Exception_To_Raise := Program_Error'Identity;
630 Entry_Call.Exception_To_Raise := Exception_To_Raise;
636 STPO.Write_Lock (Caller);
637 Initialization.Wakeup_Entry_Caller
638 (Self_Id, Entry_Call, Done);
639 STPO.Unlock (Caller);
646 POO.PO_Do_Or_Queue (Self_Id, Called_PO, Entry_Call);
647 POO.PO_Service_Entries (Self_Id, Called_PO);
651 Entry_Calls.Reset_Priority
652 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
655 -- The call does not need to be requeued
657 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
658 Entry_Call.Exception_To_Raise := Ex;
664 STPO.Write_Lock (Caller);
666 -- Done with Caller locked to make sure that Wakeup is not lost
668 if Ex /= Ada.Exceptions.Null_Id then
670 (Caller.Common.Compiler_Data.Current_Excep'Access,
671 Self_Id.Common.Compiler_Data.Current_Excep);
674 Acceptor_Prev_Priority := Entry_Call.Acceptor_Prev_Priority;
675 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
677 STPO.Unlock (Caller);
683 Entry_Calls.Reset_Priority (Self_Id, Acceptor_Prev_Priority);
687 Initialization.Undefer_Abort (Self_Id);
689 if Exception_To_Raise /= Ada.Exceptions.Null_Id then
693 -- ??? Do we need to give precedence to Program_Error that might be
694 -- raised due to failure of finalization, over Tasking_Error from
695 -- failure of requeue?
696 end Exceptional_Complete_Rendezvous;
698 -------------------------------------
699 -- Requeue_Protected_To_Task_Entry --
700 -------------------------------------
702 procedure Requeue_Protected_To_Task_Entry
703 (Object : STPE.Protection_Entries_Access;
705 E : Task_Entry_Index;
706 With_Abort : Boolean)
708 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
710 pragma Assert (STPO.Self.Deferral_Level > 0);
712 Entry_Call.E := Entry_Index (E);
713 Entry_Call.Called_Task := Acceptor;
714 Entry_Call.Called_PO := Null_Address;
715 Entry_Call.With_Abort := With_Abort;
716 Object.Call_In_Progress := null;
717 end Requeue_Protected_To_Task_Entry;
719 ------------------------
720 -- Requeue_Task_Entry --
721 ------------------------
723 procedure Requeue_Task_Entry
725 E : Task_Entry_Index;
726 With_Abort : Boolean)
728 Self_Id : constant Task_Id := STPO.Self;
729 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
732 Initialization.Defer_Abort (Self_Id);
733 Entry_Call.Needs_Requeue := True;
734 Entry_Call.With_Abort := With_Abort;
735 Entry_Call.E := Entry_Index (E);
736 Entry_Call.Called_Task := Acceptor;
737 Initialization.Undefer_Abort (Self_Id);
738 end Requeue_Task_Entry;
744 procedure Selective_Wait
745 (Open_Accepts : Accept_List_Access;
746 Select_Mode : Select_Modes;
747 Uninterpreted_Data : out System.Address;
748 Index : out Select_Index)
750 Self_Id : constant Task_Id := STPO.Self;
751 Entry_Call : Entry_Call_Link;
752 Treatment : Select_Treatment;
754 Selection : Select_Index;
755 Open_Alternative : Boolean;
758 Initialization.Defer_Abort (Self_Id);
764 STPO.Write_Lock (Self_Id);
766 if not Self_Id.Callable then
767 pragma Assert (Self_Id.Pending_ATC_Level = 0);
769 pragma Assert (Self_Id.Pending_Action);
771 STPO.Unlock (Self_Id);
777 -- ??? In some cases abort is deferred more than once. Need to
778 -- figure out why this happens.
780 if Self_Id.Deferral_Level > 1 then
781 Self_Id.Deferral_Level := 1;
784 Initialization.Undefer_Abort (Self_Id);
786 -- Should never get here ???
788 pragma Assert (False);
789 raise Standard'Abort_Signal;
792 pragma Assert (Open_Accepts /= null);
794 Uninterpreted_Data := Null_Address;
796 Queuing.Select_Task_Entry_Call
797 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
799 -- Determine the kind and disposition of the select
801 Treatment := Default_Treatment (Select_Mode);
802 Self_Id.Chosen_Index := No_Rendezvous;
804 if Open_Alternative then
805 if Entry_Call /= null then
806 if Open_Accepts (Selection).Null_Body then
807 Treatment := Accept_Alternative_Completed;
809 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
810 Treatment := Accept_Alternative_Selected;
813 Self_Id.Chosen_Index := Selection;
815 elsif Treatment = No_Alternative_Open then
816 Treatment := Accept_Alternative_Open;
820 -- Handle the select according to the disposition selected above
823 when Accept_Alternative_Selected =>
824 -- Ready to rendezvous
826 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
828 -- In this case the accept body is not Null_Body. Defer abort
829 -- until it gets into the accept body.
831 pragma Assert (Self_Id.Deferral_Level = 1);
833 Initialization.Defer_Abort_Nestable (Self_Id);
834 STPO.Unlock (Self_Id);
836 when Accept_Alternative_Completed =>
838 -- Accept body is null, so rendezvous is over immediately
840 if Parameters.Runtime_Traces then
841 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
844 STPO.Unlock (Self_Id);
845 Caller := Entry_Call.Self;
847 STPO.Write_Lock (Caller);
848 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
849 STPO.Unlock (Caller);
851 when Accept_Alternative_Open =>
855 Self_Id.Open_Accepts := Open_Accepts;
857 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R
'));
859 if Parameters.Runtime_Traces then
860 Send_Trace_Info (W_Select, Self_Id,
861 Integer (Open_Accepts'Length));
864 Wait_For_Call (Self_Id);
866 pragma Assert (Self_Id.Open_Accepts = null);
868 -- Self_Id.Common.Call should already be updated by the Caller if
869 -- not aborted. It might also be ready to do rendezvous even if
870 -- this wakes up due to an abort. Therefore, if the call is not
871 -- empty we need to do the rendezvous if the accept body is not
874 -- Aren't the first two conditions below redundant???
876 if Self_Id.Chosen_Index /= No_Rendezvous
877 and then Self_Id.Common.Call /= null
878 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
880 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
883 (Self_Id.Deferral_Level = 1
885 (Self_Id.Deferral_Level = 0
886 and then not Restrictions.Abort_Allowed));
888 Initialization.Defer_Abort_Nestable (Self_Id);
890 -- Leave abort deferred until the accept body
893 STPO.Unlock (Self_Id);
895 when Else_Selected =>
896 pragma Assert (Self_Id.Open_Accepts = null);
898 if Parameters.Runtime_Traces then
899 Send_Trace_Info (M_Select_Else);
902 STPO.Unlock (Self_Id);
904 when Terminate_Selected =>
905 -- Terminate alternative is open
907 Self_Id.Open_Accepts := Open_Accepts;
908 Self_Id.Common.State := Acceptor_Sleep;
910 -- Notify ancestors that this task is on a terminate alternative
912 STPO.Unlock (Self_Id);
913 Utilities.Make_Passive (Self_Id, Task_Completed => False);
914 STPO.Write_Lock (Self_Id);
916 -- Wait for normal entry call or termination
918 Wait_For_Call (Self_Id);
920 pragma Assert (Self_Id.Open_Accepts = null);
922 if Self_Id.Terminate_Alternative then
923 -- An entry call should have reset this to False,
924 -- so we must be aborted.
925 -- We cannot be in an async. select, since that
926 -- is not legal, so the abort must be of the entire
927 -- task. Therefore, we do not need to cancel the
928 -- terminate alternative. The cleanup will be done
929 -- in Complete_Master.
931 pragma Assert (Self_Id.Pending_ATC_Level = 0);
932 pragma Assert (Self_Id.Awake_Count = 0);
934 STPO.Unlock (Self_Id);
940 Index := Self_Id.Chosen_Index;
941 Initialization.Undefer_Abort_Nestable (Self_Id);
943 if Self_Id.Pending_Action then
944 Initialization.Do_Pending_Action (Self_Id);
950 -- Self_Id.Common.Call and Self_Id.Chosen_Index
951 -- should already be updated by the Caller.
953 if Self_Id.Chosen_Index /= No_Rendezvous
954 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
956 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
958 pragma Assert (Self_Id.Deferral_Level = 1);
960 -- We need an extra defer here, to keep abort
961 -- deferred until we get into the accept body
963 Initialization.Defer_Abort_Nestable (Self_Id);
967 STPO.Unlock (Self_Id);
969 when No_Alternative_Open =>
970 -- In this case, Index will be No_Rendezvous on return, which
971 -- should cause a Program_Error if it is not a Delay_Mode.
973 -- If delay alternative exists (Delay_Mode) we should suspend
974 -- until the delay expires.
976 Self_Id.Open_Accepts := null;
978 if Select_Mode = Delay_Mode then
979 Self_Id.Common.State := Delay_Sleep;
983 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
984 Sleep (Self_Id, Delay_Sleep);
987 Self_Id.Common.State := Runnable;
988 STPO.Unlock (Self_Id);
991 STPO.Unlock (Self_Id);
997 Initialization.Undefer_Abort (Self_Id);
998 raise Program_Error with "Entry call not a delay mode";
1006 -- Caller has been chosen.
1007 -- Self_Id.Common.Call should already be updated by the Caller.
1008 -- Self_Id.Chosen_Index should either be updated by the Caller
1009 -- or by Test_Selective_Wait.
1010 -- On return, we sill start rendezvous unless the accept body is
1011 -- null. In the latter case, we will have already completed the RV.
1013 Index := Self_Id.Chosen_Index;
1014 Initialization.Undefer_Abort_Nestable (Self_Id);
1017 ------------------------------------
1018 -- Setup_For_Rendezvous_With_Body --
1019 ------------------------------------
1021 procedure Setup_For_Rendezvous_With_Body
1022 (Entry_Call : Entry_Call_Link;
1023 Acceptor : Task_Id) is
1025 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1026 Acceptor.Common.Call := Entry_Call;
1028 if Entry_Call.State = Now_Abortable then
1029 Entry_Call.State := Was_Abortable;
1032 Boost_Priority (Entry_Call, Acceptor);
1033 end Setup_For_Rendezvous_With_Body;
1039 function Task_Count (E : Task_Entry_Index) return Natural is
1040 Self_Id : constant Task_Id := STPO.Self;
1041 Return_Count : Natural;
1044 Initialization.Defer_Abort (Self_Id);
1050 STPO.Write_Lock (Self_Id);
1051 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1052 STPO.Unlock (Self_Id);
1058 Initialization.Undefer_Abort (Self_Id);
1060 -- Call Yield to let other tasks get a chance to run as this is a
1061 -- potential dispatching point.
1063 Yield (Do_Yield => False);
1064 return Return_Count;
1067 ----------------------
1068 -- Task_Do_Or_Queue --
1069 ----------------------
1071 function Task_Do_Or_Queue
1073 Entry_Call : Entry_Call_Link) return Boolean
1075 E : constant Task_Entry_Index :=
1076 Task_Entry_Index (Entry_Call.E);
1077 Old_State : constant Entry_Call_State := Entry_Call.State;
1078 Acceptor : constant Task_Id := Entry_Call.Called_Task;
1079 Parent : constant Task_Id := Acceptor.Common.Parent;
1080 Parent_Locked : Boolean := False;
1081 Null_Body : Boolean;
1084 -- Find out whether Entry_Call can be accepted immediately
1086 -- If the Acceptor is not callable, return False.
1087 -- If the rendezvous can start, initiate it.
1088 -- If the accept-body is trivial, also complete the rendezvous.
1089 -- If the acceptor is not ready, enqueue the call.
1091 -- This should have a special case for Accept_Call and Accept_Trivial,
1092 -- so that we don't have the loop setup overhead, below.
1094 -- The call state Done is used here and elsewhere to include both the
1095 -- case of normal successful completion, and the case of an exception
1096 -- being raised. The difference is that if an exception is raised no one
1097 -- will pay attention to the fact that State = Done. Instead the
1098 -- exception will be raised in Undefer_Abort, and control will skip past
1099 -- the place where we normally would resume from an entry call.
1101 pragma Assert (not Queuing.Onqueue (Entry_Call));
1103 -- We rely that the call is off-queue for protection, that the caller
1104 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1105 -- record for another call.
1106 -- We rely on the Caller's lock for call State mod's.
1108 -- We can't lock Acceptor.Parent while holding Acceptor,
1109 -- so lock it in advance if we expect to need to lock it.
1111 if Acceptor.Terminate_Alternative then
1112 STPO.Write_Lock (Parent);
1113 Parent_Locked := True;
1116 STPO.Write_Lock (Acceptor);
1118 -- If the acceptor is not callable, abort the call and return False
1120 if not Acceptor.Callable then
1121 STPO.Unlock (Acceptor);
1123 if Parent_Locked then
1124 STPO.Unlock (Parent);
1127 pragma Assert (Entry_Call.State < Done);
1129 -- In case we are not the caller, set up the caller
1130 -- to raise Tasking_Error when it wakes up.
1132 STPO.Write_Lock (Entry_Call.Self);
1133 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1134 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1135 STPO.Unlock (Entry_Call.Self);
1140 -- Try to serve the call immediately
1142 if Acceptor.Open_Accepts /= null then
1143 for J in Acceptor.Open_Accepts'Range loop
1144 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1146 -- Commit acceptor to rendezvous with us
1148 Acceptor.Chosen_Index := J;
1149 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1150 Acceptor.Open_Accepts := null;
1152 -- Prevent abort while call is being served
1154 if Entry_Call.State = Now_Abortable then
1155 Entry_Call.State := Was_Abortable;
1158 if Acceptor.Terminate_Alternative then
1160 -- Cancel terminate alternative. See matching code in
1161 -- Selective_Wait and Vulnerable_Complete_Master.
1163 Acceptor.Terminate_Alternative := False;
1164 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1166 if Acceptor.Awake_Count = 1 then
1168 -- Notify parent that acceptor is awake
1170 pragma Assert (Parent.Awake_Count > 0);
1172 Parent.Awake_Count := Parent.Awake_Count + 1;
1174 if Parent.Common.State = Master_Completion_Sleep
1175 and then Acceptor.Master_of_Task = Parent.Master_Within
1177 Parent.Common.Wait_Count :=
1178 Parent.Common.Wait_Count + 1;
1185 -- Rendezvous is over immediately
1187 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1188 STPO.Unlock (Acceptor);
1190 if Parent_Locked then
1191 STPO.Unlock (Parent);
1194 STPO.Write_Lock (Entry_Call.Self);
1195 Initialization.Wakeup_Entry_Caller
1196 (Self_ID, Entry_Call, Done);
1197 STPO.Unlock (Entry_Call.Self);
1200 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1202 -- For terminate_alternative, acceptor may not be asleep
1203 -- yet, so we skip the wakeup
1205 if Acceptor.Common.State /= Runnable then
1206 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1209 STPO.Unlock (Acceptor);
1211 if Parent_Locked then
1212 STPO.Unlock (Parent);
1220 -- The acceptor is accepting, but not this entry
1223 -- If the acceptor was ready to accept this call,
1224 -- we would not have gotten this far, so now we should
1225 -- (re)enqueue the call, if the mode permits that.
1227 -- If the call is timed, it may have timed out before the requeue,
1228 -- in the unusual case where the current accept has taken longer than
1229 -- the given delay. In that case the requeue is cancelled, and the
1230 -- outer timed call will be aborted.
1232 if Entry_Call.Mode = Conditional_Call
1234 (Entry_Call.Mode = Timed_Call
1235 and then Entry_Call.With_Abort
1236 and then Entry_Call.Cancellation_Attempted)
1238 STPO.Unlock (Acceptor);
1240 if Parent_Locked then
1241 STPO.Unlock (Parent);
1244 STPO.Write_Lock (Entry_Call.Self);
1246 pragma Assert (Entry_Call.State >= Was_Abortable);
1248 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1249 STPO.Unlock (Entry_Call.Self);
1252 -- Timed_Call, Simple_Call, or Asynchronous_Call
1254 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1256 -- Update abortability of call
1258 pragma Assert (Old_State < Done);
1261 New_State (Entry_Call.With_Abort, Entry_Call.State);
1263 STPO.Unlock (Acceptor);
1265 if Parent_Locked then
1266 STPO.Unlock (Parent);
1269 if Old_State /= Entry_Call.State
1270 and then Entry_Call.State = Now_Abortable
1271 and then Entry_Call.Mode > Simple_Call
1272 and then Entry_Call.Self /= Self_ID
1274 -- Asynchronous_Call or Conditional_Call
1277 -- Because of ATCB lock ordering rule
1279 STPO.Write_Lock (Entry_Call.Self);
1281 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1283 -- Caller may not yet have reached wait-point
1285 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1288 STPO.Unlock (Entry_Call.Self);
1293 end Task_Do_Or_Queue;
1295 ---------------------
1296 -- Task_Entry_Call --
1297 ---------------------
1299 procedure Task_Entry_Call
1300 (Acceptor : Task_Id;
1301 E : Task_Entry_Index;
1302 Uninterpreted_Data : System.Address;
1304 Rendezvous_Successful : out Boolean)
1306 Self_Id : constant Task_Id := STPO.Self;
1307 Entry_Call : Entry_Call_Link;
1310 -- If pragma Detect_Blocking is active then Program_Error must be
1311 -- raised if this potentially blocking operation is called from a
1312 -- protected action.
1314 if System.Tasking.Detect_Blocking
1315 and then Self_Id.Common.Protected_Action_Nesting > 0
1317 raise Program_Error with "potentially blocking operation";
1320 if Parameters.Runtime_Traces then
1321 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1324 if Mode = Simple_Call or else Mode = Conditional_Call then
1326 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1329 -- This is an asynchronous call
1331 -- Abort must already be deferred by the compiler-generated code.
1332 -- Without this, an abort that occurs between the time that this
1333 -- call is made and the time that the abortable part's cleanup
1334 -- handler is set up might miss the cleanup handler and leave the
1337 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1339 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1340 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1341 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1342 Entry_Call.Next := null;
1343 Entry_Call.Mode := Mode;
1344 Entry_Call.Cancellation_Attempted := False;
1345 Entry_Call.State := Not_Yet_Abortable;
1346 Entry_Call.E := Entry_Index (E);
1347 Entry_Call.Prio := Get_Priority (Self_Id);
1348 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1349 Entry_Call.Called_Task := Acceptor;
1350 Entry_Call.Called_PO := Null_Address;
1351 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1352 Entry_Call.With_Abort := True;
1358 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1359 STPO.Write_Lock (Self_Id);
1360 Utilities.Exit_One_ATC_Level (Self_Id);
1361 STPO.Unlock (Self_Id);
1367 Initialization.Undefer_Abort (Self_Id);
1369 if Parameters.Runtime_Traces then
1370 Send_Trace_Info (E_Missed, Acceptor);
1373 raise Tasking_Error;
1376 -- The following is special for async. entry calls.
1377 -- If the call was not queued abortably, we need to wait until
1378 -- it is before proceeding with the abortable part.
1380 -- Wait_Until_Abortable can be called unconditionally here,
1381 -- but it is expensive.
1383 if Entry_Call.State < Was_Abortable then
1384 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1391 -- Note: following assignment needs to be atomic
1393 Rendezvous_Successful := Entry_Call.State = Done;
1395 end Task_Entry_Call;
1397 -----------------------
1398 -- Task_Entry_Caller --
1399 -----------------------
1401 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id is
1402 Self_Id : constant Task_Id := STPO.Self;
1403 Entry_Call : Entry_Call_Link;
1406 Entry_Call := Self_Id.Common.Call;
1408 for Depth in 1 .. D loop
1409 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1410 pragma Assert (Entry_Call /= null);
1413 return Entry_Call.Self;
1414 end Task_Entry_Caller;
1416 --------------------------
1417 -- Timed_Selective_Wait --
1418 --------------------------
1420 procedure Timed_Selective_Wait
1421 (Open_Accepts : Accept_List_Access;
1422 Select_Mode : Select_Modes;
1423 Uninterpreted_Data : out System.Address;
1426 Index : out Select_Index)
1428 Self_Id : constant Task_Id := STPO.Self;
1429 Treatment : Select_Treatment;
1430 Entry_Call : Entry_Call_Link;
1432 Selection : Select_Index;
1433 Open_Alternative : Boolean;
1434 Timedout : Boolean := False;
1435 Yielded : Boolean := True;
1438 pragma Assert (Select_Mode = Delay_Mode);
1440 Initialization.Defer_Abort (Self_Id);
1442 -- If we are aborted here, the effect will be pending
1448 STPO.Write_Lock (Self_Id);
1450 if not Self_Id.Callable then
1451 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1453 pragma Assert (Self_Id.Pending_Action);
1455 STPO.Unlock (Self_Id);
1461 Initialization.Undefer_Abort (Self_Id);
1463 -- Should never get here ???
1465 pragma Assert (False);
1466 raise Standard'Abort_Signal;
1469 Uninterpreted_Data := Null_Address;
1471 pragma Assert (Open_Accepts /= null);
1473 Queuing.Select_Task_Entry_Call
1474 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1476 -- Determine the kind and disposition of the select
1478 Treatment := Default_Treatment (Select_Mode);
1479 Self_Id.Chosen_Index := No_Rendezvous;
1481 if Open_Alternative then
1482 if Entry_Call /= null then
1483 if Open_Accepts (Selection).Null_Body then
1484 Treatment := Accept_Alternative_Completed;
1487 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1488 Treatment := Accept_Alternative_Selected;
1491 Self_Id.Chosen_Index := Selection;
1493 elsif Treatment = No_Alternative_Open then
1494 Treatment := Accept_Alternative_Open;
1498 -- Handle the select according to the disposition selected above
1501 when Accept_Alternative_Selected =>
1502 -- Ready to rendezvous
1503 -- In this case the accept body is not Null_Body. Defer abort
1504 -- until it gets into the accept body.
1506 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1507 Initialization.Defer_Abort (Self_Id);
1508 STPO.Unlock (Self_Id);
1510 when Accept_Alternative_Completed =>
1511 -- Rendezvous is over
1513 if Parameters.Runtime_Traces then
1514 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1517 STPO.Unlock (Self_Id);
1518 Caller := Entry_Call.Self;
1520 STPO.Write_Lock (Caller);
1521 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1522 STPO.Unlock (Caller);
1524 when Accept_Alternative_Open =>
1528 Self_Id.Open_Accepts := Open_Accepts;
1530 -- Wait for a normal call and a pending action until the
1531 -- Wakeup_Time is reached.
1533 Self_Id.Common.State := Acceptor_Delay_Sleep;
1535 -- Try to remove calls to Sleep in the loop below by letting the
1536 -- caller a chance of getting ready immediately, using Unlock
1537 -- Yield. See similar action in Wait_For_Completion/Wait_For_Call.
1545 if Self_Id.Open_Accepts /= null then
1552 Write_Lock (Self_Id);
1555 -- Check if this task has been aborted while the lock was released
1557 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1558 Self_Id.Open_Accepts := null;
1562 exit when Self_Id.Open_Accepts = null;
1565 Sleep (Self_Id, Acceptor_Delay_Sleep);
1567 if Parameters.Runtime_Traces then
1568 Send_Trace_Info (WT_Select,
1570 Integer (Open_Accepts'Length),
1574 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1575 Acceptor_Delay_Sleep, Timedout, Yielded);
1579 Self_Id.Open_Accepts := null;
1581 if Parameters.Runtime_Traces then
1582 Send_Trace_Info (E_Timeout);
1587 Self_Id.Common.State := Runnable;
1589 -- Self_Id.Common.Call should already be updated by the Caller if
1590 -- not aborted. It might also be ready to do rendezvous even if
1591 -- this wakes up due to an abort. Therefore, if the call is not
1592 -- empty we need to do the rendezvous if the accept body is not
1595 if Self_Id.Chosen_Index /= No_Rendezvous
1596 and then Self_Id.Common.Call /= null
1597 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1599 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1601 pragma Assert (Self_Id.Deferral_Level = 1);
1603 Initialization.Defer_Abort_Nestable (Self_Id);
1605 -- Leave abort deferred until the accept body
1608 STPO.Unlock (Self_Id);
1610 when No_Alternative_Open =>
1611 -- In this case, Index will be No_Rendezvous on return. We sleep
1612 -- for the time we need to.
1613 -- Wait for a signal or timeout. A wakeup can be made
1614 -- for several reasons:
1615 -- 1) Delay is expired
1616 -- 2) Pending_Action needs to be checked
1617 -- (Abort, Priority change)
1618 -- 3) Spurious wakeup
1620 Self_Id.Open_Accepts := null;
1621 Self_Id.Common.State := Acceptor_Delay_Sleep;
1623 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Delay_Sleep,
1626 Self_Id.Common.State := Runnable;
1628 STPO.Unlock (Self_Id);
1631 -- Should never get here
1632 pragma Assert (False);
1644 -- Caller has been chosen
1646 -- Self_Id.Common.Call should already be updated by the Caller
1648 -- Self_Id.Chosen_Index should either be updated by the Caller
1649 -- or by Test_Selective_Wait
1651 Index := Self_Id.Chosen_Index;
1652 Initialization.Undefer_Abort_Nestable (Self_Id);
1654 -- Start rendezvous, if not already completed
1655 end Timed_Selective_Wait;
1657 ---------------------------
1658 -- Timed_Task_Entry_Call --
1659 ---------------------------
1661 procedure Timed_Task_Entry_Call
1662 (Acceptor : Task_Id;
1663 E : Task_Entry_Index;
1664 Uninterpreted_Data : System.Address;
1667 Rendezvous_Successful : out Boolean)
1669 Self_Id : constant Task_Id := STPO.Self;
1671 Entry_Call : Entry_Call_Link;
1674 pragma Unreferenced (Yielded);
1677 -- If pragma Detect_Blocking is active then Program_Error must be
1678 -- raised if this potentially blocking operation is called from a
1679 -- protected action.
1681 if System.Tasking.Detect_Blocking
1682 and then Self_Id.Common.Protected_Action_Nesting > 0
1684 raise Program_Error with "potentially blocking operation";
1687 Initialization.Defer_Abort (Self_Id);
1688 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1691 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1692 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1694 if Parameters.Runtime_Traces then
1695 Send_Trace_Info (WT_Call, Acceptor,
1696 Entry_Index (E), Timeout);
1699 Level := Self_Id.ATC_Nesting_Level;
1700 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1701 Entry_Call.Next := null;
1702 Entry_Call.Mode := Timed_Call;
1703 Entry_Call.Cancellation_Attempted := False;
1705 -- If this is a call made inside of an abort deferred region,
1706 -- the call should be never abortable.
1709 (if Self_Id.Deferral_Level > 1
1710 then Never_Abortable
1711 else Now_Abortable);
1713 Entry_Call.E := Entry_Index (E);
1714 Entry_Call.Prio := Get_Priority (Self_Id);
1715 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1716 Entry_Call.Called_Task := Acceptor;
1717 Entry_Call.Called_PO := Null_Address;
1718 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1719 Entry_Call.With_Abort := True;
1721 -- Note: the caller will undefer abort on return (see WARNING above)
1727 if not Task_Do_Or_Queue (Self_Id, Entry_Call) then
1728 STPO.Write_Lock (Self_Id);
1729 Utilities.Exit_One_ATC_Level (Self_Id);
1730 STPO.Unlock (Self_Id);
1736 Initialization.Undefer_Abort (Self_Id);
1738 if Parameters.Runtime_Traces then
1739 Send_Trace_Info (E_Missed, Acceptor);
1741 raise Tasking_Error;
1744 Write_Lock (Self_Id);
1745 Entry_Calls.Wait_For_Completion_With_Timeout
1746 (Entry_Call, Timeout, Mode, Yielded);
1753 -- ??? Do we need to yield in case Yielded is False
1755 Rendezvous_Successful := Entry_Call.State = Done;
1756 Initialization.Undefer_Abort (Self_Id);
1757 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1758 end Timed_Task_Entry_Call;
1764 procedure Wait_For_Call (Self_Id : Task_Id) is
1766 Self_Id.Common.State := Acceptor_Sleep;
1768 -- Try to remove calls to Sleep in the loop below by letting the caller
1769 -- a chance of getting ready immediately, using Unlock & Yield.
1770 -- See similar action in Wait_For_Completion & Timed_Selective_Wait.
1778 if Self_Id.Open_Accepts /= null then
1785 Write_Lock (Self_Id);
1788 -- Check if this task has been aborted while the lock was released
1790 if Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level then
1791 Self_Id.Open_Accepts := null;
1795 exit when Self_Id.Open_Accepts = null;
1796 Sleep (Self_Id, Acceptor_Sleep);
1799 Self_Id.Common.State := Runnable;
1802 end System.Tasking.Rendezvous;