1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- SYSTEM.TASKING.PROTECTED_OBJECTS.OPERATIONS --
9 -- Copyright (C) 1998-2012, 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 -- This package contains all extended primitives related to Protected_Objects
35 -- The handling of protected objects with no entries is done in
36 -- System.Tasking.Protected_Objects, the simple routines for protected
37 -- objects with entries in System.Tasking.Protected_Objects.Entries.
39 -- The split between Entries and Operations is needed to break circular
40 -- dependencies inside the run time.
42 -- This package contains all primitives related to Protected_Objects.
43 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
45 with System
.Task_Primitives
.Operations
;
46 with System
.Tasking
.Entry_Calls
;
47 with System
.Tasking
.Queuing
;
48 with System
.Tasking
.Rendezvous
;
49 with System
.Tasking
.Utilities
;
50 with System
.Tasking
.Debug
;
51 with System
.Parameters
;
52 with System
.Traces
.Tasking
;
53 with System
.Restrictions
;
55 with System
.Tasking
.Initialization
;
56 pragma Elaborate_All
(System
.Tasking
.Initialization
);
57 -- Insures that tasking is initialized if any protected objects are created
59 package body System
.Tasking
.Protected_Objects
.Operations
is
61 package STPO
renames System
.Task_Primitives
.Operations
;
68 use System
.Restrictions
;
69 use System
.Restrictions
.Rident
;
71 use System
.Traces
.Tasking
;
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 procedure Update_For_Queue_To_PO
78 (Entry_Call
: Entry_Call_Link
;
79 With_Abort
: Boolean);
80 pragma Inline
(Update_For_Queue_To_PO
);
81 -- Update the state of an existing entry call to reflect the fact that it
82 -- is being enqueued, based on whether the current queuing action is with
83 -- or without abort. Call this only while holding the PO's lock. It returns
84 -- with the PO's lock still held.
86 procedure Requeue_Call
88 Object
: Protection_Entries_Access
;
89 Entry_Call
: Entry_Call_Link
);
90 -- Handle requeue of Entry_Call.
91 -- In particular, queue the call if needed, or service it immediately
94 ---------------------------------
95 -- Cancel_Protected_Entry_Call --
96 ---------------------------------
98 -- Compiler interface only (do not call from within the RTS)
100 -- This should have analogous effect to Cancel_Task_Entry_Call, setting
101 -- the value of Block.Cancelled instead of returning the parameter value
104 -- The effect should be idempotent, since the call may already have been
118 -- X : protected_entry_index := 1;
119 -- B80b : communication_block;
120 -- communication_blockIP (B80b);
126 -- procedure _clean is
128 -- if enqueued (B80b) then
129 -- cancel_protected_entry_call (B80b);
135 -- protected_entry_call (rTV!(r)._object'unchecked_access, X,
136 -- null_address, asynchronous_call, B80b, objectF => 0);
137 -- if enqueued (B80b) then
145 -- when _abort_signal =>
146 -- abort_undefer.all;
150 -- if not cancelled (B80b) then
155 -- If the entry call completes after we get into the abortable part,
156 -- Abort_Signal should be raised and ATC will take us to the at-end
157 -- handler, which will call _clean.
159 -- If the entry call returns with the call already completed, we can skip
160 -- this, and use the "if enqueued()" to go past the at-end handler, but we
161 -- will still call _clean.
163 -- If the abortable part completes before the entry call is Done, it will
166 -- If the entry call or the abortable part raises an exception,
167 -- we will still call _clean, but the value of Cancelled should not matter.
169 -- Whoever calls _clean first gets to decide whether the call
170 -- has been "cancelled".
172 -- Enqueued should be true if there is any chance that the call is still on
173 -- a queue. It seems to be safe to make it True if the call was Onqueue at
174 -- some point before return from Protected_Entry_Call.
176 -- Cancelled should be true iff the abortable part completed
177 -- and succeeded in cancelling the entry call before it completed.
180 -- The need for Enqueued is less obvious. The "if enqueued ()" tests are
181 -- not necessary, since Cancel_Protected_Entry_Call/Protected_Entry_Call
182 -- must do the same test internally, with locking. The one that makes
183 -- cancellation conditional may be a useful heuristic since at least 1/2
184 -- the time the call should be off-queue by that point. The other one seems
185 -- totally useless, since Protected_Entry_Call must do the same check and
186 -- then possibly wait for the call to be abortable, internally.
188 -- We can check Call.State here without locking the caller's mutex,
189 -- since the call must be over after returning from Wait_For_Completion.
190 -- No other task can access the call record at this point.
192 procedure Cancel_Protected_Entry_Call
193 (Block
: in out Communication_Block
) is
195 Entry_Calls
.Try_To_Cancel_Entry_Call
(Block
.Cancelled
);
196 end Cancel_Protected_Entry_Call
;
202 function Cancelled
(Block
: Communication_Block
) return Boolean is
204 return Block
.Cancelled
;
207 -------------------------
208 -- Complete_Entry_Body --
209 -------------------------
211 procedure Complete_Entry_Body
(Object
: Protection_Entries_Access
) is
213 Exceptional_Complete_Entry_Body
(Object
, Ada
.Exceptions
.Null_Id
);
214 end Complete_Entry_Body
;
220 function Enqueued
(Block
: Communication_Block
) return Boolean is
222 return Block
.Enqueued
;
225 -------------------------------------
226 -- Exceptional_Complete_Entry_Body --
227 -------------------------------------
229 procedure Exceptional_Complete_Entry_Body
230 (Object
: Protection_Entries_Access
;
231 Ex
: Ada
.Exceptions
.Exception_Id
)
233 procedure Transfer_Occurrence
234 (Target
: Ada
.Exceptions
.Exception_Occurrence_Access
;
235 Source
: Ada
.Exceptions
.Exception_Occurrence
);
236 pragma Import
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
238 Entry_Call
: constant Entry_Call_Link
:= Object
.Call_In_Progress
;
243 (Debug
.Trace
(STPO
.Self
, "Exceptional_Complete_Entry_Body", 'P'));
245 -- We must have abort deferred, since we are inside a protected
248 if Entry_Call
/= null then
250 -- The call was not requeued
252 Entry_Call
.Exception_To_Raise
:= Ex
;
254 if Ex
/= Ada
.Exceptions
.Null_Id
then
256 -- An exception was raised and abort was deferred, so adjust
257 -- before propagating, otherwise the task will stay with deferral
258 -- enabled for its remaining life.
260 Self_Id
:= STPO
.Self
;
262 if not ZCX_By_Default
then
263 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
267 (Entry_Call
.Self
.Common
.Compiler_Data
.Current_Excep
'Access,
268 Self_Id
.Common
.Compiler_Data
.Current_Excep
);
271 -- Wakeup_Entry_Caller will be called from PO_Do_Or_Queue or
272 -- PO_Service_Entries on return.
276 if Runtime_Traces
then
278 -- ??? Entry_Call can be null
280 Send_Trace_Info
(PO_Done
, Entry_Call
.Self
);
282 end Exceptional_Complete_Entry_Body
;
288 procedure PO_Do_Or_Queue
290 Object
: Protection_Entries_Access
;
291 Entry_Call
: Entry_Call_Link
)
293 E
: constant Protected_Entry_Index
:=
294 Protected_Entry_Index
(Entry_Call
.E
);
295 Barrier_Value
: Boolean;
298 -- When the Action procedure for an entry body returns, it is either
299 -- completed (having called [Exceptional_]Complete_Entry_Body) or it
300 -- is queued, having executed a requeue statement.
303 Object
.Entry_Bodies
(
304 Object
.Find_Body_Index
(Object
.Compiler_Info
, E
)).
305 Barrier
(Object
.Compiler_Info
, E
);
307 if Barrier_Value
then
309 -- Not abortable while service is in progress
311 if Entry_Call
.State
= Now_Abortable
then
312 Entry_Call
.State
:= Was_Abortable
;
315 Object
.Call_In_Progress
:= Entry_Call
;
318 (Debug
.Trace
(Self_ID
, "PODOQ: start entry body", 'P'));
319 Object
.Entry_Bodies
(
320 Object
.Find_Body_Index
(Object
.Compiler_Info
, E
)).Action
(
321 Object
.Compiler_Info
, Entry_Call
.Uninterpreted_Data
, E
);
323 if Object
.Call_In_Progress
/= null then
325 -- Body of current entry served call to completion
327 Object
.Call_In_Progress
:= null;
333 STPO
.Write_Lock
(Entry_Call
.Self
);
334 Initialization
.Wakeup_Entry_Caller
(Self_ID
, Entry_Call
, Done
);
335 STPO
.Unlock
(Entry_Call
.Self
);
342 Requeue_Call
(Self_ID
, Object
, Entry_Call
);
345 elsif Entry_Call
.Mode
/= Conditional_Call
346 or else not Entry_Call
.With_Abort
349 if Run_Time_Restrictions
.Set
(Max_Entry_Queue_Length
)
351 Run_Time_Restrictions
.Value
(Max_Entry_Queue_Length
) <=
352 Queuing
.Count_Waiting
(Object
.Entry_Queues
(E
))
354 -- This violates the Max_Entry_Queue_Length restriction,
355 -- raise Program_Error.
357 Entry_Call
.Exception_To_Raise
:= Program_Error
'Identity;
363 STPO
.Write_Lock
(Entry_Call
.Self
);
364 Initialization
.Wakeup_Entry_Caller
(Self_ID
, Entry_Call
, Done
);
365 STPO
.Unlock
(Entry_Call
.Self
);
371 Queuing
.Enqueue
(Object
.Entry_Queues
(E
), Entry_Call
);
372 Update_For_Queue_To_PO
(Entry_Call
, Entry_Call
.With_Abort
);
375 -- Conditional_Call and With_Abort
381 STPO
.Write_Lock
(Entry_Call
.Self
);
382 pragma Assert
(Entry_Call
.State
/= Not_Yet_Abortable
);
383 Initialization
.Wakeup_Entry_Caller
(Self_ID
, Entry_Call
, Cancelled
);
384 STPO
.Unlock
(Entry_Call
.Self
);
393 Queuing
.Broadcast_Program_Error
(Self_ID
, Object
, Entry_Call
);
396 ------------------------
397 -- PO_Service_Entries --
398 ------------------------
400 procedure PO_Service_Entries
402 Object
: Entries
.Protection_Entries_Access
;
403 Unlock_Object
: Boolean := True)
405 E
: Protected_Entry_Index
;
407 Entry_Call
: Entry_Call_Link
;
411 Queuing
.Select_Protected_Entry_Call
(Self_ID
, Object
, Entry_Call
);
413 exit when Entry_Call
= null;
415 E
:= Protected_Entry_Index
(Entry_Call
.E
);
417 -- Not abortable while service is in progress
419 if Entry_Call
.State
= Now_Abortable
then
420 Entry_Call
.State
:= Was_Abortable
;
423 Object
.Call_In_Progress
:= Entry_Call
;
426 if Runtime_Traces
then
427 Send_Trace_Info
(PO_Run
, Self_ID
,
428 Entry_Call
.Self
, Entry_Index
(E
));
432 (Debug
.Trace
(Self_ID
, "POSE: start entry body", 'P'));
435 (Object
.Find_Body_Index
(Object
.Compiler_Info
, E
)).Action
436 (Object
.Compiler_Info
, Entry_Call
.Uninterpreted_Data
, E
);
440 Queuing
.Broadcast_Program_Error
441 (Self_ID
, Object
, Entry_Call
);
444 if Object
.Call_In_Progress
= null then
445 Requeue_Call
(Self_ID
, Object
, Entry_Call
);
446 exit when Entry_Call
.State
= Cancelled
;
449 Object
.Call_In_Progress
:= null;
450 Caller
:= Entry_Call
.Self
;
456 STPO
.Write_Lock
(Caller
);
457 Initialization
.Wakeup_Entry_Caller
(Self_ID
, Entry_Call
, Done
);
458 STPO
.Unlock
(Caller
);
466 if Unlock_Object
then
467 Unlock_Entries
(Object
);
469 end PO_Service_Entries
;
471 ---------------------
472 -- Protected_Count --
473 ---------------------
475 function Protected_Count
476 (Object
: Protection_Entries
'Class;
477 E
: Protected_Entry_Index
) return Natural
480 return Queuing
.Count_Waiting
(Object
.Entry_Queues
(E
));
483 --------------------------
484 -- Protected_Entry_Call --
485 --------------------------
487 -- Compiler interface only (do not call from within the RTS)
496 -- X : protected_entry_index := 1;
497 -- B85b : communication_block;
498 -- communication_blockIP (B85b);
501 -- protected_entry_call (rTV!(r)._object'unchecked_access, X,
502 -- null_address, conditional_call, B85b, objectF => 0);
504 -- if cancelled (B85b) then
511 -- See also Cancel_Protected_Entry_Call for code expansion of asynchronous
514 -- The initial part of this procedure does not need to lock the calling
515 -- task's ATCB, up to the point where the call record first may be queued
516 -- (PO_Do_Or_Queue), since before that no other task will have access to
519 -- If this is a call made inside of an abort deferred region, the call
520 -- should be never abortable.
522 -- If the call was not queued abortably, we need to wait until it is before
523 -- proceeding with the abortable part.
525 -- There are some heuristics here, just to save time for frequently
526 -- occurring cases. For example, we check Initially_Abortable to try to
527 -- avoid calling the procedure Wait_Until_Abortable, since the normal case
528 -- for async. entry calls is to be queued abortably.
530 -- Another heuristic uses the Block.Enqueued to try to avoid calling
531 -- Cancel_Protected_Entry_Call if the call can be served immediately.
533 procedure Protected_Entry_Call
534 (Object
: Protection_Entries_Access
;
535 E
: Protected_Entry_Index
;
536 Uninterpreted_Data
: System
.Address
;
538 Block
: out Communication_Block
)
540 Self_ID
: constant Task_Id
:= STPO
.Self
;
541 Entry_Call
: Entry_Call_Link
;
542 Initially_Abortable
: Boolean;
543 Ceiling_Violation
: Boolean;
547 (Debug
.Trace
(Self_ID
, "Protected_Entry_Call", 'P'));
549 if Runtime_Traces
then
550 Send_Trace_Info
(PO_Call
, Entry_Index
(E
));
553 if Self_ID
.ATC_Nesting_Level
= ATC_Level
'Last then
554 raise Storage_Error
with "not enough ATC nesting levels";
557 -- If pragma Detect_Blocking is active then Program_Error must be
558 -- raised if this potentially blocking operation is called from a
562 and then Self_ID
.Common
.Protected_Action_Nesting
> 0
564 raise Program_Error
with "potentially blocking operation";
567 -- Self_ID.Deferral_Level should be 0, except when called from Finalize,
568 -- where abort is already deferred.
570 Initialization
.Defer_Abort_Nestable
(Self_ID
);
571 Lock_Entries_With_Status
(Object
, Ceiling_Violation
);
573 if Ceiling_Violation
then
575 -- Failed ceiling check
577 Initialization
.Undefer_Abort_Nestable
(Self_ID
);
581 Block
.Self
:= Self_ID
;
582 Self_ID
.ATC_Nesting_Level
:= Self_ID
.ATC_Nesting_Level
+ 1;
584 (Debug
.Trace
(Self_ID
, "PEC: entered ATC level: " &
585 ATC_Level
'Image (Self_ID
.ATC_Nesting_Level
), 'A'));
587 Self_ID
.Entry_Calls
(Self_ID
.ATC_Nesting_Level
)'Access;
588 Entry_Call
.Next
:= null;
589 Entry_Call
.Mode
:= Mode
;
590 Entry_Call
.Cancellation_Attempted
:= False;
593 (if Self_ID
.Deferral_Level
> 1
594 then Never_Abortable
else Now_Abortable
);
596 Entry_Call
.E
:= Entry_Index
(E
);
597 Entry_Call
.Prio
:= STPO
.Get_Priority
(Self_ID
);
598 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
599 Entry_Call
.Called_PO
:= To_Address
(Object
);
600 Entry_Call
.Called_Task
:= null;
601 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
602 Entry_Call
.With_Abort
:= True;
604 PO_Do_Or_Queue
(Self_ID
, Object
, Entry_Call
);
605 Initially_Abortable
:= Entry_Call
.State
= Now_Abortable
;
606 PO_Service_Entries
(Self_ID
, Object
);
608 -- Try to prevent waiting later (in Try_To_Cancel_Protected_Entry_Call)
609 -- for completed or cancelled calls. (This is a heuristic, only.)
611 if Entry_Call
.State
>= Done
then
613 -- Once State >= Done it will not change any more
619 STPO
.Write_Lock
(Self_ID
);
620 Utilities
.Exit_One_ATC_Level
(Self_ID
);
621 STPO
.Unlock
(Self_ID
);
627 Block
.Enqueued
:= False;
628 Block
.Cancelled
:= Entry_Call
.State
= Cancelled
;
629 Initialization
.Undefer_Abort_Nestable
(Self_ID
);
630 Entry_Calls
.Check_Exception
(Self_ID
, Entry_Call
);
634 -- In this case we cannot conclude anything, since State can change
640 -- Now for the general case
642 if Mode
= Asynchronous_Call
then
644 -- Try to avoid an expensive call
646 if not Initially_Abortable
then
649 Entry_Calls
.Wait_Until_Abortable
(Self_ID
, Entry_Call
);
652 Entry_Calls
.Wait_Until_Abortable
(Self_ID
, Entry_Call
);
658 when Simple_Call | Conditional_Call
=>
661 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
665 STPO
.Write_Lock
(Self_ID
);
666 Entry_Calls
.Wait_For_Completion
(Entry_Call
);
667 STPO
.Unlock
(Self_ID
);
670 Block
.Cancelled
:= Entry_Call
.State
= Cancelled
;
672 when Asynchronous_Call | Timed_Call
=>
673 pragma Assert
(False);
678 Initialization
.Undefer_Abort_Nestable
(Self_ID
);
679 Entry_Calls
.Check_Exception
(Self_ID
, Entry_Call
);
680 end Protected_Entry_Call
;
686 procedure Requeue_Call
688 Object
: Protection_Entries_Access
;
689 Entry_Call
: Entry_Call_Link
)
691 New_Object
: Protection_Entries_Access
;
692 Ceiling_Violation
: Boolean;
694 E
: Protected_Entry_Index
;
697 New_Object
:= To_Protection
(Entry_Call
.Called_PO
);
699 if New_Object
= null then
701 -- Call is to be requeued to a task entry
707 Result
:= Rendezvous
.Task_Do_Or_Queue
(Self_Id
, Entry_Call
);
710 Queuing
.Broadcast_Program_Error
711 (Self_Id
, Object
, Entry_Call
, RTS_Locked
=> True);
719 -- Call should be requeued to a PO
721 if Object
/= New_Object
then
723 -- Requeue is to different PO
725 Lock_Entries_With_Status
(New_Object
, Ceiling_Violation
);
727 if Ceiling_Violation
then
728 Object
.Call_In_Progress
:= null;
729 Queuing
.Broadcast_Program_Error
(Self_Id
, Object
, Entry_Call
);
732 PO_Do_Or_Queue
(Self_Id
, New_Object
, Entry_Call
);
733 PO_Service_Entries
(Self_Id
, New_Object
);
737 -- Requeue is to same protected object
739 -- ??? Try to compensate apparent failure of the scheduler on some
740 -- OS (e.g VxWorks) to give higher priority tasks a chance to run
743 STPO
.Yield
(Do_Yield
=> False);
745 if Entry_Call
.With_Abort
746 and then Entry_Call
.Cancellation_Attempted
748 -- If this is a requeue with abort and someone tried to cancel
749 -- this call, cancel it at this point.
751 Entry_Call
.State
:= Cancelled
;
755 if not Entry_Call
.With_Abort
756 or else Entry_Call
.Mode
/= Conditional_Call
758 E
:= Protected_Entry_Index
(Entry_Call
.E
);
760 if Run_Time_Restrictions
.Set
(Max_Entry_Queue_Length
)
762 Run_Time_Restrictions
.Value
(Max_Entry_Queue_Length
) <=
763 Queuing
.Count_Waiting
(Object
.Entry_Queues
(E
))
765 -- This violates the Max_Entry_Queue_Length restriction,
766 -- raise Program_Error.
768 Entry_Call
.Exception_To_Raise
:= Program_Error
'Identity;
774 STPO
.Write_Lock
(Entry_Call
.Self
);
775 Initialization
.Wakeup_Entry_Caller
776 (Self_Id
, Entry_Call
, Done
);
777 STPO
.Unlock
(Entry_Call
.Self
);
785 (New_Object
.Entry_Queues
(E
), Entry_Call
);
786 Update_For_Queue_To_PO
(Entry_Call
, Entry_Call
.With_Abort
);
790 PO_Do_Or_Queue
(Self_Id
, New_Object
, Entry_Call
);
796 ----------------------------
797 -- Protected_Entry_Caller --
798 ----------------------------
800 function Protected_Entry_Caller
801 (Object
: Protection_Entries
'Class) return Task_Id
is
803 return Object
.Call_In_Progress
.Self
;
804 end Protected_Entry_Caller
;
806 -----------------------------
807 -- Requeue_Protected_Entry --
808 -----------------------------
810 -- Compiler interface only (do not call from within the RTS)
819 -- procedure rPT__E10b (O : address; P : address; E :
820 -- protected_entry_index) is
821 -- type rTVP is access rTV;
823 -- _object : rTVP := rTVP!(O);
826 -- rR : protection renames _object._object;
827 -- vP : integer renames _object.v;
828 -- bP : boolean renames _object.b;
832 -- requeue_protected_entry (rR'unchecked_access, rR'
833 -- unchecked_access, 2, false, objectF => 0, new_objectF =>
837 -- complete_entry_body (_object._object'unchecked_access, objectF =>
842 -- abort_undefer.all;
843 -- exceptional_complete_entry_body (_object._object'
844 -- unchecked_access, current_exception, objectF => 0);
848 procedure Requeue_Protected_Entry
849 (Object
: Protection_Entries_Access
;
850 New_Object
: Protection_Entries_Access
;
851 E
: Protected_Entry_Index
;
852 With_Abort
: Boolean)
854 Entry_Call
: constant Entry_Call_Link
:= Object
.Call_In_Progress
;
858 (Debug
.Trace
(STPO
.Self
, "Requeue_Protected_Entry", 'P'));
859 pragma Assert
(STPO
.Self
.Deferral_Level
> 0);
861 Entry_Call
.E
:= Entry_Index
(E
);
862 Entry_Call
.Called_PO
:= To_Address
(New_Object
);
863 Entry_Call
.Called_Task
:= null;
864 Entry_Call
.With_Abort
:= With_Abort
;
865 Object
.Call_In_Progress
:= null;
866 end Requeue_Protected_Entry
;
868 -------------------------------------
869 -- Requeue_Task_To_Protected_Entry --
870 -------------------------------------
872 -- Compiler interface only (do not call from within the RTS)
883 -- accept_call (1, A79b);
885 -- requeue_task_to_protected_entry (rTV!(r)._object'
886 -- unchecked_access, 2, false, new_objectF => 0);
889 -- complete_rendezvous;
892 -- when all others =>
893 -- exceptional_complete_rendezvous (get_gnat_exception);
896 procedure Requeue_Task_To_Protected_Entry
897 (New_Object
: Protection_Entries_Access
;
898 E
: Protected_Entry_Index
;
899 With_Abort
: Boolean)
901 Self_ID
: constant Task_Id
:= STPO
.Self
;
902 Entry_Call
: constant Entry_Call_Link
:= Self_ID
.Common
.Call
;
905 Initialization
.Defer_Abort
(Self_ID
);
907 -- We do not need to lock Self_ID here since the call is not abortable
908 -- at this point, and therefore, the caller cannot cancel the call.
910 Entry_Call
.Needs_Requeue
:= True;
911 Entry_Call
.With_Abort
:= With_Abort
;
912 Entry_Call
.Called_PO
:= To_Address
(New_Object
);
913 Entry_Call
.Called_Task
:= null;
914 Entry_Call
.E
:= Entry_Index
(E
);
915 Initialization
.Undefer_Abort
(Self_ID
);
916 end Requeue_Task_To_Protected_Entry
;
918 ---------------------
919 -- Service_Entries --
920 ---------------------
922 procedure Service_Entries
(Object
: Protection_Entries_Access
) is
923 Self_ID
: constant Task_Id
:= STPO
.Self
;
925 PO_Service_Entries
(Self_ID
, Object
);
928 --------------------------------
929 -- Timed_Protected_Entry_Call --
930 --------------------------------
932 -- Compiler interface only (do not call from within the RTS)
934 procedure Timed_Protected_Entry_Call
935 (Object
: Protection_Entries_Access
;
936 E
: Protected_Entry_Index
;
937 Uninterpreted_Data
: System
.Address
;
940 Entry_Call_Successful
: out Boolean)
942 Self_Id
: constant Task_Id
:= STPO
.Self
;
943 Entry_Call
: Entry_Call_Link
;
944 Ceiling_Violation
: Boolean;
947 pragma Unreferenced
(Yielded
);
950 if Self_Id
.ATC_Nesting_Level
= ATC_Level
'Last then
951 raise Storage_Error
with "not enough ATC nesting levels";
954 -- If pragma Detect_Blocking is active then Program_Error must be
955 -- raised if this potentially blocking operation is called from a
959 and then Self_Id
.Common
.Protected_Action_Nesting
> 0
961 raise Program_Error
with "potentially blocking operation";
964 if Runtime_Traces
then
965 Send_Trace_Info
(POT_Call
, Entry_Index
(E
), Timeout
);
968 Initialization
.Defer_Abort_Nestable
(Self_Id
);
969 Lock_Entries_With_Status
(Object
, Ceiling_Violation
);
971 if Ceiling_Violation
then
972 Initialization
.Undefer_Abort
(Self_Id
);
976 Self_Id
.ATC_Nesting_Level
:= Self_Id
.ATC_Nesting_Level
+ 1;
978 (Debug
.Trace
(Self_Id
, "TPEC: exited to ATC level: " &
979 ATC_Level
'Image (Self_Id
.ATC_Nesting_Level
), 'A'));
980 Entry_Call
:= Self_Id
.Entry_Calls
(Self_Id
.ATC_Nesting_Level
)'Access;
981 Entry_Call
.Next
:= null;
982 Entry_Call
.Mode
:= Timed_Call
;
983 Entry_Call
.Cancellation_Attempted
:= False;
986 (if Self_Id
.Deferral_Level
> 1
990 Entry_Call
.E
:= Entry_Index
(E
);
991 Entry_Call
.Prio
:= STPO
.Get_Priority
(Self_Id
);
992 Entry_Call
.Uninterpreted_Data
:= Uninterpreted_Data
;
993 Entry_Call
.Called_PO
:= To_Address
(Object
);
994 Entry_Call
.Called_Task
:= null;
995 Entry_Call
.Exception_To_Raise
:= Ada
.Exceptions
.Null_Id
;
996 Entry_Call
.With_Abort
:= True;
998 PO_Do_Or_Queue
(Self_Id
, Object
, Entry_Call
);
999 PO_Service_Entries
(Self_Id
, Object
);
1004 STPO
.Write_Lock
(Self_Id
);
1007 -- Try to avoid waiting for completed or cancelled calls
1009 if Entry_Call
.State
>= Done
then
1010 Utilities
.Exit_One_ATC_Level
(Self_Id
);
1015 STPO
.Unlock
(Self_Id
);
1018 Entry_Call_Successful
:= Entry_Call
.State
= Done
;
1019 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
1020 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
1024 Entry_Calls
.Wait_For_Completion_With_Timeout
1025 (Entry_Call
, Timeout
, Mode
, Yielded
);
1030 STPO
.Unlock
(Self_Id
);
1033 -- ??? Do we need to yield in case Yielded is False
1035 Initialization
.Undefer_Abort_Nestable
(Self_Id
);
1036 Entry_Call_Successful
:= Entry_Call
.State
= Done
;
1037 Entry_Calls
.Check_Exception
(Self_Id
, Entry_Call
);
1038 end Timed_Protected_Entry_Call
;
1040 ----------------------------
1041 -- Update_For_Queue_To_PO --
1042 ----------------------------
1044 -- Update the state of an existing entry call, based on
1045 -- whether the current queuing action is with or without abort.
1046 -- Call this only while holding the server's lock.
1047 -- It returns with the server's lock released.
1049 New_State
: constant array (Boolean, Entry_Call_State
)
1050 of Entry_Call_State
:=
1052 (Never_Abortable
=> Never_Abortable
,
1053 Not_Yet_Abortable
=> Now_Abortable
,
1054 Was_Abortable
=> Now_Abortable
,
1055 Now_Abortable
=> Now_Abortable
,
1057 Cancelled
=> Cancelled
),
1059 (Never_Abortable
=> Never_Abortable
,
1060 Not_Yet_Abortable
=> Not_Yet_Abortable
,
1061 Was_Abortable
=> Was_Abortable
,
1062 Now_Abortable
=> Now_Abortable
,
1064 Cancelled
=> Cancelled
)
1067 procedure Update_For_Queue_To_PO
1068 (Entry_Call
: Entry_Call_Link
;
1069 With_Abort
: Boolean)
1071 Old
: constant Entry_Call_State
:= Entry_Call
.State
;
1074 pragma Assert
(Old
< Done
);
1076 Entry_Call
.State
:= New_State
(With_Abort
, Entry_Call
.State
);
1078 if Entry_Call
.Mode
= Asynchronous_Call
then
1079 if Old
< Was_Abortable
and then
1080 Entry_Call
.State
= Now_Abortable
1086 STPO
.Write_Lock
(Entry_Call
.Self
);
1088 if Entry_Call
.Self
.Common
.State
= Async_Select_Sleep
then
1089 STPO
.Wakeup
(Entry_Call
.Self
, Async_Select_Sleep
);
1092 STPO
.Unlock
(Entry_Call
.Self
);
1100 elsif Entry_Call
.Mode
= Conditional_Call
then
1101 pragma Assert
(Entry_Call
.State
< Was_Abortable
);
1104 end Update_For_Queue_To_PO
;
1106 end System
.Tasking
.Protected_Objects
.Operations
;