Daily bump.
[official-gcc.git] / gcc / ada / s-tposen.ads
blob9ae62378065e2e813ecfd24d21c7bc25c023bd5c
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 . P R O T E C T E D _ O B J E C T S . --
6 -- S I N G L E _ E N T R Y --
7 -- --
8 -- S p e c --
9 -- --
10 -- $Revision: 1.3 $
11 -- --
12 -- Copyright (C) 1991-1999 Florida State University --
13 -- --
14 -- GNARL is free software; you can redistribute it and/or modify it under --
15 -- terms of the GNU General Public License as published by the Free Soft- --
16 -- ware Foundation; either version 2, or (at your option) any later ver- --
17 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
20 -- for more details. You should have received a copy of the GNU General --
21 -- Public License distributed with GNARL; see file COPYING. If not, write --
22 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
23 -- MA 02111-1307, USA. --
24 -- --
25 -- As a special exception, if other files instantiate generics from this --
26 -- unit, or you link this unit with other files to produce an executable, --
27 -- this unit does not by itself cause the resulting executable to be --
28 -- covered by the GNU General Public License. This exception does not --
29 -- however invalidate any other reasons why the executable file might be --
30 -- covered by the GNU Public License. --
31 -- --
32 -- GNARL was developed by the GNARL team at Florida State University. It is --
33 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
34 -- State University (http://www.gnat.com). --
35 -- --
36 ------------------------------------------------------------------------------
38 -- This package provides an optimized version of Protected_Objects.Operations
39 -- and Protected_Objects.Entries making the following assumptions:
41 -- PO have only one entry
42 -- There is only one caller at a time (No_Entry_Queue)
43 -- There is no dynamic priority support (No_Dynamic_Priorities)
44 -- No Abort Statements
45 -- (No_Abort_Statements, Max_Asynchronous_Select_Nesting => 0)
46 -- PO are at library level
47 -- None of the tasks will terminate (no need for finalization)
49 -- This interface is intended to be used in the ravenscar profile, the
50 -- compiler is responsible for ensuring that the conditions mentioned above
51 -- are respected, except for the No_Entry_Queue restriction that is checked
52 -- dynamically in this package, since the check cannot be performed at compile
53 -- time, and is relatively cheap (see body).
55 -- This package is part of the high level tasking interface used by the
56 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
57 -- (aka GNARLI, GNU Ada Run-time Library Interface)
59 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
60 -- Any changes to this interface may require corresponding compiler changes
61 -- in exp_ch9.adb and possibly exp_ch7.adb
63 package System.Tasking.Protected_Objects.Single_Entry is
64 pragma Elaborate_Body;
66 ---------------------------------
67 -- Compiler Interface (GNARLI) --
68 ---------------------------------
70 -- The compiler will expand in the GNAT tree the following construct:
72 -- protected PO is
73 -- entry E;
74 -- procedure P;
75 -- private
76 -- Open : Boolean := False;
77 -- end PO;
79 -- protected body PO is
80 -- entry E when Open is
81 -- ...variable declarations...
82 -- begin
83 -- ...B...
84 -- end E;
86 -- procedure P is
87 -- ...variable declarations...
88 -- begin
89 -- ...C...
90 -- end P;
91 -- end PO;
93 -- as follows:
95 -- protected type poT is
96 -- entry e;
97 -- procedure p;
98 -- private
99 -- open : boolean := false;
100 -- end poT;
101 -- type poTV is limited record
102 -- open : boolean := false;
103 -- _object : aliased protection_entry;
104 -- end record;
105 -- procedure poPT__E1s (O : address; P : address; E :
106 -- protected_entry_index);
107 -- function poPT__B2s (O : address; E : protected_entry_index) return
108 -- boolean;
109 -- procedure poPT__pN (_object : in out poTV);
110 -- procedure poPT__pP (_object : in out poTV);
111 -- poTA : aliased entry_body := (
112 -- barrier => poPT__B2s'unrestricted_access,
113 -- action => poPT__E1s'unrestricted_access);
114 -- freeze poTV [
115 -- procedure _init_proc (_init : in out poTV) is
116 -- begin
117 -- _init.open := false;
118 -- _init_proc (_init._object);
119 -- initialize_protection_entry (_init._object'unchecked_access,
120 -- unspecified_priority, _init'address, poTA'
121 -- unrestricted_access);
122 -- return;
123 -- end _init_proc;
124 -- ]
125 -- po : poT;
126 -- _init_proc (poTV!(po));
128 -- function poPT__B2s (O : address; E : protected_entry_index) return
129 -- boolean is
130 -- type poTVP is access poTV;
131 -- _object : poTVP := poTVP!(O);
132 -- poR : protection_entry renames _object._object;
133 -- openP : boolean renames _object.open;
134 -- begin
135 -- return open;
136 -- end poPT__B2s;
138 -- procedure poPT__E1s (O : address; P : address; E :
139 -- protected_entry_index) is
140 -- type poTVP is access poTV;
141 -- _object : poTVP := poTVP!(O);
142 -- begin
143 -- B1b : declare
144 -- poR : protection_entry renames _object._object;
145 -- openP : boolean renames _object.open;
146 -- ...variable declarations...
147 -- begin
148 -- ...B...
149 -- end B1b;
150 -- complete_single_entry_body (_object._object'unchecked_access);
151 -- return;
152 -- exception
153 -- when all others =>
154 -- exceptional_complete_single_entry_body (_object._object'
155 -- unchecked_access, get_gnat_exception);
156 -- return;
157 -- end poPT__E1s;
159 -- procedure poPT__pN (_object : in out poTV) is
160 -- poR : protection_entry renames _object._object;
161 -- openP : boolean renames _object.open;
162 -- ...variable declarations...
163 -- begin
164 -- ...C...
165 -- return;
166 -- end poPT__pN;
168 -- procedure poPT__pP (_object : in out poTV) is
169 -- procedure _clean is
170 -- begin
171 -- service_entry (_object._object'unchecked_access);
172 -- unlock_entry (_object._object'unchecked_access);
173 -- return;
174 -- end _clean;
175 -- begin
176 -- lock_entry (_object._object'unchecked_access);
177 -- B5b : begin
178 -- poPT__pN (_object);
179 -- at end
180 -- _clean;
181 -- end B5b;
182 -- return;
183 -- end poPT__pP;
185 type Protection_Entry is limited private;
186 -- This type contains the GNARL state of a protected object. The
187 -- application-defined portion of the state (i.e. private objects)
188 -- is maintained by the compiler-generated code.
190 type Protection_Entry_Access is access all Protection_Entry;
192 procedure Initialize_Protection_Entry
193 (Object : Protection_Entry_Access;
194 Ceiling_Priority : Integer;
195 Compiler_Info : System.Address;
196 Entry_Body : Entry_Body_Access);
197 -- Initialize the Object parameter so that it can be used by the run time
198 -- to keep track of the runtime state of a protected object.
200 procedure Lock_Entry (Object : Protection_Entry_Access);
201 -- Lock a protected object for write access. Upon return, the caller
202 -- owns the lock to this object, and no other call to Lock or
203 -- Lock_Read_Only with the same argument will return until the
204 -- corresponding call to Unlock has been made by the caller.
206 procedure Lock_Read_Only_Entry
207 (Object : Protection_Entry_Access);
208 -- Lock a protected object for read access. Upon return, the caller
209 -- owns the lock for read access, and no other calls to Lock
210 -- with the same argument will return until the corresponding call
211 -- to Unlock has been made by the caller. Other cals to Lock_Read_Only
212 -- may (but need not) return before the call to Unlock, and the
213 -- corresponding callers will also own the lock for read access.
215 procedure Unlock_Entry (Object : Protection_Entry_Access);
216 -- Relinquish ownership of the lock for the object represented by
217 -- the Object parameter. If this ownership was for write access, or
218 -- if it was for read access where there are no other read access
219 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
220 -- of the tasks waiting on this lock (if any) will be given the
221 -- lock and allowed to return from the Lock or Lock_Read_Only call.
223 procedure Service_Entry (Object : Protection_Entry_Access);
224 -- Service the entry queue of the specified object, executing the
225 -- corresponding body of any queued entry call that is waiting on True
226 -- barrier. This is used when the state of a protected object may have
227 -- changed, in particular after the execution of the statement sequence of
228 -- a protected procedure.
229 -- This must be called with abortion deferred and with the corresponding
230 -- object locked.
232 procedure Protected_Single_Entry_Call
233 (Object : Protection_Entry_Access;
234 Uninterpreted_Data : System.Address;
235 Mode : Call_Modes);
236 -- Make a protected entry call to the specified object.
237 -- Pend a protected entry call on the protected object represented
238 -- by Object. A pended call is not queued; it may be executed immediately
239 -- or queued, depending on the state of the entry barrier.
241 -- Uninterpreted_Data
242 -- This will be returned by Next_Entry_Call when this call is serviced.
243 -- It can be used by the compiler to pass information between the
244 -- caller and the server, in particular entry parameters.
246 -- Mode
247 -- The kind of call to be pended
249 procedure Timed_Protected_Single_Entry_Call
250 (Object : Protection_Entry_Access;
251 Uninterpreted_Data : System.Address;
252 Timeout : Duration;
253 Mode : Delay_Modes;
254 Entry_Call_Successful : out Boolean);
255 -- Same as the Protected_Entry_Call but with time-out specified.
256 -- This routine is used to implement timed entry calls.
258 procedure Complete_Single_Entry_Body
259 (Object : Protection_Entry_Access);
260 pragma Inline (Complete_Single_Entry_Body);
261 -- Called from within an entry body procedure, indicates that the
262 -- corresponding entry call has been serviced.
264 procedure Exceptional_Complete_Single_Entry_Body
265 (Object : Protection_Entry_Access;
266 Ex : Ada.Exceptions.Exception_Id);
267 -- Perform all of the functions of Complete_Entry_Body. In addition,
268 -- report in Ex the exception whose propagation terminated the entry
269 -- body to the runtime system.
271 function Protected_Count_Entry (Object : Protection_Entry)
272 return Natural;
273 -- Return the number of entry calls on Object (0 or 1).
275 function Protected_Single_Entry_Caller (Object : Protection_Entry)
276 return Task_ID;
277 -- Return value of E'Caller, where E is the protected entry currently
278 -- being handled. This will only work if called from within an
279 -- entry body, as required by the LRM (C.7.1(14)).
281 private
282 type Protection_Entry is record
283 L : aliased Task_Primitives.Lock;
284 Compiler_Info : System.Address;
285 Call_In_Progress : Entry_Call_Link;
286 Ceiling : System.Any_Priority;
287 Entry_Body : Entry_Body_Access;
288 Entry_Queue : Entry_Call_Link;
289 end record;
290 pragma Volatile (Protection_Entry);
291 for Protection_Entry'Alignment use Standard'Maximum_Alignment;
292 -- Use maximum alignement so that one can convert a protection_entry_access
293 -- to a task_id.
295 end System.Tasking.Protected_Objects.Single_Entry;