OSDN Git Service

* java-tree.h (push_labeled_block, pop_labeled_block): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-taprob.ads
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 --                                                                          --
7 --                                  S p e c                                 --
8 --                                                                          --
9 --          Copyright (C) 1992-2006, 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 2,  or (at your option) any later ver- --
14 -- sion. GNARL 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.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package provides necessary definitions to handle simple (i.e without
35 --  entries) protected objects.
36
37 --  All the routines that handle protected objects with entries have been moved
38 --  to two children: Entries and Operations. Note that Entries only contains
39 --  the type declaration and the OO primitives. This is needed to avoid
40 --  circular dependency.
41
42 --  This package is part of the high level tasking interface used by the
43 --  compiler to expand Ada 95 tasking constructs into simpler run time calls
44 --  (aka GNARLI, GNU Ada Run-time Library Interface)
45
46 --  Note: the compiler generates direct calls to this interface, via Rtsfind.
47 --  Any changes to this interface may require corresponding compiler changes
48 --  in exp_ch9.adb and possibly exp_ch7.adb and exp_attr.adb
49
50 package System.Tasking.Protected_Objects is
51    pragma Elaborate_Body;
52
53    ---------------------------------
54    -- Compiler Interface (GNARLI) --
55    ---------------------------------
56
57    --  The compiler will expand in the GNAT tree the following construct:
58
59    --  protected PO is
60    --     procedure P;
61    --  private
62    --     open : boolean := false;
63    --  end PO;
64
65    --  protected body PO is
66    --     procedure P is
67    --        ...variable declarations...
68    --     begin
69    --        ...B...
70    --     end P;
71    --  end PO;
72
73    --  as follows:
74
75    --  protected type poT is
76    --     procedure p;
77    --  private
78    --     open : boolean := false;
79    --  end poT;
80    --  type poTV is limited record
81    --     open : boolean := false;
82    --     _object : aliased protection;
83    --  end record;
84    --  procedure poPT__pN (_object : in out poTV);
85    --  procedure poPT__pP (_object : in out poTV);
86    --  freeze poTV [
87    --     procedure poTVI (_init : in out poTV) is
88    --     begin
89    --        _init.open := false;
90    --        object-init-proc (_init._object);
91    --        initialize_protection (_init._object'unchecked_access,
92    --          unspecified_priority);
93    --        return;
94    --     end _init_proc;
95    --  ]
96    --  po : poT;
97    --  poTVI (poTV!(po));
98
99    --  procedure poPT__pN (_object : in out poTV) is
100    --     poR : protection renames _object._object;
101    --     openP : boolean renames _object.open;
102    --     ...variable declarations...
103    --  begin
104    --     ...B...
105    --     return;
106    --  end poPT__pN;
107
108    --  procedure poPT__pP (_object : in out poTV) is
109    --     procedure _clean is
110    --     begin
111    --        unlock (_object._object'unchecked_access);
112    --        return;
113    --     end _clean;
114    --  begin
115    --     lock (_object._object'unchecked_access);
116    --     B2b : begin
117    --        poPT__pN (_object);
118    --     at end
119    --        _clean;
120    --     end B2b;
121    --     return;
122    --  end poPT__pP;
123
124    Null_Protected_Entry : constant := Null_Entry;
125
126    Max_Protected_Entry : constant := Max_Entry;
127
128    type Protected_Entry_Index is new Entry_Index
129      range Null_Protected_Entry .. Max_Protected_Entry;
130
131    type Barrier_Function_Pointer is access
132      function
133        (O    : System.Address;
134         E    : Protected_Entry_Index)
135         return Boolean;
136    --  Pointer to a function which evaluates the barrier of a protected
137    --  entry body. O is a pointer to the compiler-generated record
138    --  representing the protected object, and E is the index of the
139    --  entry serviced by the body.
140
141    type Entry_Action_Pointer is access
142      procedure
143        (O : System.Address;
144         P : System.Address;
145         E : Protected_Entry_Index);
146    --  Pointer to a procedure which executes the sequence of statements
147    --  of a protected entry body. O is a pointer to the compiler-generated
148    --  record representing the protected object, P is a pointer to the
149    --  record of entry parameters, and E is the index of the
150    --  entry serviced by the body.
151
152    type Entry_Body is record
153       Barrier : Barrier_Function_Pointer;
154       Action  : Entry_Action_Pointer;
155    end record;
156    --  The compiler-generated code passes objects of this type to the GNARL
157    --  to allow it to access the executable code of an entry body.
158
159    type Entry_Body_Access is access all Entry_Body;
160
161    type Protection is limited private;
162    --  This type contains the GNARL state of a protected object. The
163    --  application-defined portion of the state (i.e. private objects)
164    --  is maintained by the compiler-generated code.
165    --  Note that there are now 2 Protection types. One for the simple
166    --  case (no entries) and one for the general case that needs the whole
167    --  Finalization mechanism.
168    --  This split helps in the case of restricted run time where we want to
169    --  minimize the size of the code.
170
171    type Protection_Access is access all Protection;
172
173    Null_PO : constant Protection_Access := null;
174
175    function Get_Ceiling
176      (Object : Protection_Access) return System.Any_Priority;
177    --  Returns the new ceiling priority of the protected object
178
179    procedure Initialize_Protection
180      (Object           : Protection_Access;
181       Ceiling_Priority : Integer);
182    --  Initialize the Object parameter so that it can be used by the runtime
183    --  to keep track of the runtime state of a protected object.
184
185    procedure Lock (Object : Protection_Access);
186    --  Lock a protected object for write access. Upon return, the caller
187    --  owns the lock to this object, and no other call to Lock or
188    --  Lock_Read_Only with the same argument will return until the
189    --  corresponding call to Unlock has been made by the caller.
190
191    procedure Lock_Read_Only (Object : Protection_Access);
192    --  Lock a protected object for read access. Upon return, the caller
193    --  owns the lock for read access, and no other calls to Lock with the
194    --  same argument will return until the corresponding call to Unlock
195    --  has been made by the caller. Other calls to Lock_Read_Only may (but
196    --  need not) return before the call to Unlock, and the corresponding
197    --  callers will also own the lock for read access.
198    --
199    --  Note: we are not currently using this interface, it is provided
200    --  for possible future use. At the current time, everyone uses Lock
201    --  for both read and write locks.
202
203    procedure Set_Ceiling
204      (Object : Protection_Access;
205       Prio   : System.Any_Priority);
206    --  Sets the new ceiling priority of the protected object
207
208    procedure Unlock (Object : Protection_Access);
209    --  Relinquish ownership of the lock for the object represented by
210    --  the Object parameter. If this ownership was for write access, or
211    --  if it was for read access where there are no other read access
212    --  locks outstanding, one (or more, in the case of Lock_Read_Only)
213    --  of the tasks waiting on this lock (if any) will be given the
214    --  lock and allowed to return from the Lock or Lock_Read_Only call.
215
216 private
217    type Protection is record
218       L : aliased Task_Primitives.Lock;
219       --  Lock used to ensure mutual exclusive access to the protected object
220
221       Ceiling : System.Any_Priority;
222       --  Ceiling priority associated to the protected object
223
224       New_Ceiling : System.Any_Priority;
225       --  New ceiling priority associated to the protected object. In case
226       --  of assignment of a new ceiling priority to the protected object the
227       --  frontend generates a call to set_ceiling to save the new value in
228       --  this field. After such assignment this value can be read by means
229       --  of the 'Priority attribute, which generates a call to get_ceiling.
230       --  However, the ceiling of the protected object will not be changed
231       --  until completion of the protected action in which the assignment
232       --  has been executed (AARM D.5.2 (10/2)).
233
234       Owner : Task_Id;
235       --  This field contains the protected object's owner. Null_Task
236       --  indicates that the protected object is not currently being used.
237       --  This information is used for detecting the type of potentially
238       --  blocking operations described in the ARM 9.5.1, par. 15 (external
239       --  calls on a protected subprogram with the same target object as that
240       --  of the protected action).
241    end record;
242
243    procedure Finalize_Protection (Object : in out Protection);
244    --  Clean up a Protection object (in particular, finalize the associated
245    --  Lock object). The compiler generates calls automatically to this
246    --  procedure
247
248 end System.Tasking.Protected_Objects;