OSDN Git Service

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