* rtl.h (struct rtx_def): Update comments.
[official-gcc.git] / gcc / ada / s-taprob.ads
blob6c7472a69ff4ebf2fa7e123c9b8a17e46f5d52b8
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA 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 -- --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
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. --
29 -- --
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). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This package provides necessary definitions to handle simple (i.e without
37 -- entries) protected objects.
39 -- All the routines that handle protected objects with entries have been moved
40 -- to two children: Entries and Operations. Note that Entries only contains
41 -- the type declaration and the OO primitives. This is needed to avoid
42 -- circular dependency.
44 -- This package is part of the high level tasking interface used by the
45 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
46 -- (aka GNARLI, GNU Ada Run-time Library Interface)
48 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
49 -- Any changes to this interface may require corresponding compiler changes
50 -- in exp_ch9.adb and possibly exp_ch7.adb
52 package System.Tasking.Protected_Objects is
53 pragma Elaborate_Body;
55 ---------------------------------
56 -- Compiler Interface (GNARLI) --
57 ---------------------------------
59 -- The compiler will expand in the GNAT tree the following construct:
61 -- protected PO is
62 -- procedure P;
63 -- private
64 -- open : boolean := false;
65 -- end PO;
67 -- protected body PO is
68 -- procedure P is
69 -- ...variable declarations...
70 -- begin
71 -- ...B...
72 -- end P;
73 -- end PO;
75 -- as follows:
77 -- protected type poT is
78 -- procedure p;
79 -- private
80 -- open : boolean := false;
81 -- end poT;
82 -- type poTV is limited record
83 -- open : boolean := false;
84 -- _object : aliased protection;
85 -- end record;
86 -- procedure poPT__pN (_object : in out poTV);
87 -- procedure poPT__pP (_object : in out poTV);
88 -- freeze poTV [
89 -- procedure _init_proc (_init : in out poTV) is
90 -- begin
91 -- _init.open := false;
92 -- _init_proc (_init._object);
93 -- initialize_protection (_init._object'unchecked_access,
94 -- unspecified_priority);
95 -- return;
96 -- end _init_proc;
97 -- ]
98 -- po : poT;
99 -- _init_proc (poTV!(po));
101 -- procedure poPT__pN (_object : in out poTV) is
102 -- poR : protection renames _object._object;
103 -- openP : boolean renames _object.open;
104 -- ...variable declarations...
105 -- begin
106 -- ...B...
107 -- return;
108 -- end poPT__pN;
110 -- procedure poPT__pP (_object : in out poTV) is
111 -- procedure _clean is
112 -- begin
113 -- unlock (_object._object'unchecked_access);
114 -- return;
115 -- end _clean;
116 -- begin
117 -- lock (_object._object'unchecked_access);
118 -- B2b : begin
119 -- poPT__pN (_object);
120 -- at end
121 -- _clean;
122 -- end B2b;
123 -- return;
124 -- end poPT__pP;
126 Null_Protected_Entry : constant := Null_Entry;
128 Max_Protected_Entry : constant := Max_Entry;
130 type Protected_Entry_Index is new Entry_Index
131 range Null_Protected_Entry .. Max_Protected_Entry;
133 type Barrier_Function_Pointer is access
134 function
135 (O : System.Address;
136 E : Protected_Entry_Index)
137 return Boolean;
138 -- Pointer to a function which evaluates the barrier of a protected
139 -- entry body. O is a pointer to the compiler-generated record
140 -- representing the protected object, and E is the index of the
141 -- entry serviced by the body.
143 type Entry_Action_Pointer is access
144 procedure
145 (O : System.Address;
146 P : System.Address;
147 E : Protected_Entry_Index);
148 -- Pointer to a procedure which executes the sequence of statements
149 -- of a protected entry body. O is a pointer to the compiler-generated
150 -- record representing the protected object, P is a pointer to the
151 -- record of entry parameters, and E is the index of the
152 -- entry serviced by the body.
154 type Entry_Body is record
155 Barrier : Barrier_Function_Pointer;
156 Action : Entry_Action_Pointer;
157 end record;
158 -- The compiler-generated code passes objects of this type to the GNARL
159 -- to allow it to access the executable code of an entry body.
161 type Entry_Body_Access is access all Entry_Body;
163 type Protection is limited private;
164 -- This type contains the GNARL state of a protected object. The
165 -- application-defined portion of the state (i.e. private objects)
166 -- is maintained by the compiler-generated code.
167 -- Note that there are now 2 Protection types. One for the simple
168 -- case (no entries) and one for the general case that needs the whole
169 -- Finalization mechanism.
170 -- This split helps in the case of restricted run time where we want to
171 -- minimize the size of the code.
173 type Protection_Access is access all Protection;
175 Null_PO : constant Protection_Access := null;
177 procedure Initialize_Protection
178 (Object : Protection_Access;
179 Ceiling_Priority : Integer);
180 -- Initialize the Object parameter so that it can be used by the runtime
181 -- to keep track of the runtime state of a protected object.
183 procedure Lock (Object : Protection_Access);
184 -- Lock a protected object for write access. Upon return, the caller
185 -- owns the lock to this object, and no other call to Lock or
186 -- Lock_Read_Only with the same argument will return until the
187 -- corresponding call to Unlock has been made by the caller.
189 procedure Lock_Read_Only (Object : Protection_Access);
190 -- Lock a protected object for read access. Upon return, the caller
191 -- owns the lock for read access, and no other calls to Lock with the
192 -- same argument will return until the corresponding call to Unlock
193 -- has been made by the caller. Other calls to Lock_Read_Only may (but
194 -- need not) return before the call to Unlock, and the corresponding
195 -- callers will also own the lock for read access.
197 -- Note: we are not currently using this interface, it is provided
198 -- for possible future use. At the current time, everyone uses Lock
199 -- for both read and write locks.
201 procedure Unlock (Object : Protection_Access);
202 -- Relinquish ownership of the lock for the object represented by
203 -- the Object parameter. If this ownership was for write access, or
204 -- if it was for read access where there are no other read access
205 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
206 -- of the tasks waiting on this lock (if any) will be given the
207 -- lock and allowed to return from the Lock or Lock_Read_Only call.
209 private
210 type Protection is record
211 L : aliased Task_Primitives.Lock;
212 Ceiling : System.Any_Priority;
213 end record;
214 pragma Volatile (Protection);
215 for Protection'Alignment use Standard'Maximum_Alignment;
216 -- Needed so that we can uncheck convert a Protection_Access to a
217 -- Protection_Entries_Access.
219 procedure Finalize_Protection (Object : in out Protection);
220 -- Clean up a Protection object; in particular, finalize the associated
221 -- Lock object. The compiler generates automatically calls to this
222 -- procedure
224 end System.Tasking.Protected_Objects;