1 ------------------------------------------------------------------------------
3 -- GNU ADA 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 --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
36 -- Used for Exception_ID
41 with System
.Task_Primitives
.Operations
;
42 -- used for Get_Priority
50 with System
.Tasking
.Entry_Calls
;
51 -- Used for Wait_For_Completion
52 -- Wait_For_Completion_With_Timeout
53 -- Wait_Until_Abortable
55 with System
.Tasking
.Initialization
;
56 -- used for Defer_Abort
58 -- Poll_Base_Priority_Change
60 with System
.Tasking
.Queuing
;
63 -- Select_Task_Entry_Call
66 with System
.Tasking
.Utilities
;
67 -- used for Check_Exception
69 -- Wakeup_Entry_Caller
71 with System
.Tasking
.Protected_Objects
.Operations
;
72 -- used for PO_Do_Or_Queue
77 with System
.Tasking
.Debug
;
80 with System
.Parameters
;
81 -- used for Single_Lock
84 with System
.Traces
.Tasking
;
85 -- used for Send_Trace_Info
87 package body System
.Tasking
.Rendezvous
is
89 package STPO
renames System
.Task_Primitives
.Operations
;
90 package POO
renames Protected_Objects
.Operations
;
91 package POE
renames Protected_Objects
.Entries
;
94 use Task_Primitives
.Operations
;
96 use System
.Traces
.Tasking
;
98 type Select_Treatment
is (
99 Accept_Alternative_Selected
, -- alternative with non-null body
100 Accept_Alternative_Completed
, -- alternative with null body
103 Accept_Alternative_Open
,
104 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.
164 procedure Setup_For_Rendezvous_With_Body
165 (Entry_Call
: Entry_Call_Link
;
167 pragma Inline
(Setup_For_Rendezvous_With_Body
);
168 -- Call this only with abort deferred and holding lock of Acceptor.
169 -- When a rendezvous selected (ready for rendezvous) we need to save
170 -- privious caller and adjust the priority. Also we need to make
171 -- this call not Abortable (Cancellable) since the rendezvous has
172 -- already been started.
174 function Is_Entry_Open
(T
: Task_ID
; E
: Task_Entry_Index
) return Boolean;
175 pragma Inline
(Is_Entry_Open
);
176 -- Call this only with abort deferred and holding lock of T.
178 procedure Wait_For_Call
(Self_Id
: Task_ID
);
179 pragma Inline
(Wait_For_Call
);
180 -- Call this only with abort deferred and holding lock of Self_Id.
181 -- An accepting task goes into Sleep by calling this routine
182 -- waiting for a call from the caller or waiting for an abort.
183 -- Make sure Self_Id is locked before calling this routine.
189 procedure Accept_Call
190 (E
: Task_Entry_Index
;
191 Uninterpreted_Data
: out System
.Address
)
193 Self_Id
: constant Task_ID
:= STPO
.Self
;
194 Caller
: Task_ID
:= null;
195 Open_Accepts
: aliased Accept_List
(1 .. 1);
196 Entry_Call
: Entry_Call_Link
;
199 Initialization
.Defer_Abort
(Self_Id
);
205 STPO
.Write_Lock
(Self_Id
);
207 if not Self_Id
.Callable
then
208 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
210 pragma Assert
(Self_Id
.Pending_Action
);
212 STPO
.Unlock
(Self_Id
);
218 Initialization
.Undefer_Abort
(Self_Id
);
220 -- Should never get here ???
222 pragma Assert
(False);
223 raise Standard
'Abort_Signal;
226 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
228 if Entry_Call
/= null then
229 Caller
:= Entry_Call
.Self
;
230 Setup_For_Rendezvous_With_Body
(Entry_Call
, Self_Id
);
231 Uninterpreted_Data
:= Entry_Call
.Uninterpreted_Data
;
236 Open_Accepts
(1).Null_Body
:= False;
237 Open_Accepts
(1).S
:= E
;
238 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
240 -- Wait for normal call
242 if Parameters
.Runtime_Traces
then
243 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
247 (Debug
.Trace
(Self_Id
, "Accept_Call: wait", 'R'));
248 Wait_For_Call
(Self_Id
);
250 pragma Assert
(Self_Id
.Open_Accepts
= null);
252 if Self_Id
.Common
.Call
/= null then
253 Caller
:= Self_Id
.Common
.Call
.Self
;
254 Uninterpreted_Data
:=
255 Caller
.Entry_Calls
(Caller
.ATC_Nesting_Level
).Uninterpreted_Data
;
257 -- Case of an aborted task.
259 Uninterpreted_Data
:= System
.Null_Address
;
263 -- Self_Id.Common.Call should already be updated by the Caller
264 -- On return, we will start the rendezvous.
266 STPO
.Unlock
(Self_Id
);
272 Initialization
.Undefer_Abort
(Self_Id
);
274 if Parameters
.Runtime_Traces
then
275 Send_Trace_Info
(M_Accept_Complete
, Caller
, Entry_Index
(E
));
283 procedure Accept_Trivial
(E
: Task_Entry_Index
) is
284 Self_Id
: constant Task_ID
:= STPO
.Self
;
285 Caller
: Task_ID
:= null;
286 Open_Accepts
: aliased Accept_List
(1 .. 1);
287 Entry_Call
: Entry_Call_Link
;
290 Initialization
.Defer_Abort_Nestable
(Self_Id
);
296 STPO
.Write_Lock
(Self_Id
);
298 if not Self_Id
.Callable
then
299 pragma Assert
(Self_Id
.Pending_ATC_Level
= 0);
301 pragma Assert
(Self_Id
.Pending_Action
);
303 STPO
.Unlock
(Self_Id
);
309 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
311 -- Should never get here ???
313 pragma Assert
(False);
314 raise Standard
'Abort_Signal;
317 Queuing
.Dequeue_Head
(Self_Id
.Entry_Queues
(E
), Entry_Call
);
319 if Entry_Call
= null then
320 -- Need to wait for entry call
322 Open_Accepts
(1).Null_Body
:= True;
323 Open_Accepts
(1).S
:= E
;
324 Self_Id
.Open_Accepts
:= Open_Accepts
'Unrestricted_Access;
326 if Parameters
.Runtime_Traces
then
327 Send_Trace_Info
(W_Accept
, Self_Id
, Integer (Open_Accepts
'Length));
331 (Debug
.Trace
(Self_Id
, "Accept_Trivial: wait", 'R'));
333 Wait_For_Call
(Self_Id
);
335 pragma Assert
(Self_Id
.Open_Accepts
= null);
337 -- No need to do anything special here for pending abort.
338 -- Abort_Signal will be raised by Undefer on exit.
340 STPO
.Unlock
(Self_Id
);
342 else -- found caller already waiting
343 pragma Assert
(Entry_Call
.State
< Done
);
345 STPO
.Unlock
(Self_Id
);
346 Caller
:= Entry_Call
.Self
;
348 STPO
.Write_Lock
(Caller
);
349 Initialization
.Wakeup_Entry_Caller
(Self_Id
, Entry_Call
, Done
);
350 STPO
.Unlock
(Caller
);
353 if Parameters
.Runtime_Traces
then
354 Send_Trace_Info
(M_Accept_Complete
);
356 -- Fake one, since there is (???) no way
357 -- to know that the rendezvous is over
359 Send_Trace_Info
(M_RDV_Complete
);
366 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
373 procedure Boost_Priority
(Call
: Entry_Call_Link
; Acceptor
: Task_ID
) is
374 Caller
: constant Task_ID
:= Call
.Self
;
375 Caller_Prio
: System
.Any_Priority
:= Get_Priority
(Caller
);
376 Acceptor_Prio
: System
.Any_Priority
:= Get_Priority
(Acceptor
);
379 if Caller_Prio
> Acceptor_Prio
then
380 Call
.Acceptor_Prev_Priority
:= Acceptor_Prio
;
381 Set_Priority
(Acceptor
, Caller_Prio
);
384 Call
.Acceptor_Prev_Priority
:= Priority_Not_Boosted
;
392 procedure Call_Simple
394 E
: Task_Entry_Index
;
395 Uninterpreted_Data
: System
.Address
)
397 Rendezvous_Successful
: Boolean;
400 (Acceptor
, E
, Uninterpreted_Data
, Simple_Call
, Rendezvous_Successful
);
403 ----------------------
404 -- Call_Synchronous --
405 ----------------------
407 -- Called from Call_Simple and Task_Entry_Call.
409 procedure Call_Synchronous
411 E
: Task_Entry_Index
;
412 Uninterpreted_Data
: System
.Address
;
414 Rendezvous_Successful
: out Boolean)
416 Self_Id
: constant Task_ID
:= STPO
.Self
;
418 Entry_Call
: Entry_Call_Link
;
421 pragma Assert
(Mode
/= Asynchronous_Call
);
423 Local_Defer_Abort
(Self_Id
);
424 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
+ 1;
426 (Debug
.Trace
(Self_Id
, "CS: entered ATC level: " &
427 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
428 Level
:= Self_Id
.ATC_Nesting_Level
;
429 Entry_Call
:= Self_Id
.Entry_Calls
(Level
)'Access;
430 Entry_Call
.Next
:= null;
431 Entry_Call
.Mode
:= Mode
;
432 Entry_Call
.Cancellation_Attempted
:= False;
434 if Parameters
.Runtime_Traces
then
435 Send_Trace_Info
(W_Call
, Acceptor
, Entry_Index
(E
));
438 -- If this is a call made inside of an abort deferred region,
439 -- the call should be never abortable.
441 if Self_Id
.Deferral_Level
> 1 then
442 Entry_Call
.State
:= Never_Abortable
;
444 Entry_Call
.State
:= Now_Abortable
;
447 Entry_Call
.E
:= Entry_Index
(E
);
448 Entry_Call
.Prio
:= Get_Priority
(Self_Id
);
449 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
450 Entry_Call
.Called_Task
:= Acceptor
;
451 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
453 -- Note: the caller will undefer abort on return (see WARNING above)
459 if not Task_Do_Or_Queue
460 (Self_Id
, Entry_Call
, With_Abort
=> True)
462 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
- 1;
468 if Parameters
.Runtime_Traces
then
469 Send_Trace_Info
(E_Missed
, Acceptor
);
472 Initialization
.Undefer_Abort
(Self_Id
);
474 (Debug
.Trace
(Self_Id
, "CS: exited to ATC level: " &
475 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
479 STPO
.Write_Lock
(Self_Id
);
481 (Debug
.Trace
(Self_Id
, "Call_Synchronous: wait", 'R'));
482 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
484 (Debug
.Trace
(Self_Id
, "Call_Synchronous: done waiting", 'R'));
485 Rendezvous_Successful
:= Entry_Call
.State
= Done
;
486 STPO
.Unlock
(Self_Id
);
492 Local_Undefer_Abort
(Self_Id
);
493 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
494 end Call_Synchronous
;
500 function Callable
(T
: Task_ID
) return Boolean is
502 Self_Id
: constant Task_ID
:= STPO
.Self
;
505 Initialization
.Defer_Abort
(Self_Id
);
512 Result
:= T
.Callable
;
519 Initialization
.Undefer_Abort
(Self_Id
);
523 ----------------------------
524 -- Cancel_Task_Entry_Call --
525 ----------------------------
527 procedure Cancel_Task_Entry_Call
(Cancelled
: out Boolean) is
529 Entry_Calls
.Try_To_Cancel_Entry_Call
(Cancelled
);
530 end Cancel_Task_Entry_Call
;
532 -------------------------
533 -- Complete_Rendezvous --
534 -------------------------
536 procedure Complete_Rendezvous
is
538 Exceptional_Complete_Rendezvous
(Ada
.Exceptions
.Null_Id
);
539 end Complete_Rendezvous
;
541 -------------------------------------
542 -- Exceptional_Complete_Rendezvous --
543 -------------------------------------
545 procedure Exceptional_Complete_Rendezvous
546 (Ex
: Ada
.Exceptions
.Exception_Id
)
548 Self_Id
: constant Task_ID
:= STPO
.Self
;
549 Entry_Call
: Entry_Call_Link
:= Self_Id
.Common
.Call
;
551 Called_PO
: STPE
.Protection_Entries_Access
;
553 Exception_To_Raise
: Ada
.Exceptions
.Exception_Id
:= Ex
;
554 Ceiling_Violation
: Boolean;
556 use type Ada
.Exceptions
.Exception_Id
;
557 procedure Internal_Reraise
;
558 pragma Import
(C
, Internal_Reraise
, "__gnat_reraise");
560 use type STPE
.Protection_Entries_Access
;
563 -- Consider phasing out Complete_Rendezvous in favor
564 -- of direct call to this with Ada.Exceptions.Null_ID.
565 -- See code expansion examples for Accept_Call and Selective_Wait.
566 -- Also consider putting an explicit re-raise after this call, in
567 -- the generated code. That way we could eliminate the
568 -- code here that reraises the exception.
570 -- The deferral level is critical here,
571 -- since we want to raise an exception or allow abort to take
572 -- place, if there is an exception or abort pending.
575 (Debug
.Trace
(Self_Id
, "Exceptional_Complete_Rendezvous", 'R'));
577 if Ex
= Ada
.Exceptions
.Null_Id
then
578 -- The call came from normal end-of-rendezvous,
579 -- so abort is not yet deferred.
581 if Parameters
.Runtime_Traces
then
582 Send_Trace_Info
(M_RDV_Complete
, Entry_Call
.Self
);
585 Initialization
.Defer_Abort_Nestable
(Self_Id
);
588 -- We need to clean up any accepts which Self may have
589 -- been serving when it was aborted.
591 if Ex
= Standard
'Abort_Signal'Identity then
596 while Entry_Call /= null loop
597 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
599 -- All forms of accept make sure that the acceptor is not
600 -- completed, before accepting further calls, so that we
601 -- can be sure that no further calls are made after the
602 -- current calls are purged.
604 Caller := Entry_Call.Self;
606 -- Take write lock. This follows the lock precedence rule that
607 -- Caller may be locked while holding lock of Acceptor.
608 -- Complete the call abnormally, with exception.
610 STPO.Write_Lock (Caller);
611 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
612 STPO.Unlock (Caller);
613 Entry_Call := Entry_Call.Acceptor_Prev_Call;
621 Caller := Entry_Call.Self;
623 if Entry_Call.Needs_Requeue then
624 -- We dare not lock Self_Id at the same time as Caller,
625 -- for fear of deadlock.
627 Entry_Call.Needs_Requeue := False;
628 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
630 if Entry_Call.Called_Task /= null then
631 -- Requeue to another task entry
637 if not Task_Do_Or_Queue
638 (Self_Id, Entry_Call, Entry_Call.Requeue_With_Abort)
644 Initialization.Undefer_Abort (Self_Id);
653 -- Requeue to a protected entry
655 Called_PO := POE.To_Protection (Entry_Call.Called_PO);
656 STPE.Lock_Entries (Called_PO, Ceiling_Violation);
658 if Ceiling_Violation then
659 pragma Assert (Ex = Ada.Exceptions.Null_Id);
661 Exception_To_Raise := Program_Error'Identity;
662 Entry_Call.Exception_To_Raise := Exception_To_Raise;
668 STPO.Write_Lock (Caller);
669 Initialization.Wakeup_Entry_Caller
670 (Self_Id, Entry_Call, Done);
671 STPO.Unlock (Caller);
679 (Self_Id, Called_PO, Entry_Call,
680 Entry_Call.Requeue_With_Abort);
681 POO.PO_Service_Entries (Self_Id, Called_PO);
682 STPE.Unlock_Entries (Called_PO);
686 Entry_Calls.Reset_Priority
687 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
690 -- The call does not need to be requeued.
692 Self_Id.Common.Call := Entry_Call.Acceptor_Prev_Call;
693 Entry_Call.Exception_To_Raise := Ex;
699 STPO.Write_Lock (Caller);
701 -- Done with Caller locked to make sure that Wakeup is not lost.
703 if Ex /= Ada.Exceptions.Null_Id then
704 Ada.Exceptions.Save_Occurrence
705 (Caller.Common.Compiler_Data.Current_Excep,
706 Self_Id.Common.Compiler_Data.Current_Excep);
709 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
710 STPO.Unlock (Caller);
716 Entry_Calls.Reset_Priority
717 (Self_Id, Entry_Call.Acceptor_Prev_Priority);
721 Initialization.Undefer_Abort (Self_Id);
723 if Exception_To_Raise /= Ada.Exceptions.Null_Id then
727 -- ??? Do we need to give precedence to Program_Error that might be
728 -- raised due to failure of finalization, over Tasking_Error from
729 -- failure of requeue?
730 end Exceptional_Complete_Rendezvous;
736 -- Call this only with abort deferred and holding lock of T.
738 function Is_Entry_Open (T : Task_ID; E : Task_Entry_Index) return Boolean is
740 pragma Assert (T.Open_Accepts /= null);
742 if T.Open_Accepts /= null then
743 for J in T.Open_Accepts'Range loop
745 pragma Assert (J > 0);
747 if E = T.Open_Accepts (J).S then
756 -------------------------------------
757 -- Requeue_Protected_To_Task_Entry --
758 -------------------------------------
760 procedure Requeue_Protected_To_Task_Entry
761 (Object : STPE.Protection_Entries_Access;
763 E : Task_Entry_Index;
764 With_Abort : Boolean)
766 Entry_Call : constant Entry_Call_Link := Object.Call_In_Progress;
768 pragma Assert (STPO.Self.Deferral_Level > 0);
770 Entry_Call.E := Entry_Index (E);
771 Entry_Call.Called_Task := Acceptor;
772 Entry_Call.Called_PO := Null_Address;
773 Entry_Call.Requeue_With_Abort := With_Abort;
774 Object.Call_In_Progress := null;
775 end Requeue_Protected_To_Task_Entry;
777 ------------------------
778 -- Requeue_Task_Entry --
779 ------------------------
781 procedure Requeue_Task_Entry
783 E : Task_Entry_Index;
784 With_Abort : Boolean)
786 Self_Id : constant Task_ID := STPO.Self;
787 Entry_Call : constant Entry_Call_Link := Self_Id.Common.Call;
790 Initialization.Defer_Abort (Self_Id);
791 Entry_Call.Needs_Requeue := True;
792 Entry_Call.Requeue_With_Abort := With_Abort;
793 Entry_Call.E := Entry_Index (E);
794 Entry_Call.Called_Task := Acceptor;
795 Initialization.Undefer_Abort (Self_Id);
796 end Requeue_Task_Entry;
802 procedure Selective_Wait
803 (Open_Accepts : Accept_List_Access;
804 Select_Mode : Select_Modes;
805 Uninterpreted_Data : out System.Address;
806 Index : out Select_Index)
808 Self_Id : constant Task_ID := STPO.Self;
809 Entry_Call : Entry_Call_Link;
810 Treatment : Select_Treatment;
812 Selection : Select_Index;
813 Open_Alternative : Boolean;
816 Initialization.Defer_Abort (Self_Id);
822 STPO.Write_Lock (Self_Id);
824 if not Self_Id.Callable then
825 pragma Assert (Self_Id.Pending_ATC_Level = 0);
827 pragma Assert (Self_Id.Pending_Action);
829 STPO.Unlock (Self_Id);
835 -- ??? In some cases abort is deferred more than once. Need to
836 -- figure out why this happens.
838 Self_Id.Deferral_Level := 1;
840 Initialization.Undefer_Abort (Self_Id);
842 -- Should never get here ???
844 pragma Assert (False);
845 raise Standard'Abort_Signal;
848 pragma Assert (Open_Accepts /= null);
850 Uninterpreted_Data := Null_Address;
852 Queuing.Select_Task_Entry_Call
853 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
855 -- Determine the kind and disposition of the select.
857 Treatment := Default_Treatment (Select_Mode);
858 Self_Id.Chosen_Index := No_Rendezvous;
860 if Open_Alternative then
861 if Entry_Call /= null then
862 if Open_Accepts (Selection).Null_Body then
863 Treatment := Accept_Alternative_Completed;
865 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
866 Treatment := Accept_Alternative_Selected;
869 Self_Id.Chosen_Index := Selection;
871 elsif Treatment = No_Alternative_Open then
872 Treatment := Accept_Alternative_Open;
876 -- Handle the select according to the disposition selected above.
879 when Accept_Alternative_Selected =>
880 -- Ready to rendezvous
882 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
884 -- In this case the accept body is not Null_Body. Defer abort
885 -- until it gets into the accept body.
887 pragma Assert (Self_Id.Deferral_Level = 1);
889 Initialization.Defer_Abort_Nestable (Self_Id);
890 STPO.Unlock (Self_Id);
892 when Accept_Alternative_Completed =>
893 -- Accept body is null, so rendezvous is over immediately.
895 if Parameters.Runtime_Traces then
896 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
899 STPO.Unlock (Self_Id);
900 Caller := Entry_Call.Self;
902 STPO.Write_Lock (Caller);
903 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
904 STPO.Unlock (Caller);
906 when Accept_Alternative_Open =>
909 Self_Id.Open_Accepts := Open_Accepts;
911 (Debug.Trace (Self_Id, "Selective_Wait: wait", 'R
'));
913 if Parameters.Runtime_Traces then
914 Send_Trace_Info (W_Select, Self_Id,
915 Integer (Open_Accepts'Length));
918 Wait_For_Call (Self_Id);
920 pragma Assert (Self_Id.Open_Accepts = null);
922 -- Self_Id.Common.Call should already be updated by the Caller if
923 -- not aborted. It might also be ready to do rendezvous even if
924 -- this wakes up due to an abortion.
925 -- Therefore, if the call is not empty we need to do the
926 -- rendezvous if the accept body is not Null_Body.
928 -- Aren't the first two conditions below redundant???
930 if Self_Id.Chosen_Index /= No_Rendezvous
931 and then Self_Id.Common.Call /= null
932 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
934 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
936 pragma Assert (Self_Id.Deferral_Level = 1);
938 Initialization.Defer_Abort_Nestable (Self_Id);
940 -- Leave abort deferred until the accept body
943 STPO.Unlock (Self_Id);
945 when Else_Selected =>
946 pragma Assert (Self_Id.Open_Accepts = null);
948 if Parameters.Runtime_Traces then
949 Send_Trace_Info (M_Select_Else);
952 STPO.Unlock (Self_Id);
954 when Terminate_Selected =>
955 -- Terminate alternative is open
957 Self_Id.Open_Accepts := Open_Accepts;
958 Self_Id.Common.State := Acceptor_Sleep;
959 STPO.Unlock (Self_Id);
961 -- Notify ancestors that this task is on a terminate alternative.
963 Utilities.Make_Passive (Self_Id, Task_Completed => False);
965 -- Wait for normal entry call or termination
967 pragma Assert (Self_Id.ATC_Nesting_Level = 1);
969 STPO.Write_Lock (Self_Id);
972 Initialization.Poll_Base_Priority_Change (Self_Id);
973 exit when Self_Id.Open_Accepts = null;
974 Sleep (Self_Id, Acceptor_Sleep);
977 Self_Id.Common.State := Runnable;
979 pragma Assert (Self_Id.Open_Accepts = null);
981 if Self_Id.Terminate_Alternative then
982 -- An entry call should have reset this to False,
983 -- so we must be aborted.
984 -- We cannot be in an async. select, since that
985 -- is not legal, so the abort must be of the entire
986 -- task. Therefore, we do not need to cancel the
987 -- terminate alternative. The cleanup will be done
988 -- in Complete_Master.
990 pragma Assert (Self_Id.Pending_ATC_Level = 0);
991 pragma Assert (Self_Id.Awake_Count = 0);
993 -- Trust that it is OK to fall through.
997 -- Self_Id.Common.Call and Self_Id.Chosen_Index
998 -- should already be updated by the Caller.
1000 if Self_Id.Chosen_Index /= No_Rendezvous
1001 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1003 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1005 pragma Assert (Self_Id.Deferral_Level = 1);
1007 -- We need an extra defer here, to keep abort
1008 -- deferred until we get into the accept body
1010 Initialization.Defer_Abort_Nestable (Self_Id);
1014 STPO.Unlock (Self_Id);
1016 when No_Alternative_Open =>
1017 -- In this case, Index will be No_Rendezvous on return, which
1018 -- should cause a Program_Error if it is not a Delay_Mode.
1020 -- If delay alternative exists (Delay_Mode) we should suspend
1021 -- until the delay expires.
1023 Self_Id.Open_Accepts := null;
1025 if Select_Mode = Delay_Mode then
1026 Self_Id.Common.State := Delay_Sleep;
1029 Initialization.Poll_Base_Priority_Change (Self_Id);
1031 Self_Id.Pending_ATC_Level < Self_Id.ATC_Nesting_Level;
1032 Sleep (Self_Id, Delay_Sleep);
1035 Self_Id.Common.State := Runnable;
1036 STPO.Unlock (Self_Id);
1039 STPO.Unlock (Self_Id);
1045 Initialization.Undefer_Abort (Self_Id);
1046 Ada.Exceptions.Raise_Exception
1047 (Program_Error'Identity, "Entry call not a delay mode");
1055 -- Caller has been chosen.
1056 -- Self_Id.Common.Call should already be updated by the Caller.
1057 -- Self_Id.Chosen_Index should either be updated by the Caller
1058 -- or by Test_Selective_Wait.
1059 -- On return, we sill start rendezvous unless the accept body is
1060 -- null. In the latter case, we will have already completed the RV.
1062 Index := Self_Id.Chosen_Index;
1063 Initialization.Undefer_Abort_Nestable (Self_Id);
1066 ------------------------------------
1067 -- Setup_For_Rendezvous_With_Body --
1068 ------------------------------------
1070 -- Call this only with abort deferred and holding lock of Acceptor.
1072 procedure Setup_For_Rendezvous_With_Body
1073 (Entry_Call : Entry_Call_Link;
1074 Acceptor : Task_ID) is
1076 Entry_Call.Acceptor_Prev_Call := Acceptor.Common.Call;
1077 Acceptor.Common.Call := Entry_Call;
1079 if Entry_Call.State = Now_Abortable then
1080 Entry_Call.State := Was_Abortable;
1083 Boost_Priority (Entry_Call, Acceptor);
1084 end Setup_For_Rendezvous_With_Body;
1090 function Task_Count (E : Task_Entry_Index) return Natural is
1091 Self_Id : constant Task_ID := STPO.Self;
1092 Return_Count : Natural;
1095 Initialization.Defer_Abort (Self_Id);
1101 STPO.Write_Lock (Self_Id);
1102 Return_Count := Queuing.Count_Waiting (Self_Id.Entry_Queues (E));
1103 STPO.Unlock (Self_Id);
1109 Initialization.Undefer_Abort (Self_Id);
1110 return Return_Count;
1113 ----------------------
1114 -- Task_Do_Or_Queue --
1115 ----------------------
1117 function Task_Do_Or_Queue
1119 Entry_Call : Entry_Call_Link;
1120 With_Abort : Boolean) return Boolean
1122 E : constant Task_Entry_Index :=
1123 Task_Entry_Index (Entry_Call.E);
1124 Old_State : constant Entry_Call_State := Entry_Call.State;
1125 Acceptor : constant Task_ID := Entry_Call.Called_Task;
1126 Parent : constant Task_ID := Acceptor.Common.Parent;
1127 Parent_Locked : Boolean := False;
1128 Null_Body : Boolean;
1131 -- Find out whether Entry_Call can be accepted immediately.
1132 -- If the Acceptor is not callable, return False.
1133 -- If the rendezvous can start, initiate it.
1134 -- If the accept-body is trivial, also complete the rendezvous.
1135 -- If the acceptor is not ready, enqueue the call.
1137 -- This should have a special case for Accept_Call and Accept_Trivial,
1138 -- so that we don't have the loop setup overhead, below.
1140 -- The call state Done is used here and elsewhere to include both the
1141 -- case of normal successful completion, and the case of an exception
1142 -- being raised. The difference is that if an exception is raised no one
1143 -- will pay attention to the fact that State = Done. Instead the
1144 -- exception will be raised in Undefer_Abort, and control will skip past
1145 -- the place where we normally would resume from an entry call.
1147 pragma Assert (not Queuing.Onqueue (Entry_Call));
1149 -- We rely that the call is off-queue for protection, that the caller
1150 -- will not exit the Entry_Caller_Sleep, and so will not reuse the call
1151 -- record for another call.
1152 -- We rely on the Caller's lock for call State mod's.
1154 -- We can't lock Acceptor.Parent while holding Acceptor,
1155 -- so lock it in advance if we expect to need to lock it.
1157 if Acceptor.Terminate_Alternative then
1158 STPO.Write_Lock (Parent);
1159 Parent_Locked := True;
1162 STPO.Write_Lock (Acceptor);
1164 -- If the acceptor is not callable, abort the call and return False.
1166 if not Acceptor.Callable then
1167 STPO.Unlock (Acceptor);
1169 if Parent_Locked then
1170 STPO.Unlock (Parent);
1173 pragma Assert (Entry_Call.State < Done);
1175 -- In case we are not the caller, set up the caller
1176 -- to raise Tasking_Error when it wakes up.
1178 STPO.Write_Lock (Entry_Call.Self);
1179 Entry_Call.Exception_To_Raise := Tasking_Error'Identity;
1180 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Done);
1181 STPO.Unlock (Entry_Call.Self);
1186 -- Try to serve the call immediately.
1188 if Acceptor.Open_Accepts /= null then
1189 for J in Acceptor.Open_Accepts'Range loop
1190 if Entry_Call.E = Entry_Index (Acceptor.Open_Accepts (J).S) then
1192 -- Commit acceptor to rendezvous with us.
1194 Acceptor.Chosen_Index := J;
1195 Null_Body := Acceptor.Open_Accepts (J).Null_Body;
1196 Acceptor.Open_Accepts := null;
1198 -- Prevent abort while call is being served.
1200 if Entry_Call.State = Now_Abortable then
1201 Entry_Call.State := Was_Abortable;
1204 if Acceptor.Terminate_Alternative then
1205 -- Cancel terminate alternative.
1206 -- See matching code in Selective_Wait and
1207 -- Vulnerable_Complete_Master.
1209 Acceptor.Terminate_Alternative := False;
1210 Acceptor.Awake_Count := Acceptor.Awake_Count + 1;
1212 if Acceptor.Awake_Count = 1 then
1214 -- Notify parent that acceptor is awake.
1216 pragma Assert (Parent.Awake_Count > 0);
1218 Parent.Awake_Count := Parent.Awake_Count + 1;
1220 if Parent.Common.State = Master_Completion_Sleep
1221 and then Acceptor.Master_of_Task = Parent.Master_Within
1223 Parent.Common.Wait_Count :=
1224 Parent.Common.Wait_Count + 1;
1230 -- Rendezvous is over immediately.
1232 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1233 STPO.Unlock (Acceptor);
1235 if Parent_Locked then
1236 STPO.Unlock (Parent);
1239 STPO.Write_Lock (Entry_Call.Self);
1240 Initialization.Wakeup_Entry_Caller
1241 (Self_ID, Entry_Call, Done);
1242 STPO.Unlock (Entry_Call.Self);
1245 Setup_For_Rendezvous_With_Body (Entry_Call, Acceptor);
1247 -- For terminate_alternative, acceptor may not be
1248 -- asleep yet, so we skip the wakeup
1250 if Acceptor.Common.State /= Runnable then
1251 STPO.Wakeup (Acceptor, Acceptor_Sleep);
1254 STPO.Unlock (Acceptor);
1256 if Parent_Locked then
1257 STPO.Unlock (Parent);
1265 -- The acceptor is accepting, but not this entry.
1268 -- If the acceptor was ready to accept this call,
1269 -- we would not have gotten this far, so now we should
1270 -- (re)enqueue the call, if the mode permits that.
1272 if Entry_Call.Mode /= Conditional_Call
1273 or else not With_Abort
1275 -- Timed_Call, Simple_Call, or Asynchronous_Call
1277 Queuing.Enqueue (Acceptor.Entry_Queues (E), Entry_Call);
1279 -- Update abortability of call
1281 pragma Assert (Old_State < Done);
1283 Entry_Call.State := New_State (With_Abort, Entry_Call.State);
1285 STPO.Unlock (Acceptor);
1287 if Parent_Locked then
1288 STPO.Unlock (Parent);
1291 if Old_State /= Entry_Call.State
1292 and then Entry_Call.State = Now_Abortable
1293 and then Entry_Call.Mode > Simple_Call
1294 and then Entry_Call.Self /= Self_ID
1296 -- Asynchronous_Call or Conditional_Call
1299 -- Because of ATCB lock ordering rule
1301 STPO.Write_Lock (Entry_Call.Self);
1303 if Entry_Call.Self.Common.State = Async_Select_Sleep then
1305 -- Caller may not yet have reached wait-point
1307 STPO.Wakeup (Entry_Call.Self, Async_Select_Sleep);
1310 STPO.Unlock (Entry_Call.Self);
1314 -- Conditional_Call and With_Abort
1316 STPO.Unlock (Acceptor);
1318 if Parent_Locked then
1319 STPO.Unlock (Parent);
1322 STPO.Write_Lock (Entry_Call.Self);
1324 pragma Assert (Entry_Call.State >= Was_Abortable);
1326 Initialization.Wakeup_Entry_Caller (Self_ID, Entry_Call, Cancelled);
1327 STPO.Unlock (Entry_Call.Self);
1331 end Task_Do_Or_Queue;
1333 ---------------------
1334 -- Task_Entry_Call --
1335 ---------------------
1337 procedure Task_Entry_Call
1338 (Acceptor : Task_ID;
1339 E : Task_Entry_Index;
1340 Uninterpreted_Data : System.Address;
1342 Rendezvous_Successful : out Boolean)
1344 Self_Id : constant Task_ID := STPO.Self;
1345 Entry_Call : Entry_Call_Link;
1348 if Parameters.Runtime_Traces then
1349 Send_Trace_Info (W_Call, Acceptor, Entry_Index (E));
1352 if Mode = Simple_Call or else Mode = Conditional_Call then
1354 (Acceptor, E, Uninterpreted_Data, Mode, Rendezvous_Successful);
1357 -- This is an asynchronous call
1359 -- Abortion must already be deferred by the compiler-generated
1360 -- code. Without this, an abortion that occurs between the time
1361 -- that this call is made and the time that the abortable part's
1362 -- cleanup handler is set up might miss the cleanup handler and
1363 -- leave the call pending.
1365 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1367 (Debug.Trace (Self_Id, "TEC: entered ATC level: " &
1368 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1369 Entry_Call := Self_Id.Entry_Calls (Self_Id.ATC_Nesting_Level)'Access;
1370 Entry_Call.Next := null;
1371 Entry_Call.Mode := Mode;
1372 Entry_Call.Cancellation_Attempted := False;
1373 Entry_Call.State := Not_Yet_Abortable;
1374 Entry_Call.E := Entry_Index (E);
1375 Entry_Call.Prio := Get_Priority (Self_Id);
1376 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1377 Entry_Call.Called_Task := Acceptor;
1378 Entry_Call.Called_PO := Null_Address;
1379 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1385 if not Task_Do_Or_Queue
1386 (Self_Id, Entry_Call, With_Abort => True)
1388 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level - 1;
1390 (Debug.Trace (Self_Id, "TEC: exited to ATC level: " &
1391 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1397 Initialization.Undefer_Abort (Self_Id);
1399 if Parameters.Runtime_Traces then
1400 Send_Trace_Info (E_Missed, Acceptor);
1403 raise Tasking_Error;
1406 -- The following is special for async. entry calls.
1407 -- If the call was not queued abortably, we need to wait until
1408 -- it is before proceeding with the abortable part.
1410 -- Wait_Until_Abortable can be called unconditionally here,
1411 -- but it is expensive.
1413 if Entry_Call.State < Was_Abortable then
1414 Entry_Calls.Wait_Until_Abortable (Self_Id, Entry_Call);
1421 -- Note: following assignment needs to be atomic.
1423 Rendezvous_Successful := Entry_Call.State = Done;
1425 end Task_Entry_Call;
1427 -----------------------
1428 -- Task_Entry_Caller --
1429 -----------------------
1431 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_ID is
1432 Self_Id : constant Task_ID := STPO.Self;
1433 Entry_Call : Entry_Call_Link;
1436 Entry_Call := Self_Id.Common.Call;
1438 for Depth in 1 .. D loop
1439 Entry_Call := Entry_Call.Acceptor_Prev_Call;
1440 pragma Assert (Entry_Call /= null);
1443 return Entry_Call.Self;
1444 end Task_Entry_Caller;
1446 --------------------------
1447 -- Timed_Selective_Wait --
1448 --------------------------
1450 procedure Timed_Selective_Wait
1451 (Open_Accepts : Accept_List_Access;
1452 Select_Mode : Select_Modes;
1453 Uninterpreted_Data : out System.Address;
1456 Index : out Select_Index)
1458 Self_Id : constant Task_ID := STPO.Self;
1459 Treatment : Select_Treatment;
1460 Entry_Call : Entry_Call_Link;
1462 Selection : Select_Index;
1463 Open_Alternative : Boolean;
1464 Timedout : Boolean := False;
1465 Yielded : Boolean := True;
1468 pragma Assert (Select_Mode = Delay_Mode);
1470 Initialization.Defer_Abort (Self_Id);
1472 -- If we are aborted here, the effect will be pending
1478 STPO.Write_Lock (Self_Id);
1480 if not Self_Id.Callable then
1481 pragma Assert (Self_Id.Pending_ATC_Level = 0);
1483 pragma Assert (Self_Id.Pending_Action);
1485 STPO.Unlock (Self_Id);
1491 Initialization.Undefer_Abort (Self_Id);
1493 -- Should never get here ???
1495 pragma Assert (False);
1496 raise Standard'Abort_Signal;
1499 Uninterpreted_Data := Null_Address;
1501 pragma Assert (Open_Accepts /= null);
1503 Queuing.Select_Task_Entry_Call
1504 (Self_Id, Open_Accepts, Entry_Call, Selection, Open_Alternative);
1506 -- Determine the kind and disposition of the select.
1508 Treatment := Default_Treatment (Select_Mode);
1509 Self_Id.Chosen_Index := No_Rendezvous;
1511 if Open_Alternative then
1512 if Entry_Call /= null then
1513 if Open_Accepts (Selection).Null_Body then
1514 Treatment := Accept_Alternative_Completed;
1517 Setup_For_Rendezvous_With_Body (Entry_Call, Self_Id);
1518 Treatment := Accept_Alternative_Selected;
1521 Self_Id.Chosen_Index := Selection;
1523 elsif Treatment = No_Alternative_Open then
1524 Treatment := Accept_Alternative_Open;
1528 -- Handle the select according to the disposition selected above.
1531 when Accept_Alternative_Selected =>
1532 -- Ready to rendezvous
1533 -- In this case the accept body is not Null_Body. Defer abort
1534 -- until it gets into the accept body.
1536 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1537 Initialization.Defer_Abort (Self_Id);
1538 STPO.Unlock (Self_Id);
1540 when Accept_Alternative_Completed =>
1541 -- Rendezvous is over
1543 if Parameters.Runtime_Traces then
1544 Send_Trace_Info (M_RDV_Complete, Entry_Call.Self);
1547 STPO.Unlock (Self_Id);
1548 Caller := Entry_Call.Self;
1550 STPO.Write_Lock (Caller);
1551 Initialization.Wakeup_Entry_Caller (Self_Id, Entry_Call, Done);
1552 STPO.Unlock (Caller);
1554 when Accept_Alternative_Open =>
1557 Self_Id.Open_Accepts := Open_Accepts;
1559 -- Wait for a normal call and a pending action until the
1560 -- Wakeup_Time is reached.
1562 Self_Id.Common.State := Acceptor_Sleep;
1565 Initialization.Poll_Base_Priority_Change (Self_Id);
1566 exit when Self_Id.Open_Accepts = null;
1569 Sleep (Self_Id, Acceptor_Sleep);
1571 if Parameters.Runtime_Traces then
1572 Send_Trace_Info (WT_Select,
1574 Integer (Open_Accepts'Length),
1578 STPO.Timed_Sleep (Self_Id, Timeout, Mode,
1579 Acceptor_Sleep, Timedout, Yielded);
1583 Self_Id.Open_Accepts := null;
1585 if Parameters.Runtime_Traces then
1586 Send_Trace_Info (E_Timeout);
1591 Self_Id.Common.State := Runnable;
1593 -- Self_Id.Common.Call should already be updated by the Caller if
1594 -- not aborted. It might also be ready to do rendezvous even if
1595 -- this wakes up due to an abortion.
1596 -- Therefore, if the call is not empty we need to do the
1597 -- rendezvous if the accept body is not Null_Body.
1599 if Self_Id.Chosen_Index /= No_Rendezvous
1600 and then Self_Id.Common.Call /= null
1601 and then not Open_Accepts (Self_Id.Chosen_Index).Null_Body
1603 Uninterpreted_Data := Self_Id.Common.Call.Uninterpreted_Data;
1605 pragma Assert (Self_Id.Deferral_Level = 1);
1607 Initialization.Defer_Abort_Nestable (Self_Id);
1609 -- Leave abort deferred until the accept body
1612 STPO.Unlock (Self_Id);
1614 when No_Alternative_Open =>
1615 -- In this case, Index will be No_Rendezvous on return. We sleep
1616 -- for the time we need to.
1617 -- Wait for a signal or timeout. A wakeup can be made
1618 -- for several reasons:
1619 -- 1) Delay is expired
1620 -- 2) Pending_Action needs to be checked
1621 -- (Abortion, Priority change)
1622 -- 3) Spurious wakeup
1624 Self_Id.Open_Accepts := null;
1625 Self_Id.Common.State := Acceptor_Sleep;
1627 Initialization.Poll_Base_Priority_Change (Self_Id);
1629 STPO.Timed_Sleep (Self_Id, Timeout, Mode, Acceptor_Sleep,
1632 Self_Id.Common.State := Runnable;
1634 STPO.Unlock (Self_Id);
1637 -- Should never get here
1638 pragma Assert (False);
1650 -- Caller has been chosen
1652 -- Self_Id.Common.Call should already be updated by the Caller
1654 -- Self_Id.Chosen_Index should either be updated by the Caller
1655 -- or by Test_Selective_Wait
1657 Index := Self_Id.Chosen_Index;
1658 Initialization.Undefer_Abort_Nestable (Self_Id);
1660 -- Start rendezvous, if not already completed
1661 end Timed_Selective_Wait;
1663 ---------------------------
1664 -- Timed_Task_Entry_Call --
1665 ---------------------------
1667 procedure Timed_Task_Entry_Call
1668 (Acceptor : Task_ID;
1669 E : Task_Entry_Index;
1670 Uninterpreted_Data : System.Address;
1673 Rendezvous_Successful : out Boolean)
1675 Self_Id : constant Task_ID := STPO.Self;
1677 Entry_Call : Entry_Call_Link;
1681 Initialization.Defer_Abort (Self_Id);
1682 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
1685 (Debug.Trace (Self_Id, "TTEC: entered ATC level: " &
1686 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1688 if Parameters.Runtime_Traces then
1689 Send_Trace_Info (WT_Call, Acceptor,
1690 Entry_Index (E), Timeout);
1693 Level := Self_Id.ATC_Nesting_Level;
1694 Entry_Call := Self_Id.Entry_Calls (Level)'Access;
1695 Entry_Call.Next := null;
1696 Entry_Call.Mode := Timed_Call;
1697 Entry_Call.Cancellation_Attempted := False;
1699 -- If this is a call made inside of an abort deferred region,
1700 -- the call should be never abortable.
1702 if Self_Id.Deferral_Level > 1 then
1703 Entry_Call.State := Never_Abortable;
1705 Entry_Call.State := Now_Abortable;
1708 Entry_Call.E := Entry_Index (E);
1709 Entry_Call.Prio := Get_Priority (Self_Id);
1710 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
1711 Entry_Call.Called_Task := Acceptor;
1712 Entry_Call.Called_PO := Null_Address;
1713 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
1715 -- Note: the caller will undefer abortion on return (see WARNING above)
1721 if not Task_Do_Or_Queue
1722 (Self_Id, Entry_Call, With_Abort => True)
1724 Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level - 1;
1727 (Debug.Trace (Self_Id, "TTEC: exited to ATC level: " &
1728 ATC_Level'Image (Self_Id.ATC_Nesting_Level), 'A
'));
1734 Initialization.Undefer_Abort (Self_Id);
1736 if Parameters.Runtime_Traces then
1737 Send_Trace_Info (E_Missed, Acceptor);
1739 raise Tasking_Error;
1742 Write_Lock (Self_Id);
1743 Entry_Calls.Wait_For_Completion_With_Timeout
1744 (Entry_Call, Timeout, Mode, Yielded);
1751 -- ??? Do we need to yield in case Yielded is False
1753 Rendezvous_Successful := Entry_Call.State = Done;
1754 Initialization.Undefer_Abort (Self_Id);
1755 Entry_Calls.Check_Exception (Self_Id, Entry_Call);
1756 end Timed_Task_Entry_Call;
1762 -- Call this only with abort deferred and holding lock of Self_Id.
1763 -- Wait for normal call and a pending action.
1765 procedure Wait_For_Call (Self_Id : Task_ID) is
1767 Self_Id.Common.State := Acceptor_Sleep;
1770 Initialization.Poll_Base_Priority_Change (Self_Id);
1772 exit when Self_Id.Open_Accepts = null;
1774 Sleep (Self_Id, Acceptor_Sleep);
1777 Self_Id.Common.State := Runnable;
1780 end System.Tasking.Rendezvous;