annotate gcc/ada/libgnarl/s-tposen.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
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 -- SYSTEM.TASKING.PROTECTED_OBJECTS.SINGLE_ENTRY --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1998-2019, 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 pragma Style_Checks (All_Checks);
kono
parents:
diff changeset
33 -- Turn off subprogram ordering check, since restricted GNARLI subprograms are
kono
parents:
diff changeset
34 -- gathered together at end.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- This package provides an optimized version of Protected_Objects.Operations
kono
parents:
diff changeset
37 -- and Protected_Objects.Entries making the following assumptions:
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- PO has only one entry
kono
parents:
diff changeset
40 -- There is only one caller at a time (No_Entry_Queue)
kono
parents:
diff changeset
41 -- There is no dynamic priority support (No_Dynamic_Priorities)
kono
parents:
diff changeset
42 -- No Abort Statements
kono
parents:
diff changeset
43 -- (No_Abort_Statements, Max_Asynchronous_Select_Nesting => 0)
kono
parents:
diff changeset
44 -- PO are at library level
kono
parents:
diff changeset
45 -- No Requeue
kono
parents:
diff changeset
46 -- None of the tasks will terminate (no need for finalization)
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- This interface is intended to be used in the ravenscar and restricted
kono
parents:
diff changeset
49 -- profiles, the compiler is responsible for ensuring that the conditions
kono
parents:
diff changeset
50 -- mentioned above are respected, except for the No_Entry_Queue restriction
kono
parents:
diff changeset
51 -- that is checked dynamically in this package, since the check cannot be
kono
parents:
diff changeset
52 -- performed at compile time, and is relatively cheap (see PO_Do_Or_Queue,
kono
parents:
diff changeset
53 -- Service_Entry).
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 pragma Polling (Off);
kono
parents:
diff changeset
56 -- Turn off polling, we do not want polling to take place during tasking
kono
parents:
diff changeset
57 -- operations. It can cause infinite loops and other problems.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 pragma Suppress (All_Checks);
kono
parents:
diff changeset
60 -- Why is this required ???
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 with Ada.Exceptions;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 with System.Task_Primitives.Operations;
kono
parents:
diff changeset
65 with System.Parameters;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 package body System.Tasking.Protected_Objects.Single_Entry is
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 package STPO renames System.Task_Primitives.Operations;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 use Parameters;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -----------------------
kono
parents:
diff changeset
74 -- Local Subprograms --
kono
parents:
diff changeset
75 -----------------------
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 procedure Send_Program_Error (Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
78 pragma Inline (Send_Program_Error);
kono
parents:
diff changeset
79 -- Raise Program_Error in the caller of the specified entry call
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 --------------------------
kono
parents:
diff changeset
82 -- Entry Calls Handling --
kono
parents:
diff changeset
83 --------------------------
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Wakeup_Entry_Caller (Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
86 pragma Inline (Wakeup_Entry_Caller);
kono
parents:
diff changeset
87 -- This is called at the end of service of an entry call, to abort the
kono
parents:
diff changeset
88 -- caller if he is in an abortable part, and to wake up the caller if he
kono
parents:
diff changeset
89 -- is on Entry_Caller_Sleep. Call it holding the lock of Entry_Call.Self.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Wait_For_Completion (Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
92 pragma Inline (Wait_For_Completion);
kono
parents:
diff changeset
93 -- This procedure suspends the calling task until the specified entry call
kono
parents:
diff changeset
94 -- has either been completed or cancelled. On exit, the call will not be
kono
parents:
diff changeset
95 -- queued. This waits for calls on protected entries.
kono
parents:
diff changeset
96 -- Call this only when holding Self_ID locked.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Check_Exception
kono
parents:
diff changeset
99 (Self_ID : Task_Id;
kono
parents:
diff changeset
100 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
101 pragma Inline (Check_Exception);
kono
parents:
diff changeset
102 -- Raise any pending exception from the Entry_Call. This should be called
kono
parents:
diff changeset
103 -- at the end of every compiler interface procedure that implements an
kono
parents:
diff changeset
104 -- entry call. The caller should not be holding any locks, or there will
kono
parents:
diff changeset
105 -- be deadlock.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure PO_Do_Or_Queue
kono
parents:
diff changeset
108 (Object : Protection_Entry_Access;
kono
parents:
diff changeset
109 Entry_Call : Entry_Call_Link);
kono
parents:
diff changeset
110 -- This procedure executes or queues an entry call, depending on the status
kono
parents:
diff changeset
111 -- of the corresponding barrier. The specified object is assumed locked.
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 procedure Internal_Raise (X : Ada.Exceptions.Exception_Id);
kono
parents:
diff changeset
124 pragma Import (C, Internal_Raise, "__gnat_raise_with_msg");
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 use type Ada.Exceptions.Exception_Id;
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
kono
parents:
diff changeset
131 begin
kono
parents:
diff changeset
132 if E /= Ada.Exceptions.Null_Id then
kono
parents:
diff changeset
133 Internal_Raise (E);
kono
parents:
diff changeset
134 end if;
kono
parents:
diff changeset
135 end Check_Exception;
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 ------------------------
kono
parents:
diff changeset
138 -- Send_Program_Error --
kono
parents:
diff changeset
139 ------------------------
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 procedure Send_Program_Error (Entry_Call : Entry_Call_Link) is
kono
parents:
diff changeset
142 Caller : constant Task_Id := Entry_Call.Self;
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 begin
kono
parents:
diff changeset
145 Entry_Call.Exception_To_Raise := Program_Error'Identity;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 if Single_Lock then
kono
parents:
diff changeset
148 STPO.Lock_RTS;
kono
parents:
diff changeset
149 end if;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 STPO.Write_Lock (Caller);
kono
parents:
diff changeset
152 Wakeup_Entry_Caller (Entry_Call);
kono
parents:
diff changeset
153 STPO.Unlock (Caller);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 if Single_Lock then
kono
parents:
diff changeset
156 STPO.Unlock_RTS;
kono
parents:
diff changeset
157 end if;
kono
parents:
diff changeset
158 end Send_Program_Error;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 -------------------------
kono
parents:
diff changeset
161 -- Wait_For_Completion --
kono
parents:
diff changeset
162 -------------------------
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 procedure Wait_For_Completion (Entry_Call : Entry_Call_Link) is
kono
parents:
diff changeset
165 Self_Id : constant Task_Id := Entry_Call.Self;
kono
parents:
diff changeset
166 begin
kono
parents:
diff changeset
167 Self_Id.Common.State := Entry_Caller_Sleep;
kono
parents:
diff changeset
168 STPO.Sleep (Self_Id, Entry_Caller_Sleep);
kono
parents:
diff changeset
169 Self_Id.Common.State := Runnable;
kono
parents:
diff changeset
170 end Wait_For_Completion;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 -------------------------
kono
parents:
diff changeset
173 -- Wakeup_Entry_Caller --
kono
parents:
diff changeset
174 -------------------------
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 -- This is called at the end of service of an entry call, to abort the
kono
parents:
diff changeset
177 -- caller if he is in an abortable part, and to wake up the caller if it
kono
parents:
diff changeset
178 -- is on Entry_Caller_Sleep. It assumes that the call is already off-queue.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 -- (This enforces the rule that a task must be off-queue if its state is
kono
parents:
diff changeset
181 -- Done or Cancelled.) Call it holding the lock of Entry_Call.Self.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 -- The caller is waiting on Entry_Caller_Sleep, in Wait_For_Completion.
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 procedure Wakeup_Entry_Caller
kono
parents:
diff changeset
186 (Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
187 is
kono
parents:
diff changeset
188 Caller : constant Task_Id := Entry_Call.Self;
kono
parents:
diff changeset
189 begin
kono
parents:
diff changeset
190 pragma Assert
kono
parents:
diff changeset
191 (Caller.Common.State /= Terminated and then
kono
parents:
diff changeset
192 Caller.Common.State /= Unactivated);
kono
parents:
diff changeset
193 Entry_Call.State := Done;
kono
parents:
diff changeset
194 STPO.Wakeup (Caller, Entry_Caller_Sleep);
kono
parents:
diff changeset
195 end Wakeup_Entry_Caller;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 -----------------------
kono
parents:
diff changeset
198 -- Restricted GNARLI --
kono
parents:
diff changeset
199 -----------------------
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 --------------------------------------------
kono
parents:
diff changeset
202 -- Exceptional_Complete_Single_Entry_Body --
kono
parents:
diff changeset
203 --------------------------------------------
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Exceptional_Complete_Single_Entry_Body
kono
parents:
diff changeset
206 (Object : Protection_Entry_Access;
kono
parents:
diff changeset
207 Ex : Ada.Exceptions.Exception_Id)
kono
parents:
diff changeset
208 is
kono
parents:
diff changeset
209 begin
kono
parents:
diff changeset
210 Object.Call_In_Progress.Exception_To_Raise := Ex;
kono
parents:
diff changeset
211 end Exceptional_Complete_Single_Entry_Body;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 ---------------------------------
kono
parents:
diff changeset
214 -- Initialize_Protection_Entry --
kono
parents:
diff changeset
215 ---------------------------------
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Initialize_Protection_Entry
kono
parents:
diff changeset
218 (Object : Protection_Entry_Access;
kono
parents:
diff changeset
219 Ceiling_Priority : Integer;
kono
parents:
diff changeset
220 Compiler_Info : System.Address;
kono
parents:
diff changeset
221 Entry_Body : Entry_Body_Access)
kono
parents:
diff changeset
222 is
kono
parents:
diff changeset
223 begin
kono
parents:
diff changeset
224 Initialize_Protection (Object.Common'Access, Ceiling_Priority);
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 Object.Compiler_Info := Compiler_Info;
kono
parents:
diff changeset
227 Object.Call_In_Progress := null;
kono
parents:
diff changeset
228 Object.Entry_Body := Entry_Body;
kono
parents:
diff changeset
229 Object.Entry_Queue := null;
kono
parents:
diff changeset
230 end Initialize_Protection_Entry;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 ----------------
kono
parents:
diff changeset
233 -- Lock_Entry --
kono
parents:
diff changeset
234 ----------------
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 -- Compiler interface only
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Do not call this procedure from within the run-time system.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 procedure Lock_Entry (Object : Protection_Entry_Access) is
kono
parents:
diff changeset
241 begin
kono
parents:
diff changeset
242 Lock (Object.Common'Access);
kono
parents:
diff changeset
243 end Lock_Entry;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 --------------------------
kono
parents:
diff changeset
246 -- Lock_Read_Only_Entry --
kono
parents:
diff changeset
247 --------------------------
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 -- Compiler interface only
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 -- Do not call this procedure from within the runtime system
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 procedure Lock_Read_Only_Entry (Object : Protection_Entry_Access) is
kono
parents:
diff changeset
254 begin
kono
parents:
diff changeset
255 Lock_Read_Only (Object.Common'Access);
kono
parents:
diff changeset
256 end Lock_Read_Only_Entry;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 --------------------
kono
parents:
diff changeset
259 -- PO_Do_Or_Queue --
kono
parents:
diff changeset
260 --------------------
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 procedure PO_Do_Or_Queue
kono
parents:
diff changeset
263 (Object : Protection_Entry_Access;
kono
parents:
diff changeset
264 Entry_Call : Entry_Call_Link)
kono
parents:
diff changeset
265 is
kono
parents:
diff changeset
266 Barrier_Value : Boolean;
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 begin
kono
parents:
diff changeset
269 -- When the Action procedure for an entry body returns, it must be
kono
parents:
diff changeset
270 -- completed (having called [Exceptional_]Complete_Entry_Body).
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 Barrier_Value := Object.Entry_Body.Barrier (Object.Compiler_Info, 1);
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 if Barrier_Value then
kono
parents:
diff changeset
275 if Object.Call_In_Progress /= null then
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 -- This violates the No_Entry_Queue restriction, send
kono
parents:
diff changeset
278 -- Program_Error to the caller.
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 Send_Program_Error (Entry_Call);
kono
parents:
diff changeset
281 return;
kono
parents:
diff changeset
282 end if;
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 Object.Call_In_Progress := Entry_Call;
kono
parents:
diff changeset
285 Object.Entry_Body.Action
kono
parents:
diff changeset
286 (Object.Compiler_Info, Entry_Call.Uninterpreted_Data, 1);
kono
parents:
diff changeset
287 Object.Call_In_Progress := null;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 if Single_Lock then
kono
parents:
diff changeset
290 STPO.Lock_RTS;
kono
parents:
diff changeset
291 end if;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 STPO.Write_Lock (Entry_Call.Self);
kono
parents:
diff changeset
294 Wakeup_Entry_Caller (Entry_Call);
kono
parents:
diff changeset
295 STPO.Unlock (Entry_Call.Self);
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 if Single_Lock then
kono
parents:
diff changeset
298 STPO.Unlock_RTS;
kono
parents:
diff changeset
299 end if;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 else
kono
parents:
diff changeset
302 pragma Assert (Entry_Call.Mode = Simple_Call);
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 if Object.Entry_Queue /= null then
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 -- This violates the No_Entry_Queue restriction, send
kono
parents:
diff changeset
307 -- Program_Error to the caller.
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 Send_Program_Error (Entry_Call);
kono
parents:
diff changeset
310 return;
kono
parents:
diff changeset
311 else
kono
parents:
diff changeset
312 Object.Entry_Queue := Entry_Call;
kono
parents:
diff changeset
313 end if;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 end if;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 exception
kono
parents:
diff changeset
318 when others =>
kono
parents:
diff changeset
319 Send_Program_Error (Entry_Call);
kono
parents:
diff changeset
320 end PO_Do_Or_Queue;
kono
parents:
diff changeset
321
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 ---------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
323 -- Protected_Count_Entry --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
324 ---------------------------
111
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 function Protected_Count_Entry (Object : Protection_Entry) return Natural is
kono
parents:
diff changeset
327 begin
kono
parents:
diff changeset
328 if Object.Entry_Queue /= null then
kono
parents:
diff changeset
329 return 1;
kono
parents:
diff changeset
330 else
kono
parents:
diff changeset
331 return 0;
kono
parents:
diff changeset
332 end if;
kono
parents:
diff changeset
333 end Protected_Count_Entry;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 ---------------------------------
kono
parents:
diff changeset
336 -- Protected_Single_Entry_Call --
kono
parents:
diff changeset
337 ---------------------------------
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 procedure Protected_Single_Entry_Call
kono
parents:
diff changeset
340 (Object : Protection_Entry_Access;
kono
parents:
diff changeset
341 Uninterpreted_Data : System.Address)
kono
parents:
diff changeset
342 is
kono
parents:
diff changeset
343 Self_Id : constant Task_Id := STPO.Self;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
344 Entry_Call : Entry_Call_Record renames
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
345 Self_Id.Entry_Calls (Self_Id.Entry_Calls'First);
111
kono
parents:
diff changeset
346 begin
kono
parents:
diff changeset
347 -- If pragma Detect_Blocking is active then Program_Error must be
kono
parents:
diff changeset
348 -- raised if this potentially blocking operation is called from a
kono
parents:
diff changeset
349 -- protected action.
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 if Detect_Blocking
kono
parents:
diff changeset
352 and then Self_Id.Common.Protected_Action_Nesting > 0
kono
parents:
diff changeset
353 then
kono
parents:
diff changeset
354 raise Program_Error with "potentially blocking operation";
kono
parents:
diff changeset
355 end if;
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 Lock_Entry (Object);
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 Entry_Call.Mode := Simple_Call;
kono
parents:
diff changeset
360 Entry_Call.State := Now_Abortable;
kono
parents:
diff changeset
361 Entry_Call.Uninterpreted_Data := Uninterpreted_Data;
kono
parents:
diff changeset
362 Entry_Call.Exception_To_Raise := Ada.Exceptions.Null_Id;
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 PO_Do_Or_Queue (Object, Entry_Call'Access);
kono
parents:
diff changeset
365 Unlock_Entry (Object);
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 -- The call is either `Done' or not. It cannot be cancelled since there
kono
parents:
diff changeset
368 -- is no ATC construct.
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 pragma Assert (Entry_Call.State /= Cancelled);
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 if Entry_Call.State /= Done then
kono
parents:
diff changeset
373 if Single_Lock then
kono
parents:
diff changeset
374 STPO.Lock_RTS;
kono
parents:
diff changeset
375 end if;
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 STPO.Write_Lock (Self_Id);
kono
parents:
diff changeset
378 Wait_For_Completion (Entry_Call'Access);
kono
parents:
diff changeset
379 STPO.Unlock (Self_Id);
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 if Single_Lock then
kono
parents:
diff changeset
382 STPO.Unlock_RTS;
kono
parents:
diff changeset
383 end if;
kono
parents:
diff changeset
384 end if;
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 Check_Exception (Self_Id, Entry_Call'Access);
kono
parents:
diff changeset
387 end Protected_Single_Entry_Call;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 -----------------------------------
kono
parents:
diff changeset
390 -- Protected_Single_Entry_Caller --
kono
parents:
diff changeset
391 -----------------------------------
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 function Protected_Single_Entry_Caller
kono
parents:
diff changeset
394 (Object : Protection_Entry) return Task_Id
kono
parents:
diff changeset
395 is
kono
parents:
diff changeset
396 begin
kono
parents:
diff changeset
397 return Object.Call_In_Progress.Self;
kono
parents:
diff changeset
398 end Protected_Single_Entry_Caller;
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 -------------------
kono
parents:
diff changeset
401 -- Service_Entry --
kono
parents:
diff changeset
402 -------------------
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 procedure Service_Entry (Object : Protection_Entry_Access) is
kono
parents:
diff changeset
405 Entry_Call : constant Entry_Call_Link := Object.Entry_Queue;
kono
parents:
diff changeset
406 Caller : Task_Id;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 begin
kono
parents:
diff changeset
409 if Entry_Call /= null
kono
parents:
diff changeset
410 and then Object.Entry_Body.Barrier (Object.Compiler_Info, 1)
kono
parents:
diff changeset
411 then
kono
parents:
diff changeset
412 Object.Entry_Queue := null;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 if Object.Call_In_Progress /= null then
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 -- Violation of No_Entry_Queue restriction, raise exception
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 Send_Program_Error (Entry_Call);
kono
parents:
diff changeset
419 Unlock_Entry (Object);
kono
parents:
diff changeset
420 return;
kono
parents:
diff changeset
421 end if;
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 Object.Call_In_Progress := Entry_Call;
kono
parents:
diff changeset
424 Object.Entry_Body.Action
kono
parents:
diff changeset
425 (Object.Compiler_Info, Entry_Call.Uninterpreted_Data, 1);
kono
parents:
diff changeset
426 Object.Call_In_Progress := null;
kono
parents:
diff changeset
427 Caller := Entry_Call.Self;
kono
parents:
diff changeset
428 Unlock_Entry (Object);
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 if Single_Lock then
kono
parents:
diff changeset
431 STPO.Lock_RTS;
kono
parents:
diff changeset
432 end if;
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 STPO.Write_Lock (Caller);
kono
parents:
diff changeset
435 Wakeup_Entry_Caller (Entry_Call);
kono
parents:
diff changeset
436 STPO.Unlock (Caller);
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 if Single_Lock then
kono
parents:
diff changeset
439 STPO.Unlock_RTS;
kono
parents:
diff changeset
440 end if;
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 else
kono
parents:
diff changeset
443 -- Just unlock the entry
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 Unlock_Entry (Object);
kono
parents:
diff changeset
446 end if;
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 exception
kono
parents:
diff changeset
449 when others =>
kono
parents:
diff changeset
450 Send_Program_Error (Entry_Call);
kono
parents:
diff changeset
451 Unlock_Entry (Object);
kono
parents:
diff changeset
452 end Service_Entry;
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 ------------------
kono
parents:
diff changeset
455 -- Unlock_Entry --
kono
parents:
diff changeset
456 ------------------
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 procedure Unlock_Entry (Object : Protection_Entry_Access) is
kono
parents:
diff changeset
459 begin
kono
parents:
diff changeset
460 Unlock (Object.Common'Access);
kono
parents:
diff changeset
461 end Unlock_Entry;
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 end System.Tasking.Protected_Objects.Single_Entry;