Update concepts branch to revision 131834
[official-gcc.git] / gcc / ada / s-tasren.ads
blob73f74ba75fe8d32710f065b313c29329bb6e6243
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . T A S K I N G . R E N D E Z V O U S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
10 -- --
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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
35 -- Any changes to this interface may require corresponding compiler changes.
37 with Ada.Exceptions;
39 with System.Tasking.Protected_Objects.Entries;
41 package System.Tasking.Rendezvous is
43 package STPE renames System.Tasking.Protected_Objects.Entries;
45 procedure Task_Entry_Call
46 (Acceptor : Task_Id;
47 E : Task_Entry_Index;
48 Uninterpreted_Data : System.Address;
49 Mode : Call_Modes;
50 Rendezvous_Successful : out Boolean);
51 -- General entry call used to implement ATC or conditional entry calls.
52 -- Compiler interface only. Do not call from within the RTS.
53 -- Acceptor is the ID of the acceptor task.
54 -- E is the entry index requested.
55 -- Uninterpreted_Data represents the parameters of the entry. It is
56 -- constructed by the compiler for the caller and the callee; therefore,
57 -- the run time never needs to decode this data.
58 -- Mode can be either Asynchronous_Call (ATC) or Conditional_Call.
59 -- Rendezvous_Successful is set to True on return if the call was serviced.
61 procedure Timed_Task_Entry_Call
62 (Acceptor : Task_Id;
63 E : Task_Entry_Index;
64 Uninterpreted_Data : System.Address;
65 Timeout : Duration;
66 Mode : Delay_Modes;
67 Rendezvous_Successful : out Boolean);
68 -- Timed entry call without using ATC.
69 -- Compiler interface only. Do not call from within the RTS.
70 -- See Task_Entry_Call for details on Acceptor, E and Uninterpreted_Data.
71 -- Timeout is the value of the time out.
72 -- Mode determines whether the delay is relative or absolute.
74 procedure Call_Simple
75 (Acceptor : Task_Id;
76 E : Task_Entry_Index;
77 Uninterpreted_Data : System.Address);
78 -- Simple entry call.
79 -- Compiler interface only. Do not call from within the RTS.
81 -- source:
82 -- T.E1 (Params);
84 -- expansion:
85 -- declare
86 -- P : parms := (parm1, parm2, parm3);
87 -- X : Task_Entry_Index := 1;
88 -- begin
89 -- Call_Simple (t._task_id, X, P'Address);
90 -- parm1 := P.param1;
91 -- parm2 := P.param2;
92 -- ...
93 -- end;
95 procedure Cancel_Task_Entry_Call (Cancelled : out Boolean);
96 -- Cancel pending asynchronous task entry call.
97 -- Compiler interface only. Do not call from within the RTS.
98 -- See Exp_Ch9.Expand_N_Asynchronous_Select for code expansion.
100 procedure Requeue_Task_Entry
101 (Acceptor : Task_Id;
102 E : Task_Entry_Index;
103 With_Abort : Boolean);
104 -- Requeue from a task entry to a task entry.
105 -- Compiler interface only. Do not call from within the RTS.
106 -- The code generation for task entry requeues is different from that for
107 -- protected entry requeues. There is a "goto" that skips around the call
108 -- to Complete_Rendezvous, so that Requeue_Task_Entry must also do the work
109 -- of Complete_Rendezvous. The difference is that it does not report that
110 -- the call's State = Done.
112 -- source:
113 -- accept e1 do
114 -- ...A...
115 -- requeue e2;
116 -- ...B...
117 -- end e1;
119 -- expansion:
120 -- A62b : address;
121 -- L61b : label
122 -- begin
123 -- accept_call (1, A62b);
124 -- ...A...
125 -- requeue_task_entry (tTV!(t)._task_id, 2, false);
126 -- goto L61b;
127 -- ...B...
128 -- complete_rendezvous;
129 -- <<L61b>>
130 -- exception
131 -- when others =>
132 -- exceptional_complete_rendezvous (current_exception);
133 -- end;
135 procedure Requeue_Protected_To_Task_Entry
136 (Object : STPE.Protection_Entries_Access;
137 Acceptor : Task_Id;
138 E : Task_Entry_Index;
139 With_Abort : Boolean);
140 -- Requeue from a protected entry to a task entry.
141 -- Compiler interface only. Do not call from within the RTS.
143 -- source:
144 -- entry e2 when b is
145 -- begin
146 -- b := false;
147 -- ...A...
148 -- requeue t.e2;
149 -- end e2;
151 -- expansion:
152 -- procedure rPT__E14b (O : address; P : address; E :
153 -- protected_entry_index) is
154 -- type rTVP is access rTV;
155 -- freeze rTVP []
156 -- _object : rTVP := rTVP!(O);
157 -- begin
158 -- declare
159 -- rR : protection renames _object._object;
160 -- vP : integer renames _object.v;
161 -- bP : boolean renames _object.b;
162 -- begin
163 -- b := false;
164 -- ...A...
165 -- requeue_protected_to_task_entry (rR'unchecked_access, tTV!(t).
166 -- _task_id, 2, false);
167 -- return;
168 -- end;
169 -- complete_entry_body (_object._object'unchecked_access, objectF =>
170 -- 0);
171 -- return;
172 -- exception
173 -- when others =>
174 -- abort_undefer.all;
175 -- exceptional_complete_entry_body (_object._object'
176 -- unchecked_access, current_exception, objectF => 0);
177 -- return;
178 -- end rPT__E14b;
180 procedure Selective_Wait
181 (Open_Accepts : Accept_List_Access;
182 Select_Mode : Select_Modes;
183 Uninterpreted_Data : out System.Address;
184 Index : out Select_Index);
185 -- Implement select statement.
186 -- Compiler interface only. Do not call from within the RTS.
187 -- See comments on Accept_Call.
189 -- source:
190 -- select accept e1 do
191 -- ...A...
192 -- end e1;
193 -- ...B...
194 -- or accept e2;
195 -- ...C...
196 -- end select;
198 -- expansion:
199 -- A32b : address;
200 -- declare
201 -- A37b : T36b;
202 -- A37b (1) := (null_body => false, s => 1);
203 -- A37b (2) := (null_body => true, s => 2);
204 -- S0 : aliased T36b := accept_list'A37b;
205 -- J1 : select_index := 0;
206 -- procedure e1A is
207 -- begin
208 -- abort_undefer.all;
209 -- ...A...
210 -- <<L31b>>
211 -- complete_rendezvous;
212 -- exception
213 -- when all others =>
214 -- exceptional_complete_rendezvous (get_gnat_exception);
215 -- end e1A;
216 -- begin
217 -- selective_wait (S0'unchecked_access, simple_mode, A32b, J1);
218 -- case J1 is
219 -- when 0 =>
220 -- goto L3;
221 -- when 1 =>
222 -- e1A;
223 -- goto L1;
224 -- when 2 =>
225 -- goto L2;
226 -- when others =>
227 -- goto L3;
228 -- end case;
229 -- <<L1>>
230 -- ...B...
231 -- goto L3;
232 -- <<L2>>
233 -- ...C...
234 -- goto L3;
235 -- <<L3>>
236 -- end;
238 procedure Timed_Selective_Wait
239 (Open_Accepts : Accept_List_Access;
240 Select_Mode : Select_Modes;
241 Uninterpreted_Data : out System.Address;
242 Timeout : Duration;
243 Mode : Delay_Modes;
244 Index : out Select_Index);
245 -- Selective wait with timeout without using ATC.
246 -- Compiler interface only. Do not call from within the RTS.
248 procedure Accept_Call
249 (E : Task_Entry_Index;
250 Uninterpreted_Data : out System.Address);
251 -- Accept an entry call.
252 -- Compiler interface only. Do not call from within the RTS.
254 -- source:
255 -- accept E do ...A... end E;
256 -- expansion:
257 -- A27b : address;
258 -- L26b : label
259 -- begin
260 -- accept_call (1, A27b);
261 -- ...A...
262 -- complete_rendezvous;
263 -- <<L26b>>
264 -- exception
265 -- when all others =>
266 -- exceptional_complete_rendezvous (get_gnat_exception);
267 -- end;
269 -- The handler for Abort_Signal (*all* others) is to handle the case when
270 -- the acceptor is aborted between Accept_Call and the corresponding
271 -- Complete_Rendezvous call. We need to wake up the caller in this case.
273 -- See also Selective_Wait
275 procedure Accept_Trivial (E : Task_Entry_Index);
276 -- Accept an entry call that has no parameters and no body.
277 -- Compiler interface only. Do not call from within the RTS.
278 -- This should only be called when there is no accept body, or the accept
279 -- body is empty.
281 -- source:
282 -- accept E;
283 -- expansion:
284 -- accept_trivial (1);
286 -- The compiler is also able to recognize the following and
287 -- translate it the same way.
289 -- accept E do null; end E;
291 function Task_Count (E : Task_Entry_Index) return Natural;
292 -- Return number of tasks waiting on the entry E (of current task)
293 -- Compiler interface only. Do not call from within the RTS.
295 function Callable (T : Task_Id) return Boolean;
296 -- Return T'Callable
297 -- Compiler interface. Do not call from within the RTS, except for body of
298 -- Ada.Task_Identification.
300 type Task_Entry_Nesting_Depth is new Task_Entry_Index
301 range 0 .. Max_Task_Entry;
303 function Task_Entry_Caller (D : Task_Entry_Nesting_Depth) return Task_Id;
304 -- Return E'Caller. This will only work if called from within an
305 -- accept statement that is handling E, as required by the LRM (C.7.1(14)).
306 -- Compiler interface only. Do not call from within the RTS.
308 procedure Complete_Rendezvous;
309 -- Called by acceptor to wake up caller
311 procedure Exceptional_Complete_Rendezvous
312 (Ex : Ada.Exceptions.Exception_Id);
313 -- Called by acceptor to mark the end of the current rendezvous and
314 -- propagate an exception to the caller.
316 -- For internal use only:
318 function Task_Do_Or_Queue
319 (Self_ID : Task_Id;
320 Entry_Call : Entry_Call_Link) return Boolean;
321 -- Call this only with abort deferred and holding no locks, except
322 -- the global RTS lock when Single_Lock is True which must be owned.
323 -- Returns False iff the call cannot be served or queued, as is the
324 -- case if the caller is not callable; i.e., a False return value
325 -- indicates that Tasking_Error should be raised.
326 -- Either initiate the entry call, such that the accepting task is
327 -- free to execute the rendezvous, queue the call on the acceptor's
328 -- queue, or cancel the call. Conditional calls that cannot be
329 -- accepted immediately are cancelled.
331 end System.Tasking.Rendezvous;