Daily bump.
[official-gcc.git] / gcc / ada / s-tposen.ads
blob074ee71e4104da4e51b9a31f4914aa8abcffe85c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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 -- Copyright (C) 1992-2005 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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 -- This package provides an optimized version of Protected_Objects.Operations
36 -- and Protected_Objects.Entries making the following assumptions:
38 -- PO have only one entry
39 -- There is only one caller at a time (No_Entry_Queue)
40 -- There is no dynamic priority support (No_Dynamic_Priorities)
41 -- No Abort Statements
42 -- (No_Abort_Statements, Max_Asynchronous_Select_Nesting => 0)
43 -- PO are at library level
44 -- None of the tasks will terminate (no need for finalization)
46 -- This interface is intended to be used in the ravenscar profile, the
47 -- compiler is responsible for ensuring that the conditions mentioned above
48 -- are respected, except for the No_Entry_Queue restriction that is checked
49 -- dynamically in this package, since the check cannot be performed at compile
50 -- time, and is relatively cheap (see body).
52 -- This package is part of the high level tasking interface used by the
53 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
54 -- (aka GNARLI, GNU Ada Run-time Library Interface)
56 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
57 -- Any changes to this interface may require corresponding compiler changes
58 -- in exp_ch9.adb and possibly exp_ch7.adb
60 package System.Tasking.Protected_Objects.Single_Entry is
61 pragma Elaborate_Body;
63 ---------------------------------
64 -- Compiler Interface (GNARLI) --
65 ---------------------------------
67 -- The compiler will expand in the GNAT tree the following construct:
69 -- protected PO is
70 -- entry E;
71 -- procedure P;
72 -- private
73 -- Open : Boolean := False;
74 -- end PO;
76 -- protected body PO is
77 -- entry E when Open is
78 -- ...variable declarations...
79 -- begin
80 -- ...B...
81 -- end E;
83 -- procedure P is
84 -- ...variable declarations...
85 -- begin
86 -- ...C...
87 -- end P;
88 -- end PO;
90 -- as follows:
92 -- protected type poT is
93 -- entry e;
94 -- procedure p;
95 -- private
96 -- open : boolean := false;
97 -- end poT;
98 -- type poTV is limited record
99 -- open : boolean := false;
100 -- _object : aliased protection_entry;
101 -- end record;
102 -- procedure poPT__E1s (O : address; P : address; E :
103 -- protected_entry_index);
104 -- function poPT__B2s (O : address; E : protected_entry_index) return
105 -- boolean;
106 -- procedure poPT__pN (_object : in out poTV);
107 -- procedure poPT__pP (_object : in out poTV);
108 -- poTA : aliased entry_body := (
109 -- barrier => poPT__B2s'unrestricted_access,
110 -- action => poPT__E1s'unrestricted_access);
111 -- freeze poTV [
112 -- procedure poTVIP (_init : in out poTV) is
113 -- begin
114 -- _init.open := false;
115 -- object-init-proc (_init._object);
116 -- initialize_protection_entry (_init._object'unchecked_access,
117 -- unspecified_priority, _init'address, poTA'
118 -- unrestricted_access);
119 -- return;
120 -- end poTVIP;
121 -- ]
122 -- po : poT;
123 -- poTVIP (poTV!(po));
125 -- function poPT__B2s (O : address; E : protected_entry_index) return
126 -- boolean is
127 -- type poTVP is access poTV;
128 -- _object : poTVP := poTVP!(O);
129 -- poR : protection_entry renames _object._object;
130 -- openP : boolean renames _object.open;
131 -- begin
132 -- return open;
133 -- end poPT__B2s;
135 -- procedure poPT__E1s (O : address; P : address; E :
136 -- protected_entry_index) is
137 -- type poTVP is access poTV;
138 -- _object : poTVP := poTVP!(O);
139 -- begin
140 -- B1b : declare
141 -- poR : protection_entry renames _object._object;
142 -- openP : boolean renames _object.open;
143 -- ...variable declarations...
144 -- begin
145 -- ...B...
146 -- end B1b;
147 -- complete_single_entry_body (_object._object'unchecked_access);
148 -- return;
149 -- exception
150 -- when all others =>
151 -- exceptional_complete_single_entry_body (_object._object'
152 -- unchecked_access, get_gnat_exception);
153 -- return;
154 -- end poPT__E1s;
156 -- procedure poPT__pN (_object : in out poTV) is
157 -- poR : protection_entry renames _object._object;
158 -- openP : boolean renames _object.open;
159 -- ...variable declarations...
160 -- begin
161 -- ...C...
162 -- return;
163 -- end poPT__pN;
165 -- procedure poPT__pP (_object : in out poTV) is
166 -- procedure _clean is
167 -- begin
168 -- service_entry (_object._object'unchecked_access);
169 -- unlock_entry (_object._object'unchecked_access);
170 -- return;
171 -- end _clean;
172 -- begin
173 -- lock_entry (_object._object'unchecked_access);
174 -- B5b : begin
175 -- poPT__pN (_object);
176 -- at end
177 -- _clean;
178 -- end B5b;
179 -- return;
180 -- end poPT__pP;
182 type Protection_Entry is limited private;
183 -- This type contains the GNARL state of a protected object. The
184 -- application-defined portion of the state (i.e. private objects)
185 -- is maintained by the compiler-generated code.
187 type Protection_Entry_Access is access all Protection_Entry;
189 procedure Initialize_Protection_Entry
190 (Object : Protection_Entry_Access;
191 Ceiling_Priority : Integer;
192 Compiler_Info : System.Address;
193 Entry_Body : Entry_Body_Access);
194 -- Initialize the Object parameter so that it can be used by the run time
195 -- to keep track of the runtime state of a protected object.
197 procedure Lock_Entry (Object : Protection_Entry_Access);
198 -- Lock a protected object for write access. Upon return, the caller
199 -- owns the lock to this object, and no other call to Lock or
200 -- Lock_Read_Only with the same argument will return until the
201 -- corresponding call to Unlock has been made by the caller.
203 procedure Lock_Read_Only_Entry
204 (Object : Protection_Entry_Access);
205 -- Lock a protected object for read access. Upon return, the caller
206 -- owns the lock for read access, and no other calls to Lock
207 -- with the same argument will return until the corresponding call
208 -- to Unlock has been made by the caller. Other cals to Lock_Read_Only
209 -- may (but need not) return before the call to Unlock, and the
210 -- corresponding callers will also own the lock for read access.
212 procedure Unlock_Entry (Object : Protection_Entry_Access);
213 -- Relinquish ownership of the lock for the object represented by
214 -- the Object parameter. If this ownership was for write access, or
215 -- if it was for read access where there are no other read access
216 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
217 -- of the tasks waiting on this lock (if any) will be given the
218 -- lock and allowed to return from the Lock or Lock_Read_Only call.
220 procedure Service_Entry (Object : Protection_Entry_Access);
221 -- Service the entry queue of the specified object, executing the
222 -- corresponding body of any queued entry call that is waiting on True
223 -- barrier. This is used when the state of a protected object may have
224 -- changed, in particular after the execution of the statement sequence of
225 -- a protected procedure.
227 -- This must be called with abort deferred and with the corresponding
228 -- object locked. Object is unlocked on return.
230 procedure Protected_Single_Entry_Call
231 (Object : Protection_Entry_Access;
232 Uninterpreted_Data : System.Address;
233 Mode : Call_Modes);
234 -- Make a protected entry call to the specified object.
235 -- Pend a protected entry call on the protected object represented
236 -- by Object. A pended call is not queued; it may be executed immediately
237 -- or queued, depending on the state of the entry barrier.
239 -- Uninterpreted_Data
240 -- This will be returned by Next_Entry_Call when this call is serviced.
241 -- It can be used by the compiler to pass information between the
242 -- caller and the server, in particular entry parameters.
244 -- Mode
245 -- The kind of call to be pended
247 procedure Timed_Protected_Single_Entry_Call
248 (Object : Protection_Entry_Access;
249 Uninterpreted_Data : System.Address;
250 Timeout : Duration;
251 Mode : Delay_Modes;
252 Entry_Call_Successful : out Boolean);
253 -- Same as the Protected_Entry_Call but with time-out specified.
254 -- This routine is used to implement timed entry calls.
256 procedure Complete_Single_Entry_Body
257 (Object : Protection_Entry_Access);
258 pragma Inline (Complete_Single_Entry_Body);
259 -- Called from within an entry body procedure, indicates that the
260 -- corresponding entry call has been serviced.
262 procedure Exceptional_Complete_Single_Entry_Body
263 (Object : Protection_Entry_Access;
264 Ex : Ada.Exceptions.Exception_Id);
265 -- Perform all of the functions of Complete_Entry_Body. In addition,
266 -- report in Ex the exception whose propagation terminated the entry
267 -- body to the runtime system.
269 function Protected_Count_Entry (Object : Protection_Entry)
270 return Natural;
271 -- Return the number of entry calls on Object (0 or 1).
273 function Protected_Single_Entry_Caller (Object : Protection_Entry)
274 return Task_Id;
275 -- Return value of E'Caller, where E is the protected entry currently
276 -- being handled. This will only work if called from within an
277 -- entry body, as required by the LRM (C.7.1(14)).
279 private
280 type Protection_Entry is record
281 L : aliased Task_Primitives.Lock;
282 -- The underlying lock associated with a Protection_Entries. Note that
283 -- you should never (un)lock Object.L directly, but instead use
284 -- Lock_Entry/Unlock_Entry.
286 Compiler_Info : System.Address;
287 -- Pointer to compiler-generated record representing protected object
289 Call_In_Progress : Entry_Call_Link;
290 -- Pointer to the entry call being executed (if any)
292 Ceiling : System.Any_Priority;
293 -- Ceiling priority associated to the protected object
295 Owner : Task_Id;
296 -- This field contains the protected object's owner. Null_Task
297 -- indicates that the protected object is not currently being used.
298 -- This information is used for detecting the type of potentially
299 -- blocking operations described in the ARM 9.5.1, par. 15 (external
300 -- calls on a protected subprogram with the same target object as that
301 -- of the protected action).
303 Entry_Body : Entry_Body_Access;
304 -- Pointer to executable code for the entry body of the protected type
306 Entry_Queue : Entry_Call_Link;
307 -- Place to store the waiting entry call (if any)
308 end record;
310 end System.Tasking.Protected_Objects.Single_Entry;