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