annotate gcc/ada/libgnarl/s-taenca.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . T A S K I N G . E N T R Y _ C A L L S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with System.Task_Primitives.Operations;
kono
parents:
diff changeset
33 with System.Tasking.Initialization;
kono
parents:
diff changeset
34 with System.Tasking.Protected_Objects.Entries;
kono
parents:
diff changeset
35 with System.Tasking.Protected_Objects.Operations;
kono
parents:
diff changeset
36 with System.Tasking.Queuing;
kono
parents:
diff changeset
37 with System.Tasking.Utilities;
kono
parents:
diff changeset
38 with System.Parameters;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 package body System.Tasking.Entry_Calls is
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 package STPO renames System.Task_Primitives.Operations;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 use Parameters;
kono
parents:
diff changeset
45 use Protected_Objects.Entries;
kono
parents:
diff changeset
46 use Protected_Objects.Operations;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- DO NOT use Protected_Objects.Lock or Protected_Objects.Unlock
kono
parents:
diff changeset
49 -- internally. Those operations will raise Program_Error, which
kono
parents:
diff changeset
50 -- we are not prepared to handle inside the RTS. Instead, use
kono
parents:
diff changeset
51 -- System.Task_Primitives lock operations directly on Protection.L.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -----------------------
kono
parents:
diff changeset
54 -- Local Subprograms --
kono
parents:
diff changeset
55 -----------------------
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 procedure Lock_Server (Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- This locks the server targeted by Entry_Call
kono
parents:
diff changeset
60 --
kono
parents:
diff changeset
61 -- This may be a task or a protected object, depending on the target of the
kono
parents:
diff changeset
62 -- original call or any subsequent requeues.
kono
parents:
diff changeset
63 --
kono
parents:
diff changeset
64 -- This routine is needed because the field specifying the server for this
kono
parents:
diff changeset
65 -- call must be protected by the server's mutex. If it were protected by
kono
parents:
diff changeset
66 -- the caller's mutex, accessing the server's queues would require locking
kono
parents:
diff changeset
67 -- the caller to get the server, locking the server, and then accessing the
kono
parents:
diff changeset
68 -- queues. This involves holding two ATCB locks at once, something which we
kono
parents:
diff changeset
69 -- can guarantee that it will always be done in the same order, or locking
kono
parents:
diff changeset
70 -- a protected object while we hold an ATCB lock, something which is not
kono
parents:
diff changeset
71 -- permitted. Since the server cannot be obtained reliably, it must be
kono
parents:
diff changeset
72 -- obtained unreliably and then checked again once it has been locked.
kono
parents:
diff changeset
73 --
kono
parents:
diff changeset
74 -- If Single_Lock and server is a PO, release RTS_Lock
kono
parents:
diff changeset
75 --
kono
parents:
diff changeset
76 -- This should only be called by the Entry_Call.Self.
kono
parents:
diff changeset
77 -- It should be holding no other ATCB locks at the time.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 procedure Unlock_Server (Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
80 -- STPO.Unlock the server targeted by Entry_Call. The server must
kono
parents:
diff changeset
81 -- be locked before calling this.
kono
parents:
diff changeset
82 --
kono
parents:
diff changeset
83 -- If Single_Lock and server is a PO, take RTS_Lock on exit.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Unlock_And_Update_Server
kono
parents:
diff changeset
86 (Self_ID : Task_Id;
kono
parents:
diff changeset
87 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
88 -- Similar to Unlock_Server, but services entry calls if the
kono
parents:
diff changeset
89 -- server is a protected object.
kono
parents:
diff changeset
90 --
kono
parents:
diff changeset
91 -- If Single_Lock and server is a PO, take RTS_Lock on exit.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 procedure Check_Pending_Actions_For_Entry_Call
kono
parents:
diff changeset
94 (Self_ID : Task_Id;
kono
parents:
diff changeset
95 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
96 -- This procedure performs priority change of a queued call and dequeuing
kono
parents:
diff changeset
97 -- of an entry call when the call is cancelled. If the call is dequeued the
kono
parents:
diff changeset
98 -- state should be set to Cancelled. Call only with abort deferred and
kono
parents:
diff changeset
99 -- holding lock of Self_ID. This is a bit of common code for all entry
kono
parents:
diff changeset
100 -- calls. The effect is to do any deferred base priority change operation,
kono
parents:
diff changeset
101 -- in case some other task called STPO.Set_Priority while the current task
kono
parents:
diff changeset
102 -- had abort deferred, and to dequeue the call if the call has been
kono
parents:
diff changeset
103 -- aborted.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 procedure Poll_Base_Priority_Change_At_Entry_Call
kono
parents:
diff changeset
106 (Self_ID : Task_Id;
kono
parents:
diff changeset
107 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
108 pragma Inline (Poll_Base_Priority_Change_At_Entry_Call);
kono
parents:
diff changeset
109 -- A specialized version of Poll_Base_Priority_Change, that does the
kono
parents:
diff changeset
110 -- optional entry queue reordering. Has to be called with the Self_ID's
kono
parents:
diff changeset
111 -- ATCB write-locked. May temporarily release the lock.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 ---------------------
kono
parents:
diff changeset
114 -- Check_Exception --
kono
parents:
diff changeset
115 ---------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Check_Exception
kono
parents:
diff changeset
118 (Self_ID : Task_Id;
kono
parents:
diff changeset
119 Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
120 is
kono
parents:
diff changeset
121 pragma Warnings (Off, Self_ID);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 use type Ada.Exceptions.Exception_Id;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 procedure Internal_Raise (X : Ada.Exceptions.Exception_Id);
kono
parents:
diff changeset
126 pragma Import (C, Internal_Raise, "__gnat_raise_with_msg");
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 E : constant Ada.Exceptions.Exception_Id :=
kono
parents:
diff changeset
129 Entry_Call.Exception_To_Raise;
kono
parents:
diff changeset
130 begin
kono
parents:
diff changeset
131 -- pragma Assert (Self_ID.Deferral_Level = 0);
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- The above may be useful for debugging, but the Florist packages
kono
parents:
diff changeset
134 -- contain critical sections that defer abort and then do entry calls,
kono
parents:
diff changeset
135 -- which causes the above Assert to trip.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 if E /= Ada.Exceptions.Null_Id then
kono
parents:
diff changeset
138 Internal_Raise (E);
kono
parents:
diff changeset
139 end if;
kono
parents:
diff changeset
140 end Check_Exception;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 ------------------------------------------
kono
parents:
diff changeset
143 -- Check_Pending_Actions_For_Entry_Call --
kono
parents:
diff changeset
144 ------------------------------------------
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 procedure Check_Pending_Actions_For_Entry_Call
kono
parents:
diff changeset
147 (Self_ID : Task_Id;
kono
parents:
diff changeset
148 Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
149 is
kono
parents:
diff changeset
150 begin
kono
parents:
diff changeset
151 pragma Assert (Self_ID = Entry_Call.Self);
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 Poll_Base_Priority_Change_At_Entry_Call (Self_ID, Entry_Call);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 if Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level
kono
parents:
diff changeset
156 and then Entry_Call.State = Now_Abortable
kono
parents:
diff changeset
157 then
kono
parents:
diff changeset
158 STPO.Unlock (Self_ID);
kono
parents:
diff changeset
159 Lock_Server (Entry_Call);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 if Queuing.Onqueue (Entry_Call)
kono
parents:
diff changeset
162 and then Entry_Call.State = Now_Abortable
kono
parents:
diff changeset
163 then
kono
parents:
diff changeset
164 Queuing.Dequeue_Call (Entry_Call);
kono
parents:
diff changeset
165 Entry_Call.State :=
kono
parents:
diff changeset
166 (if Entry_Call.Cancellation_Attempted then Cancelled else Done);
kono
parents:
diff changeset
167 Unlock_And_Update_Server (Self_ID, Entry_Call);
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 else
kono
parents:
diff changeset
170 Unlock_Server (Entry_Call);
kono
parents:
diff changeset
171 end if;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 STPO.Write_Lock (Self_ID);
kono
parents:
diff changeset
174 end if;
kono
parents:
diff changeset
175 end Check_Pending_Actions_For_Entry_Call;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -----------------
kono
parents:
diff changeset
178 -- Lock_Server --
kono
parents:
diff changeset
179 -----------------
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 procedure Lock_Server (Entry_Call : Entry_Call_Link) is
kono
parents:
diff changeset
182 Test_Task : Task_Id;
kono
parents:
diff changeset
183 Test_PO : Protection_Entries_Access;
kono
parents:
diff changeset
184 Ceiling_Violation : Boolean;
kono
parents:
diff changeset
185 Failures : Integer := 0;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 begin
kono
parents:
diff changeset
188 Test_Task := Entry_Call.Called_Task;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 loop
kono
parents:
diff changeset
191 if Test_Task = null then
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 -- Entry_Call was queued on a protected object, or in transition,
kono
parents:
diff changeset
194 -- when we last fetched Test_Task.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 Test_PO := To_Protection (Entry_Call.Called_PO);
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 if Test_PO = null then
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 -- We had very bad luck, interleaving with TWO different
kono
parents:
diff changeset
201 -- requeue operations. Go around the loop and try again.
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 if Single_Lock then
kono
parents:
diff changeset
204 STPO.Unlock_RTS;
kono
parents:
diff changeset
205 STPO.Yield;
kono
parents:
diff changeset
206 STPO.Lock_RTS;
kono
parents:
diff changeset
207 else
kono
parents:
diff changeset
208 STPO.Yield;
kono
parents:
diff changeset
209 end if;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 else
kono
parents:
diff changeset
212 if Single_Lock then
kono
parents:
diff changeset
213 STPO.Unlock_RTS;
kono
parents:
diff changeset
214 end if;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 Lock_Entries_With_Status (Test_PO, Ceiling_Violation);
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 -- ???
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 -- The following code allows Lock_Server to be called when
kono
parents:
diff changeset
221 -- cancelling a call, to allow for the possibility that the
kono
parents:
diff changeset
222 -- priority of the caller has been raised beyond that of the
kono
parents:
diff changeset
223 -- protected entry call by Ada.Dynamic_Priorities.Set_Priority.
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 -- If the current task has a higher priority than the ceiling
kono
parents:
diff changeset
226 -- of the protected object, temporarily lower it. It will
kono
parents:
diff changeset
227 -- be reset in Unlock.
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if Ceiling_Violation then
kono
parents:
diff changeset
230 declare
kono
parents:
diff changeset
231 Current_Task : constant Task_Id := STPO.Self;
kono
parents:
diff changeset
232 Old_Base_Priority : System.Any_Priority;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 begin
kono
parents:
diff changeset
235 if Single_Lock then
kono
parents:
diff changeset
236 STPO.Lock_RTS;
kono
parents:
diff changeset
237 end if;
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 STPO.Write_Lock (Current_Task);
kono
parents:
diff changeset
240 Old_Base_Priority := Current_Task.Common.Base_Priority;
kono
parents:
diff changeset
241 Current_Task.New_Base_Priority := Test_PO.Ceiling;
kono
parents:
diff changeset
242 System.Tasking.Initialization.Change_Base_Priority
kono
parents:
diff changeset
243 (Current_Task);
kono
parents:
diff changeset
244 STPO.Unlock (Current_Task);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 if Single_Lock then
kono
parents:
diff changeset
247 STPO.Unlock_RTS;
kono
parents:
diff changeset
248 end if;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 -- Following lock should not fail
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 Lock_Entries (Test_PO);
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 Test_PO.Old_Base_Priority := Old_Base_Priority;
kono
parents:
diff changeset
255 Test_PO.Pending_Action := True;
kono
parents:
diff changeset
256 end;
kono
parents:
diff changeset
257 end if;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 exit when To_Address (Test_PO) = Entry_Call.Called_PO;
kono
parents:
diff changeset
260 Unlock_Entries (Test_PO);
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 if Single_Lock then
kono
parents:
diff changeset
263 STPO.Lock_RTS;
kono
parents:
diff changeset
264 end if;
kono
parents:
diff changeset
265 end if;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 else
kono
parents:
diff changeset
268 STPO.Write_Lock (Test_Task);
kono
parents:
diff changeset
269 exit when Test_Task = Entry_Call.Called_Task;
kono
parents:
diff changeset
270 STPO.Unlock (Test_Task);
kono
parents:
diff changeset
271 end if;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 Test_Task := Entry_Call.Called_Task;
kono
parents:
diff changeset
274 Failures := Failures + 1;
kono
parents:
diff changeset
275 pragma Assert (Failures <= 5);
kono
parents:
diff changeset
276 end loop;
kono
parents:
diff changeset
277 end Lock_Server;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 ---------------------------------------------
kono
parents:
diff changeset
280 -- Poll_Base_Priority_Change_At_Entry_Call --
kono
parents:
diff changeset
281 ---------------------------------------------
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 procedure Poll_Base_Priority_Change_At_Entry_Call
kono
parents:
diff changeset
284 (Self_ID : Task_Id;
kono
parents:
diff changeset
285 Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
286 is
kono
parents:
diff changeset
287 begin
kono
parents:
diff changeset
288 if Self_ID.Pending_Priority_Change then
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 -- Check for ceiling violations ???
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 Self_ID.Pending_Priority_Change := False;
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 -- Requeue the entry call at the new priority. We need to requeue
kono
parents:
diff changeset
295 -- even if the new priority is the same than the previous (see ACATS
kono
parents:
diff changeset
296 -- test cxd4006).
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 STPO.Unlock (Self_ID);
kono
parents:
diff changeset
299 Lock_Server (Entry_Call);
kono
parents:
diff changeset
300 Queuing.Requeue_Call_With_New_Prio
kono
parents:
diff changeset
301 (Entry_Call, STPO.Get_Priority (Self_ID));
kono
parents:
diff changeset
302 Unlock_And_Update_Server (Self_ID, Entry_Call);
kono
parents:
diff changeset
303 STPO.Write_Lock (Self_ID);
kono
parents:
diff changeset
304 end if;
kono
parents:
diff changeset
305 end Poll_Base_Priority_Change_At_Entry_Call;
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 --------------------
kono
parents:
diff changeset
308 -- Reset_Priority --
kono
parents:
diff changeset
309 --------------------
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 procedure Reset_Priority
kono
parents:
diff changeset
312 (Acceptor : Task_Id;
kono
parents:
diff changeset
313 Acceptor_Prev_Priority : Rendezvous_Priority)
kono
parents:
diff changeset
314 is
kono
parents:
diff changeset
315 begin
kono
parents:
diff changeset
316 pragma Assert (Acceptor = STPO.Self);
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 -- Since we limit this kind of "active" priority change to be done
kono
parents:
diff changeset
319 -- by the task for itself, we don't need to lock Acceptor.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 if Acceptor_Prev_Priority /= Priority_Not_Boosted then
kono
parents:
diff changeset
322 STPO.Set_Priority (Acceptor, Acceptor_Prev_Priority,
kono
parents:
diff changeset
323 Loss_Of_Inheritance => True);
kono
parents:
diff changeset
324 end if;
kono
parents:
diff changeset
325 end Reset_Priority;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 ------------------------------
kono
parents:
diff changeset
328 -- Try_To_Cancel_Entry_Call --
kono
parents:
diff changeset
329 ------------------------------
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 procedure Try_To_Cancel_Entry_Call (Succeeded : out Boolean) is
kono
parents:
diff changeset
332 Entry_Call : Entry_Call_Link;
kono
parents:
diff changeset
333 Self_ID : constant Task_Id := STPO.Self;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 use type Ada.Exceptions.Exception_Id;
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 begin
kono
parents:
diff changeset
338 Entry_Call := Self_ID.Entry_Calls (Self_ID.ATC_Nesting_Level)'Access;
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 -- Experimentation has shown that abort is sometimes (but not
kono
parents:
diff changeset
341 -- always) already deferred when Cancel_xxx_Entry_Call is called.
kono
parents:
diff changeset
342 -- That may indicate an error. Find out what is going on. ???
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 pragma Assert (Entry_Call.Mode = Asynchronous_Call);
kono
parents:
diff changeset
345 Initialization.Defer_Abort_Nestable (Self_ID);
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 if Single_Lock then
kono
parents:
diff changeset
348 STPO.Lock_RTS;
kono
parents:
diff changeset
349 end if;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 STPO.Write_Lock (Self_ID);
kono
parents:
diff changeset
352 Entry_Call.Cancellation_Attempted := True;
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 if Self_ID.Pending_ATC_Level >= Entry_Call.Level then
kono
parents:
diff changeset
355 Self_ID.Pending_ATC_Level := Entry_Call.Level - 1;
kono
parents:
diff changeset
356 end if;
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 Entry_Calls.Wait_For_Completion (Entry_Call);
kono
parents:
diff changeset
359 STPO.Unlock (Self_ID);
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 if Single_Lock then
kono
parents:
diff changeset
362 STPO.Unlock_RTS;
kono
parents:
diff changeset
363 end if;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 Succeeded := Entry_Call.State = Cancelled;
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 Initialization.Undefer_Abort_Nestable (Self_ID);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 -- Ideally, abort should no longer be deferred at this point, so we
kono
parents:
diff changeset
370 -- should be able to call Check_Exception. The loop below should be
kono
parents:
diff changeset
371 -- considered temporary, to work around the possibility that abort
kono
parents:
diff changeset
372 -- may be deferred more than one level deep ???
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 if Entry_Call.Exception_To_Raise /= Ada.Exceptions.Null_Id then
kono
parents:
diff changeset
375 while Self_ID.Deferral_Level > 0 loop
kono
parents:
diff changeset
376 System.Tasking.Initialization.Undefer_Abort_Nestable (Self_ID);
kono
parents:
diff changeset
377 end loop;
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 Entry_Calls.Check_Exception (Self_ID, Entry_Call);
kono
parents:
diff changeset
380 end if;
kono
parents:
diff changeset
381 end Try_To_Cancel_Entry_Call;
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 ------------------------------
kono
parents:
diff changeset
384 -- Unlock_And_Update_Server --
kono
parents:
diff changeset
385 ------------------------------
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 procedure Unlock_And_Update_Server
kono
parents:
diff changeset
388 (Self_ID : Task_Id;
kono
parents:
diff changeset
389 Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
390 is
kono
parents:
diff changeset
391 Called_PO : Protection_Entries_Access;
kono
parents:
diff changeset
392 Caller : Task_Id;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 begin
kono
parents:
diff changeset
395 if Entry_Call.Called_Task /= null then
kono
parents:
diff changeset
396 STPO.Unlock (Entry_Call.Called_Task);
kono
parents:
diff changeset
397 else
kono
parents:
diff changeset
398 Called_PO := To_Protection (Entry_Call.Called_PO);
kono
parents:
diff changeset
399 PO_Service_Entries (Self_ID, Called_PO, False);
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 if Called_PO.Pending_Action then
kono
parents:
diff changeset
402 Called_PO.Pending_Action := False;
kono
parents:
diff changeset
403 Caller := STPO.Self;
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 if Single_Lock then
kono
parents:
diff changeset
406 STPO.Lock_RTS;
kono
parents:
diff changeset
407 end if;
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 STPO.Write_Lock (Caller);
kono
parents:
diff changeset
410 Caller.New_Base_Priority := Called_PO.Old_Base_Priority;
kono
parents:
diff changeset
411 Initialization.Change_Base_Priority (Caller);
kono
parents:
diff changeset
412 STPO.Unlock (Caller);
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 if Single_Lock then
kono
parents:
diff changeset
415 STPO.Unlock_RTS;
kono
parents:
diff changeset
416 end if;
kono
parents:
diff changeset
417 end if;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 Unlock_Entries (Called_PO);
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 if Single_Lock then
kono
parents:
diff changeset
422 STPO.Lock_RTS;
kono
parents:
diff changeset
423 end if;
kono
parents:
diff changeset
424 end if;
kono
parents:
diff changeset
425 end Unlock_And_Update_Server;
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 -------------------
kono
parents:
diff changeset
428 -- Unlock_Server --
kono
parents:
diff changeset
429 -------------------
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 procedure Unlock_Server (Entry_Call : Entry_Call_Link) is
kono
parents:
diff changeset
432 Caller : Task_Id;
kono
parents:
diff changeset
433 Called_PO : Protection_Entries_Access;
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 begin
kono
parents:
diff changeset
436 if Entry_Call.Called_Task /= null then
kono
parents:
diff changeset
437 STPO.Unlock (Entry_Call.Called_Task);
kono
parents:
diff changeset
438 else
kono
parents:
diff changeset
439 Called_PO := To_Protection (Entry_Call.Called_PO);
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 if Called_PO.Pending_Action then
kono
parents:
diff changeset
442 Called_PO.Pending_Action := False;
kono
parents:
diff changeset
443 Caller := STPO.Self;
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 if Single_Lock then
kono
parents:
diff changeset
446 STPO.Lock_RTS;
kono
parents:
diff changeset
447 end if;
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 STPO.Write_Lock (Caller);
kono
parents:
diff changeset
450 Caller.New_Base_Priority := Called_PO.Old_Base_Priority;
kono
parents:
diff changeset
451 Initialization.Change_Base_Priority (Caller);
kono
parents:
diff changeset
452 STPO.Unlock (Caller);
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 if Single_Lock then
kono
parents:
diff changeset
455 STPO.Unlock_RTS;
kono
parents:
diff changeset
456 end if;
kono
parents:
diff changeset
457 end if;
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 Unlock_Entries (Called_PO);
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 if Single_Lock then
kono
parents:
diff changeset
462 STPO.Lock_RTS;
kono
parents:
diff changeset
463 end if;
kono
parents:
diff changeset
464 end if;
kono
parents:
diff changeset
465 end Unlock_Server;
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 -------------------------
kono
parents:
diff changeset
468 -- Wait_For_Completion --
kono
parents:
diff changeset
469 -------------------------
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 procedure Wait_For_Completion (Entry_Call : Entry_Call_Link) is
kono
parents:
diff changeset
472 Self_Id : constant Task_Id := Entry_Call.Self;
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 begin
kono
parents:
diff changeset
475 -- If this is a conditional call, it should be cancelled when it
kono
parents:
diff changeset
476 -- becomes abortable. This is checked in the loop below.
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 Self_Id.Common.State := Entry_Caller_Sleep;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 -- Try to remove calls to Sleep in the loop below by letting the caller
kono
parents:
diff changeset
481 -- a chance of getting ready immediately, using Unlock & Yield.
kono
parents:
diff changeset
482 -- See similar action in Wait_For_Call & Timed_Selective_Wait.
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 if Single_Lock then
kono
parents:
diff changeset
485 STPO.Unlock_RTS;
kono
parents:
diff changeset
486 else
kono
parents:
diff changeset
487 STPO.Unlock (Self_Id);
kono
parents:
diff changeset
488 end if;
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 if Entry_Call.State < Done then
kono
parents:
diff changeset
491 STPO.Yield;
kono
parents:
diff changeset
492 end if;
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 if Single_Lock then
kono
parents:
diff changeset
495 STPO.Lock_RTS;
kono
parents:
diff changeset
496 else
kono
parents:
diff changeset
497 STPO.Write_Lock (Self_Id);
kono
parents:
diff changeset
498 end if;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 loop
kono
parents:
diff changeset
501 Check_Pending_Actions_For_Entry_Call (Self_Id, Entry_Call);
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 exit when Entry_Call.State >= Done;
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 STPO.Sleep (Self_Id, Entry_Caller_Sleep);
kono
parents:
diff changeset
506 end loop;
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 Self_Id.Common.State := Runnable;
kono
parents:
diff changeset
509 Utilities.Exit_One_ATC_Level (Self_Id);
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 end Wait_For_Completion;
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 --------------------------------------
kono
parents:
diff changeset
514 -- Wait_For_Completion_With_Timeout --
kono
parents:
diff changeset
515 --------------------------------------
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 procedure Wait_For_Completion_With_Timeout
kono
parents:
diff changeset
518 (Entry_Call : Entry_Call_Link;
kono
parents:
diff changeset
519 Wakeup_Time : Duration;
kono
parents:
diff changeset
520 Mode : Delay_Modes;
kono
parents:
diff changeset
521 Yielded : out Boolean)
kono
parents:
diff changeset
522 is
kono
parents:
diff changeset
523 Self_Id : constant Task_Id := Entry_Call.Self;
kono
parents:
diff changeset
524 Timedout : Boolean := False;
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 begin
kono
parents:
diff changeset
527 -- This procedure waits for the entry call to be served, with a timeout.
kono
parents:
diff changeset
528 -- It tries to cancel the call if the timeout expires before the call is
kono
parents:
diff changeset
529 -- served.
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 -- If we wake up from the timed sleep operation here, it may be for
kono
parents:
diff changeset
532 -- several possible reasons:
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 -- 1) The entry call is done being served.
kono
parents:
diff changeset
535 -- 2) There is an abort or priority change to be served.
kono
parents:
diff changeset
536 -- 3) The timeout has expired (Timedout = True)
kono
parents:
diff changeset
537 -- 4) There has been a spurious wakeup.
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 -- Once the timeout has expired we may need to continue to wait if the
kono
parents:
diff changeset
540 -- call is already being serviced. In that case, we want to go back to
kono
parents:
diff changeset
541 -- sleep, but without any timeout. The variable Timedout is used to
kono
parents:
diff changeset
542 -- control this. If the Timedout flag is set, we do not need to
kono
parents:
diff changeset
543 -- STPO.Sleep with a timeout. We just sleep until we get a wakeup for
kono
parents:
diff changeset
544 -- some status change.
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 -- The original call may have become abortable after waking up. We want
kono
parents:
diff changeset
547 -- to check Check_Pending_Actions_For_Entry_Call again in any case.
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 pragma Assert (Entry_Call.Mode = Timed_Call);
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 Yielded := False;
kono
parents:
diff changeset
552 Self_Id.Common.State := Entry_Caller_Sleep;
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 -- Looping is necessary in case the task wakes up early from the timed
kono
parents:
diff changeset
555 -- sleep, due to a "spurious wakeup". Spurious wakeups are a weakness of
kono
parents:
diff changeset
556 -- POSIX condition variables. A thread waiting for a condition variable
kono
parents:
diff changeset
557 -- is allowed to wake up at any time, not just when the condition is
kono
parents:
diff changeset
558 -- signaled. See same loop in the ordinary Wait_For_Completion, above.
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 loop
kono
parents:
diff changeset
561 Check_Pending_Actions_For_Entry_Call (Self_Id, Entry_Call);
kono
parents:
diff changeset
562 exit when Entry_Call.State >= Done;
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 STPO.Timed_Sleep (Self_Id, Wakeup_Time, Mode,
kono
parents:
diff changeset
565 Entry_Caller_Sleep, Timedout, Yielded);
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 if Timedout then
kono
parents:
diff changeset
568 -- Try to cancel the call (see Try_To_Cancel_Entry_Call for
kono
parents:
diff changeset
569 -- corresponding code in the ATC case).
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 Entry_Call.Cancellation_Attempted := True;
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 -- Reset Entry_Call.State so that the call is marked as cancelled
kono
parents:
diff changeset
574 -- by Check_Pending_Actions_For_Entry_Call below.
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 if Entry_Call.State < Was_Abortable then
kono
parents:
diff changeset
577 Entry_Call.State := Now_Abortable;
kono
parents:
diff changeset
578 end if;
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 if Self_Id.Pending_ATC_Level >= Entry_Call.Level then
kono
parents:
diff changeset
581 Self_Id.Pending_ATC_Level := Entry_Call.Level - 1;
kono
parents:
diff changeset
582 end if;
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 -- The following loop is the same as the loop and exit code
kono
parents:
diff changeset
585 -- from the ordinary Wait_For_Completion. If we get here, we
kono
parents:
diff changeset
586 -- have timed out but we need to keep waiting until the call
kono
parents:
diff changeset
587 -- has actually completed or been cancelled successfully.
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 loop
kono
parents:
diff changeset
590 Check_Pending_Actions_For_Entry_Call (Self_Id, Entry_Call);
kono
parents:
diff changeset
591 exit when Entry_Call.State >= Done;
kono
parents:
diff changeset
592 STPO.Sleep (Self_Id, Entry_Caller_Sleep);
kono
parents:
diff changeset
593 end loop;
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 Self_Id.Common.State := Runnable;
kono
parents:
diff changeset
596 Utilities.Exit_One_ATC_Level (Self_Id);
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 return;
kono
parents:
diff changeset
599 end if;
kono
parents:
diff changeset
600 end loop;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 -- This last part is the same as ordinary Wait_For_Completion,
kono
parents:
diff changeset
603 -- and is only executed if the call completed without timing out.
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 Self_Id.Common.State := Runnable;
kono
parents:
diff changeset
606 Utilities.Exit_One_ATC_Level (Self_Id);
kono
parents:
diff changeset
607 end Wait_For_Completion_With_Timeout;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 --------------------------
kono
parents:
diff changeset
610 -- Wait_Until_Abortable --
kono
parents:
diff changeset
611 --------------------------
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 procedure Wait_Until_Abortable
kono
parents:
diff changeset
614 (Self_ID : Task_Id;
kono
parents:
diff changeset
615 Call : Entry_Call_Link)
kono
parents:
diff changeset
616 is
kono
parents:
diff changeset
617 begin
kono
parents:
diff changeset
618 pragma Assert (Self_ID.ATC_Nesting_Level > 0);
kono
parents:
diff changeset
619 pragma Assert (Call.Mode = Asynchronous_Call);
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 STPO.Write_Lock (Self_ID);
kono
parents:
diff changeset
622 Self_ID.Common.State := Entry_Caller_Sleep;
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 loop
kono
parents:
diff changeset
625 Check_Pending_Actions_For_Entry_Call (Self_ID, Call);
kono
parents:
diff changeset
626 exit when Call.State >= Was_Abortable;
kono
parents:
diff changeset
627 STPO.Sleep (Self_ID, Async_Select_Sleep);
kono
parents:
diff changeset
628 end loop;
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 Self_ID.Common.State := Runnable;
kono
parents:
diff changeset
631 STPO.Unlock (Self_ID);
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 end Wait_Until_Abortable;
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 end System.Tasking.Entry_Calls;