File : s-tposen-raven.ads
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) 1998-2013, AdaCore --
10 -- --
11 -- GNAT 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 -- --
19 -- --
20 -- --
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 ------------------------------------------------------------------------------
31
32 -- This package provides an optimized version of Protected_Objects.Operations
33 -- and Protected_Objects.Entries making the following assumptions:
34
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)
42 -- No timed or conditional entry calls
43 -- No exception handlers allowed
44
45 -- This interface is intended to be used in the Ravenscar profile, the
46 -- compiler is responsible for ensuring that the conditions mentioned above
47 -- are respected, except for the No_Entry_Queue restriction that is checked
48 -- dynamically in this package, since the check cannot be performed at compile
49 -- time, and is relatively cheap (see body).
50
51 -- This package is part of the high level tasking interface used by the
52 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
53 -- (aka GNARLI, GNU Ada Run-time Library Interface)
54
55 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
56 -- Any changes to this interface may require corresponding compiler changes
57 -- in exp_ch9.adb and possibly exp_ch7.adb
58
59 package System.Tasking.Protected_Objects.Single_Entry is
60 pragma Elaborate_Body;
61
62 ---------------------------------
63 -- Compiler Interface (GNARLI) --
64 ---------------------------------
65
66 -- The compiler will expand in the GNAT tree the following construct:
67
68 -- protected PO is
69 -- entry E;
70 -- procedure P;
71 -- private
72 -- Open : Boolean := False;
73 -- end PO;
74
75 -- protected body PO is
76 -- entry E when Open is
77 -- ...variable declarations...
78 -- begin
79 -- ...B...
80 -- end E;
81
82 -- procedure P is
83 -- ...variable declarations...
84 -- begin
85 -- ...C...
86 -- end P;
87 -- end PO;
88
89 -- as follows:
90
91 -- protected type poT is
92 -- entry e;
93 -- procedure p;
94 -- private
95 -- open : boolean := false;
96 -- end poT;
97 -- type poTV is limited record
98 -- open : boolean := false;
99 -- _object : aliased protection_entry;
100 -- end record;
101 -- procedure poPT__E1s (O : address; P : address; E :
102 -- protected_entry_index);
103 -- function poPT__B2s (O : address; E : protected_entry_index) return
104 -- boolean;
105 -- procedure poPT__pN (_object : in out poTV);
106 -- procedure poPT__pP (_object : in out poTV);
107 -- poTA : aliased entry_body := (
108 -- barrier => poPT__B2s'unrestricted_access,
109 -- action => poPT__E1s'unrestricted_access);
110 -- freeze poTV [
111 -- procedure poTVIP (_init : in out poTV) is
112 -- begin
113 -- _init.open := false;
114 -- object-init-proc (_init._object);
115 -- initialize_protection_entry (_init._object'unchecked_access,
116 -- unspecified_priority, _init'address, poTA'
117 -- unrestricted_access);
118 -- return;
119 -- end poTVIP;
120 -- ]
121 -- po : poT;
122 -- poTVIP (poTV!(po));
123
124 -- function poPT__B2s (O : address; E : protected_entry_index) return
125 -- boolean is
126 -- type poTVP is access poTV;
127 -- _object : poTVP := poTVP!(O);
128 -- poR : protection_entry renames _object._object;
129 -- openP : boolean renames _object.open;
130 -- begin
131 -- return open;
132 -- end poPT__B2s;
133
134 -- procedure poPT__E1s (O : address; P : address; E :
135 -- protected_entry_index) is
136 -- type poTVP is access poTV;
137 -- _object : poTVP := poTVP!(O);
138 -- begin
139 -- B1b : declare
140 -- poR : protection_entry renames _object._object;
141 -- openP : boolean renames _object.open;
142 -- ...variable declarations...
143 -- begin
144 -- ...B...
145 -- end B1b;
146 -- return;
147 -- end poPT__E1s;
148
149 -- procedure poPT__pN (_object : in out poTV) is
150 -- poR : protection_entry renames _object._object;
151 -- openP : boolean renames _object.open;
152 -- ...variable declarations...
153 -- begin
154 -- ...C...
155 -- return;
156 -- end poPT__pN;
157
158 -- procedure poPT__pP (_object : in out poTV) is
159 -- procedure _clean is
160 -- begin
161 -- service_entry (_object._object'unchecked_access);
162 -- return;
163 -- end _clean;
164 -- begin
165 -- lock_entry (_object._object'unchecked_access);
166 -- B5b : begin
167 -- poPT__pN (_object);
168 -- at end
169 -- _clean;
170 -- end B5b;
171 -- return;
172 -- end poPT__pP;
173
174 type Protection_Entry is limited private;
175 -- This type contains the GNARL state of a protected object. The
176 -- application-defined portion of the state (i.e. private objects)
177 -- is maintained by the compiler-generated code.
178
179 type Protection_Entry_Access is access all Protection_Entry;
180
181 procedure Initialize_Protection_Entry
182 (Object : Protection_Entry_Access;
183 Ceiling_Priority : Integer;
184 Compiler_Info : System.Address;
185 Entry_Body : Entry_Body_Access);
186 -- Initialize the Object parameter so that it can be used by the run time
187 -- to keep track of the runtime state of a protected object.
188
189 procedure Lock_Entry (Object : Protection_Entry_Access);
190 -- Lock a protected object for write access. Upon return, the caller
191 -- owns the lock to this object, and no other call to Lock with the same
192 -- argument will return until the corresponding call to Unlock has been
193 -- made by the caller.
194
195 procedure Unlock_Entry (Object : Protection_Entry_Access);
196 -- Relinquish ownership of the lock for the object represented by
197 -- the Object parameter. One of the tasks waiting on this lock (if any)
198 -- will be given the lock and allowed to return from the Lock call.
199
200 procedure Service_Entry (Object : Protection_Entry_Access);
201 -- Service the entry queue of the specified object, executing the
202 -- corresponding body of any queued entry call that is waiting on True
203 -- barrier. This is used when the state of a protected object may have
204 -- changed, in particular after the execution of the statement sequence
205 -- of a protected procedure. This procedure must be called with abort
206 -- deferred and with the corresponding object locked. Object is unlocked
207 -- on return.
208
209 procedure Protected_Single_Entry_Call
210 (Object : Protection_Entry_Access;
211 Uninterpreted_Data : System.Address);
212 -- Make a protected entry call to the specified object. Pends a protected
213 -- entry call on the protected object represented by Object. A pended call
214 -- is not queued; it may be executed immediately or queued, depending on
215 -- the state of the entry barrier.
216 --
217 -- Uninterpreted_Data
218 -- This will be returned by Next_Entry_Call when this call is serviced.
219 -- It can be used by the compiler to pass information between the
220 -- caller and the server, in particular entry parameters.
221
222 function Protected_Count_Entry (Object : Protection_Entry) return Natural;
223 -- Return the number of entry calls on Object (0 or 1)
224
225 function Protected_Single_Entry_Caller
226 (Object : Protection_Entry) return Task_Id;
227 -- Return value of E'Caller, where E is the protected entry currently being
228 -- handled. This will only work if called from within an entry body, as
229 -- required by the LRM (C.7.1(14)).
230
231 private
232 type Protection_Entry is record
233 Common : aliased Protection;
234 -- State of the protected object. This part is common to any protected
235 -- object, including those without entries.
236
237 Compiler_Info : System.Address;
238 -- Pointer to compiler-generated record representing protected object
239
240 Call_In_Progress : Entry_Call_Link;
241 -- Pointer to the entry call being executed (if any)
242
243 Entry_Body : Entry_Body_Access;
244 -- Pointer to the executable code for entry body of the protected type
245
246 Entry_Queue : Entry_Call_Link;
247 -- Place to store the waiting entry call (if any)
248 end record;
249 pragma Suppress_Initialization (Protection_Entry);
250
251 end System.Tasking.Protected_Objects.Single_Entry;