2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / s-taprob.ads
blob3ff9082588de46da8dc666a315ac6486563d552c
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-2005, 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 ------------------------------------------------------------------------------
34 -- This package provides necessary definitions to handle simple (i.e without
35 -- entries) protected objects.
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.
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)
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
50 package System.Tasking.Protected_Objects is
51 pragma Elaborate_Body;
53 ---------------------------------
54 -- Compiler Interface (GNARLI) --
55 ---------------------------------
57 -- The compiler will expand in the GNAT tree the following construct:
59 -- protected PO is
60 -- procedure P;
61 -- private
62 -- open : boolean := false;
63 -- end PO;
65 -- protected body PO is
66 -- procedure P is
67 -- ...variable declarations...
68 -- begin
69 -- ...B...
70 -- end P;
71 -- end PO;
73 -- as follows:
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));
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;
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;
124 Null_Protected_Entry : constant := Null_Entry;
126 Max_Protected_Entry : constant := Max_Entry;
128 type Protected_Entry_Index is new Entry_Index
129 range Null_Protected_Entry .. Max_Protected_Entry;
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.
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.
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.
159 type Entry_Body_Access is access all Entry_Body;
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.
171 type Protection_Access is access all Protection;
173 Null_PO : constant Protection_Access := null;
175 procedure Initialize_Protection
176 (Object : Protection_Access;
177 Ceiling_Priority : Integer);
178 -- Initialize the Object parameter so that it can be used by the runtime
179 -- to keep track of the runtime state of a protected object.
181 procedure Lock (Object : Protection_Access);
182 -- Lock a protected object for write access. Upon return, the caller
183 -- owns the lock to this object, and no other call to Lock or
184 -- Lock_Read_Only with the same argument will return until the
185 -- corresponding call to Unlock has been made by the caller.
187 procedure Lock_Read_Only (Object : Protection_Access);
188 -- Lock a protected object for read access. Upon return, the caller
189 -- owns the lock for read access, and no other calls to Lock with the
190 -- same argument will return until the corresponding call to Unlock
191 -- has been made by the caller. Other calls to Lock_Read_Only may (but
192 -- need not) return before the call to Unlock, and the corresponding
193 -- callers will also own the lock for read access.
195 -- Note: we are not currently using this interface, it is provided
196 -- for possible future use. At the current time, everyone uses Lock
197 -- for both read and write locks.
199 procedure Unlock (Object : Protection_Access);
200 -- Relinquish ownership of the lock for the object represented by
201 -- the Object parameter. If this ownership was for write access, or
202 -- if it was for read access where there are no other read access
203 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
204 -- of the tasks waiting on this lock (if any) will be given the
205 -- lock and allowed to return from the Lock or Lock_Read_Only call.
207 private
208 type Protection is record
209 L : aliased Task_Primitives.Lock;
210 -- Lock used to ensure mutual exclusive access to the protected object
212 Ceiling : System.Any_Priority;
213 -- Ceiling priority associated to the protected object
215 Owner : Task_Id;
216 -- This field contains the protected object's owner. Null_Task
217 -- indicates that the protected object is not currently being used.
218 -- This information is used for detecting the type of potentially
219 -- blocking operations described in the ARM 9.5.1, par. 15 (external
220 -- calls on a protected subprogram with the same target object as that
221 -- of the protected action).
222 end record;
224 procedure Finalize_Protection (Object : in out Protection);
225 -- Clean up a Protection object (in particular, finalize the associated
226 -- Lock object). The compiler generates calls automatically to this
227 -- procedure
229 end System.Tasking.Protected_Objects;