1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
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 --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
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. --
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. --
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). --
35 ------------------------------------------------------------------------------
37 -- This package provides necessary definitions to handle simple (i.e without
38 -- entries) protected objects.
40 -- All the routines that handle protected objects with entries have been moved
41 -- to two children: Entries and Operations. Note that Entries only contains
42 -- the type declaration and the OO primitives. This is needed to avoid
43 -- circular dependency.
45 -- This package is part of the high level tasking interface used by the
46 -- compiler to expand Ada 95 tasking constructs into simpler run time calls
47 -- (aka GNARLI, GNU Ada Run-time Library Interface)
49 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
50 -- Any changes to this interface may require corresponding compiler changes
51 -- in exp_ch9.adb and possibly exp_ch7.adb
53 package System
.Tasking
.Protected_Objects
is
54 pragma Elaborate_Body
;
56 ---------------------------------
57 -- Compiler Interface (GNARLI) --
58 ---------------------------------
60 -- The compiler will expand in the GNAT tree the following construct:
65 -- open : boolean := false;
68 -- protected body PO is
70 -- ...variable declarations...
78 -- protected type poT is
81 -- open : boolean := false;
83 -- type poTV is limited record
84 -- open : boolean := false;
85 -- _object : aliased protection;
87 -- procedure poPT__pN (_object : in out poTV);
88 -- procedure poPT__pP (_object : in out poTV);
90 -- procedure _init_proc (_init : in out poTV) is
92 -- _init.open := false;
93 -- _init_proc (_init._object);
94 -- initialize_protection (_init._object'unchecked_access,
95 -- unspecified_priority);
100 -- _init_proc (poTV!(po));
102 -- procedure poPT__pN (_object : in out poTV) is
103 -- poR : protection renames _object._object;
104 -- openP : boolean renames _object.open;
105 -- ...variable declarations...
111 -- procedure poPT__pP (_object : in out poTV) is
112 -- procedure _clean is
114 -- unlock (_object._object'unchecked_access);
118 -- lock (_object._object'unchecked_access);
120 -- poPT__pN (_object);
127 Null_Protected_Entry
: constant := Null_Entry
;
129 Max_Protected_Entry
: constant := Max_Entry
;
131 type Protected_Entry_Index
is new Entry_Index
132 range Null_Protected_Entry
.. Max_Protected_Entry
;
134 type Barrier_Function_Pointer
is access
137 E
: Protected_Entry_Index
)
139 -- Pointer to a function which evaluates the barrier of a protected
140 -- entry body. O is a pointer to the compiler-generated record
141 -- representing the protected object, and E is the index of the
142 -- entry serviced by the body.
144 type Entry_Action_Pointer
is access
148 E
: Protected_Entry_Index
);
149 -- Pointer to a procedure which executes the sequence of statements
150 -- of a protected entry body. O is a pointer to the compiler-generated
151 -- record representing the protected object, P is a pointer to the
152 -- record of entry parameters, and E is the index of the
153 -- entry serviced by the body.
155 type Entry_Body
is record
156 Barrier
: Barrier_Function_Pointer
;
157 Action
: Entry_Action_Pointer
;
159 -- The compiler-generated code passes objects of this type to the GNARL
160 -- to allow it to access the executable code of an entry body.
162 type Entry_Body_Access
is access all Entry_Body
;
164 type Protection
is limited private;
165 -- This type contains the GNARL state of a protected object. The
166 -- application-defined portion of the state (i.e. private objects)
167 -- is maintained by the compiler-generated code.
168 -- Note that there are now 2 Protection types. One for the simple
169 -- case (no entries) and one for the general case that needs the whole
170 -- Finalization mechanism.
171 -- This split helps in the case of restricted run time where we want to
172 -- minimize the size of the code.
174 type Protection_Access
is access all Protection
;
176 Null_PO
: constant Protection_Access
:= null;
178 procedure Initialize_Protection
179 (Object
: Protection_Access
;
180 Ceiling_Priority
: Integer);
181 -- Initialize the Object parameter so that it can be used by the runtime
182 -- to keep track of the runtime state of a protected object.
184 procedure Lock
(Object
: Protection_Access
);
185 -- Lock a protected object for write access. Upon return, the caller
186 -- owns the lock to this object, and no other call to Lock or
187 -- Lock_Read_Only with the same argument will return until the
188 -- corresponding call to Unlock has been made by the caller.
190 procedure Lock_Read_Only
(Object
: Protection_Access
);
191 -- Lock a protected object for read access. Upon return, the caller
192 -- owns the lock for read access, and no other calls to Lock with the
193 -- same argument will return until the corresponding call to Unlock
194 -- has been made by the caller. Other calls to Lock_Read_Only may (but
195 -- need not) return before the call to Unlock, and the corresponding
196 -- callers will also own the lock for read access.
198 -- Note: we are not currently using this interface, it is provided
199 -- for possible future use. At the current time, everyone uses Lock
200 -- for both read and write locks.
202 procedure Unlock
(Object
: Protection_Access
);
203 -- Relinquish ownership of the lock for the object represented by
204 -- the Object parameter. If this ownership was for write access, or
205 -- if it was for read access where there are no other read access
206 -- locks outstanding, one (or more, in the case of Lock_Read_Only)
207 -- of the tasks waiting on this lock (if any) will be given the
208 -- lock and allowed to return from the Lock or Lock_Read_Only call.
211 type Protection
is record
212 L
: aliased Task_Primitives
.Lock
;
213 Ceiling
: System
.Any_Priority
;
215 pragma Volatile
(Protection
);
216 for Protection
'Alignment use Standard
'Maximum_Alignment;
217 -- Needed so that we can uncheck convert a Protection_Access to a
218 -- Protection_Entries_Access.
220 procedure Finalize_Protection
(Object
: in out Protection
);
221 -- Clean up a Protection object; in particular, finalize the associated
222 -- Lock object. The compiler generates automatically calls to this
225 end System
.Tasking
.Protected_Objects
;