2009-10-01 Tobias Burnus <burnus@net-b.de>
[official-gcc/alias-decl.git] / gcc / ada / s-tposen.ads
blob8c07cfd3ac9f38d0d0939dc70b3892ac691b18a6
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- SYSTEM.TASKING.PROTECTED_OBJECTS.SINGLE_ENTRY --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2009, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This package provides an optimized version of Protected_Objects.Operations
33 -- and Protected_Objects.Entries making the following assumptions:
35 -- PO have only one entry
36 -- There is only one caller at a time (No_Entry_Queue)
37 -- There is no dynamic priority support (No_Dynamic_Priorities)
38 -- No Abort Statements
39 -- (No_Abort_Statements, Max_Asynchronous_Select_Nesting => 0)
40 -- PO are at library level
41 -- None of the tasks will terminate (no need for finalization)
43 -- This interface is intended to be used in the ravenscar profile, the
44 -- compiler is responsible for ensuring that the conditions mentioned above
45 -- are respected, except for the No_Entry_Queue restriction that is checked
46 -- dynamically in this package, since the check cannot be performed at compile
47 -- time, and is relatively cheap (see body).
49 -- This package is part of the high level tasking interface used by the
50 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
51 -- (aka GNARLI, GNU Ada Run-time Library Interface)
53 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
54 -- Any changes to this interface may require corresponding compiler changes
55 -- in exp_ch9.adb and possibly exp_ch7.adb
57 package System.Tasking.Protected_Objects.Single_Entry is
58 pragma Elaborate_Body;
60 ---------------------------------
61 -- Compiler Interface (GNARLI) --
62 ---------------------------------
64 -- The compiler will expand in the GNAT tree the following construct:
66 -- protected PO is
67 -- entry E;
68 -- procedure P;
69 -- private
70 -- Open : Boolean := False;
71 -- end PO;
73 -- protected body PO is
74 -- entry E when Open is
75 -- ...variable declarations...
76 -- begin
77 -- ...B...
78 -- end E;
80 -- procedure P is
81 -- ...variable declarations...
82 -- begin
83 -- ...C...
84 -- end P;
85 -- end PO;
87 -- as follows:
89 -- protected type poT is
90 -- entry e;
91 -- procedure p;
92 -- private
93 -- open : boolean := false;
94 -- end poT;
95 -- type poTV is limited record
96 -- open : boolean := false;
97 -- _object : aliased protection_entry;
98 -- end record;
99 -- procedure poPT__E1s (O : address; P : address; E :
100 -- protected_entry_index);
101 -- function poPT__B2s (O : address; E : protected_entry_index) return
102 -- boolean;
103 -- procedure poPT__pN (_object : in out poTV);
104 -- procedure poPT__pP (_object : in out poTV);
105 -- poTA : aliased entry_body := (
106 -- barrier => poPT__B2s'unrestricted_access,
107 -- action => poPT__E1s'unrestricted_access);
108 -- freeze poTV [
109 -- procedure poTVIP (_init : in out poTV) is
110 -- begin
111 -- _init.open := false;
112 -- object-init-proc (_init._object);
113 -- initialize_protection_entry (_init._object'unchecked_access,
114 -- unspecified_priority, _init'address, poTA'
115 -- unrestricted_access);
116 -- return;
117 -- end poTVIP;
118 -- ]
119 -- po : poT;
120 -- poTVIP (poTV!(po));
122 -- function poPT__B2s (O : address; E : protected_entry_index) return
123 -- boolean is
124 -- type poTVP is access poTV;
125 -- _object : poTVP := poTVP!(O);
126 -- poR : protection_entry renames _object._object;
127 -- openP : boolean renames _object.open;
128 -- begin
129 -- return open;
130 -- end poPT__B2s;
132 -- procedure poPT__E1s (O : address; P : address; E :
133 -- protected_entry_index) is
134 -- type poTVP is access poTV;
135 -- _object : poTVP := poTVP!(O);
136 -- begin
137 -- B1b : declare
138 -- poR : protection_entry renames _object._object;
139 -- openP : boolean renames _object.open;
140 -- ...variable declarations...
141 -- begin
142 -- ...B...
143 -- end B1b;
144 -- complete_single_entry_body (_object._object'unchecked_access);
145 -- return;
146 -- exception
147 -- when all others =>
148 -- exceptional_complete_single_entry_body (_object._object'
149 -- unchecked_access, get_gnat_exception);
150 -- return;
151 -- end poPT__E1s;
153 -- procedure poPT__pN (_object : in out poTV) is
154 -- poR : protection_entry renames _object._object;
155 -- openP : boolean renames _object.open;
156 -- ...variable declarations...
157 -- begin
158 -- ...C...
159 -- return;
160 -- end poPT__pN;
162 -- procedure poPT__pP (_object : in out poTV) is
163 -- procedure _clean is
164 -- begin
165 -- service_entry (_object._object'unchecked_access);
166 -- unlock_entry (_object._object'unchecked_access);
167 -- return;
168 -- end _clean;
169 -- begin
170 -- lock_entry (_object._object'unchecked_access);
171 -- B5b : begin
172 -- poPT__pN (_object);
173 -- at end
174 -- _clean;
175 -- end B5b;
176 -- return;
177 -- end poPT__pP;
179 type Protection_Entry is limited private;
180 -- This type contains the GNARL state of a protected object. The
181 -- application-defined portion of the state (i.e. private objects)
182 -- is maintained by the compiler-generated code.
184 type Protection_Entry_Access is access all Protection_Entry;
186 procedure Initialize_Protection_Entry
187 (Object : Protection_Entry_Access;
188 Ceiling_Priority : Integer;
189 Compiler_Info : System.Address;
190 Entry_Body : Entry_Body_Access);
191 -- Initialize the Object parameter so that it can be used by the run time
192 -- to keep track of the runtime state of a protected object.
194 procedure Lock_Entry (Object : Protection_Entry_Access);
195 -- Lock a protected object for write access. Upon return, the caller
196 -- owns the lock to this object, and no other call to Lock or
197 -- Lock_Read_Only with the same argument will return until the
198 -- corresponding call to Unlock has been made by the caller.
200 procedure Lock_Read_Only_Entry
201 (Object : Protection_Entry_Access);
202 -- Lock a protected object for read access. Upon return, the caller
203 -- owns the lock for read access, and no other calls to Lock
204 -- with the same argument will return until the corresponding call
205 -- to Unlock has been made by the caller. Other calls to Lock_Read_Only
206 -- may (but need not) return before the call to Unlock, and the
207 -- corresponding callers will also own the lock for read access.
209 procedure Unlock_Entry (Object : Protection_Entry_Access);
210 -- Relinquish ownership of the lock for the object represented by
211 -- the Object parameter. If this ownership was for write access, or
212 -- if it was for read access where there are no other read access
213 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
214 -- of the tasks waiting on this lock (if any) will be given the
215 -- lock and allowed to return from the Lock or Lock_Read_Only call.
217 procedure Service_Entry (Object : Protection_Entry_Access);
218 -- Service the entry queue of the specified object, executing the
219 -- corresponding body of any queued entry call that is waiting on True
220 -- barrier. This is used when the state of a protected object may have
221 -- changed, in particular after the execution of the statement sequence of
222 -- a protected procedure.
224 -- This must be called with abort deferred and with the corresponding
225 -- object locked. Object is unlocked on return.
227 procedure Protected_Single_Entry_Call
228 (Object : Protection_Entry_Access;
229 Uninterpreted_Data : System.Address;
230 Mode : Call_Modes);
231 -- Make a protected entry call to the specified object.
232 -- Pend a protected entry call on the protected object represented
233 -- by Object. A pended call is not queued; it may be executed immediately
234 -- or queued, depending on the state of the entry barrier.
236 -- Uninterpreted_Data
237 -- This will be returned by Next_Entry_Call when this call is serviced.
238 -- It can be used by the compiler to pass information between the
239 -- caller and the server, in particular entry parameters.
241 -- Mode
242 -- The kind of call to be pended
244 procedure Timed_Protected_Single_Entry_Call
245 (Object : Protection_Entry_Access;
246 Uninterpreted_Data : System.Address;
247 Timeout : Duration;
248 Mode : Delay_Modes;
249 Entry_Call_Successful : out Boolean);
250 -- Same as the Protected_Entry_Call but with time-out specified.
251 -- This routine is used to implement timed entry calls.
253 procedure Complete_Single_Entry_Body
254 (Object : Protection_Entry_Access);
255 pragma Inline (Complete_Single_Entry_Body);
256 -- Called from within an entry body procedure, indicates that the
257 -- corresponding entry call has been serviced.
259 procedure Exceptional_Complete_Single_Entry_Body
260 (Object : Protection_Entry_Access;
261 Ex : Ada.Exceptions.Exception_Id);
262 -- Perform all of the functions of Complete_Entry_Body. In addition,
263 -- report in Ex the exception whose propagation terminated the entry
264 -- body to the runtime system.
266 function Protected_Count_Entry (Object : Protection_Entry)
267 return Natural;
268 -- Return the number of entry calls on Object (0 or 1)
270 function Protected_Single_Entry_Caller (Object : Protection_Entry)
271 return Task_Id;
272 -- Return value of E'Caller, where E is the protected entry currently
273 -- being handled. This will only work if called from within an
274 -- entry body, as required by the LRM (C.7.1(14)).
276 private
277 type Protection_Entry is record
278 Common : aliased Protection;
279 -- State of the protected object. This part is common to any protected
280 -- object, including those without entries.
282 Compiler_Info : System.Address;
283 -- Pointer to compiler-generated record representing protected object
285 Call_In_Progress : Entry_Call_Link;
286 -- Pointer to the entry call being executed (if any)
288 Entry_Body : Entry_Body_Access;
289 -- Pointer to executable code for the entry body of the protected type
291 Entry_Queue : Entry_Call_Link;
292 -- Place to store the waiting entry call (if any)
293 end record;
295 end System.Tasking.Protected_Objects.Single_Entry;