annotate gcc/ada/libgnarl/s-taprob.ads @ 131:84e7813d76e9

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