1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- SYSTEM.TASKING.PROTECTED_OBJECTS.SINGLE_ENTRY --
10 -- Copyright (C) 1991-2001 Florida State University --
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. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This package provides an optimized version of Protected_Objects.Operations
37 -- and Protected_Objects.Entries making the following assumptions:
39 -- PO have only one entry
40 -- There is only one caller at a time (No_Entry_Queue)
41 -- There is no dynamic priority support (No_Dynamic_Priorities)
42 -- No Abort Statements
43 -- (No_Abort_Statements, Max_Asynchronous_Select_Nesting => 0)
44 -- PO are at library level
45 -- None of the tasks will terminate (no need for finalization)
47 -- This interface is intended to be used in the ravenscar profile, the
48 -- compiler is responsible for ensuring that the conditions mentioned above
49 -- are respected, except for the No_Entry_Queue restriction that is checked
50 -- dynamically in this package, since the check cannot be performed at compile
51 -- time, and is relatively cheap (see body).
53 -- This package is part of the high level tasking interface used by the
54 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
55 -- (aka GNARLI, GNU Ada Run-time Library Interface)
57 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
58 -- Any changes to this interface may require corresponding compiler changes
59 -- in exp_ch9.adb and possibly exp_ch7.adb
61 package System
.Tasking
.Protected_Objects
.Single_Entry
is
62 pragma Elaborate_Body
;
64 ---------------------------------
65 -- Compiler Interface (GNARLI) --
66 ---------------------------------
68 -- The compiler will expand in the GNAT tree the following construct:
74 -- Open : Boolean := False;
77 -- protected body PO is
78 -- entry E when Open is
79 -- ...variable declarations...
85 -- ...variable declarations...
93 -- protected type poT is
97 -- open : boolean := false;
99 -- type poTV is limited record
100 -- open : boolean := false;
101 -- _object : aliased protection_entry;
103 -- procedure poPT__E1s (O : address; P : address; E :
104 -- protected_entry_index);
105 -- function poPT__B2s (O : address; E : protected_entry_index) return
107 -- procedure poPT__pN (_object : in out poTV);
108 -- procedure poPT__pP (_object : in out poTV);
109 -- poTA : aliased entry_body := (
110 -- barrier => poPT__B2s'unrestricted_access,
111 -- action => poPT__E1s'unrestricted_access);
113 -- procedure _init_proc (_init : in out poTV) is
115 -- _init.open := false;
116 -- _init_proc (_init._object);
117 -- initialize_protection_entry (_init._object'unchecked_access,
118 -- unspecified_priority, _init'address, poTA'
119 -- unrestricted_access);
124 -- _init_proc (poTV!(po));
126 -- function poPT__B2s (O : address; E : protected_entry_index) return
128 -- type poTVP is access poTV;
129 -- _object : poTVP := poTVP!(O);
130 -- poR : protection_entry renames _object._object;
131 -- openP : boolean renames _object.open;
136 -- procedure poPT__E1s (O : address; P : address; E :
137 -- protected_entry_index) is
138 -- type poTVP is access poTV;
139 -- _object : poTVP := poTVP!(O);
142 -- poR : protection_entry renames _object._object;
143 -- openP : boolean renames _object.open;
144 -- ...variable declarations...
148 -- complete_single_entry_body (_object._object'unchecked_access);
151 -- when all others =>
152 -- exceptional_complete_single_entry_body (_object._object'
153 -- unchecked_access, get_gnat_exception);
157 -- procedure poPT__pN (_object : in out poTV) is
158 -- poR : protection_entry renames _object._object;
159 -- openP : boolean renames _object.open;
160 -- ...variable declarations...
166 -- procedure poPT__pP (_object : in out poTV) is
167 -- procedure _clean is
169 -- service_entry (_object._object'unchecked_access);
170 -- unlock_entry (_object._object'unchecked_access);
174 -- lock_entry (_object._object'unchecked_access);
176 -- poPT__pN (_object);
183 type Protection_Entry
is limited private;
184 -- This type contains the GNARL state of a protected object. The
185 -- application-defined portion of the state (i.e. private objects)
186 -- is maintained by the compiler-generated code.
188 type Protection_Entry_Access
is access all Protection_Entry
;
190 procedure Initialize_Protection_Entry
191 (Object
: Protection_Entry_Access
;
192 Ceiling_Priority
: Integer;
193 Compiler_Info
: System
.Address
;
194 Entry_Body
: Entry_Body_Access
);
195 -- Initialize the Object parameter so that it can be used by the run time
196 -- to keep track of the runtime state of a protected object.
198 procedure Lock_Entry
(Object
: Protection_Entry_Access
);
199 -- Lock a protected object for write access. Upon return, the caller
200 -- owns the lock to this object, and no other call to Lock or
201 -- Lock_Read_Only with the same argument will return until the
202 -- corresponding call to Unlock has been made by the caller.
204 procedure Lock_Read_Only_Entry
205 (Object
: Protection_Entry_Access
);
206 -- Lock a protected object for read access. Upon return, the caller
207 -- owns the lock for read access, and no other calls to Lock
208 -- with the same argument will return until the corresponding call
209 -- to Unlock has been made by the caller. Other cals to Lock_Read_Only
210 -- may (but need not) return before the call to Unlock, and the
211 -- corresponding callers will also own the lock for read access.
213 procedure Unlock_Entry
(Object
: Protection_Entry_Access
);
214 -- Relinquish ownership of the lock for the object represented by
215 -- the Object parameter. If this ownership was for write access, or
216 -- if it was for read access where there are no other read access
217 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
218 -- of the tasks waiting on this lock (if any) will be given the
219 -- lock and allowed to return from the Lock or Lock_Read_Only call.
221 procedure Service_Entry
(Object
: Protection_Entry_Access
);
222 -- Service the entry queue of the specified object, executing the
223 -- corresponding body of any queued entry call that is waiting on True
224 -- barrier. This is used when the state of a protected object may have
225 -- changed, in particular after the execution of the statement sequence of
226 -- a protected procedure.
227 -- This must be called with abortion deferred and with the corresponding
230 procedure Protected_Single_Entry_Call
231 (Object
: Protection_Entry_Access
;
232 Uninterpreted_Data
: System
.Address
;
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.
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
;
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
)
271 -- Return the number of entry calls on Object (0 or 1).
273 function Protected_Single_Entry_Caller
(Object
: Protection_Entry
)
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)).
280 type Protection_Entry
is record
281 L
: aliased Task_Primitives
.Lock
;
282 Compiler_Info
: System
.Address
;
283 Call_In_Progress
: Entry_Call_Link
;
284 Ceiling
: System
.Any_Priority
;
285 Entry_Body
: Entry_Body_Access
;
286 Entry_Queue
: Entry_Call_Link
;
288 pragma Volatile
(Protection_Entry
);
289 for Protection_Entry
'Alignment use Standard
'Maximum_Alignment;
290 -- Use maximum alignement so that one can convert a protection_entry_access
293 end System
.Tasking
.Protected_Objects
.Single_Entry
;