annotate gcc/ada/libgnarl/s-taprop.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 -- GNU ADA 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 _ P R I M I T I V E S .O P E R A T I O N 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 contains all the GNULL primitives that interface directly with
kono
parents:
diff changeset
33 -- the underlying OS.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 with System.Parameters;
kono
parents:
diff changeset
36 with System.Tasking;
kono
parents:
diff changeset
37 with System.OS_Interface;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 package System.Task_Primitives.Operations is
kono
parents:
diff changeset
40 pragma Preelaborate;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 package ST renames System.Tasking;
kono
parents:
diff changeset
43 package OSI renames System.OS_Interface;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 procedure Initialize (Environment_Task : ST.Task_Id);
kono
parents:
diff changeset
46 -- Perform initialization and set up of the environment task for proper
kono
parents:
diff changeset
47 -- operation of the tasking run-time. This must be called once, before any
kono
parents:
diff changeset
48 -- other subprograms of this package are called.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 procedure Create_Task
kono
parents:
diff changeset
51 (T : ST.Task_Id;
kono
parents:
diff changeset
52 Wrapper : System.Address;
kono
parents:
diff changeset
53 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
54 Priority : System.Any_Priority;
kono
parents:
diff changeset
55 Succeeded : out Boolean);
kono
parents:
diff changeset
56 pragma Inline (Create_Task);
kono
parents:
diff changeset
57 -- Create a new low-level task with ST.Task_Id T and place other needed
kono
parents:
diff changeset
58 -- information in the ATCB.
kono
parents:
diff changeset
59 --
kono
parents:
diff changeset
60 -- A new thread of control is created, with a stack of at least Stack_Size
kono
parents:
diff changeset
61 -- storage units, and the procedure Wrapper is called by this new thread
kono
parents:
diff changeset
62 -- of control. If Stack_Size = Unspecified_Storage_Size, choose a default
kono
parents:
diff changeset
63 -- stack size; this may be effectively "unbounded" on some systems.
kono
parents:
diff changeset
64 --
kono
parents:
diff changeset
65 -- The newly created low-level task is associated with the ST.Task_Id T
kono
parents:
diff changeset
66 -- such that any subsequent call to Self from within the context of the
kono
parents:
diff changeset
67 -- low-level task returns T.
kono
parents:
diff changeset
68 --
kono
parents:
diff changeset
69 -- The caller is responsible for ensuring that the storage of the Ada
kono
parents:
diff changeset
70 -- task control block object pointed to by T persists for the lifetime
kono
parents:
diff changeset
71 -- of the new task.
kono
parents:
diff changeset
72 --
kono
parents:
diff changeset
73 -- Succeeded is set to true unless creation of the task failed,
kono
parents:
diff changeset
74 -- as it may if there are insufficient resources to create another task.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 procedure Enter_Task (Self_ID : ST.Task_Id);
kono
parents:
diff changeset
77 pragma Inline (Enter_Task);
kono
parents:
diff changeset
78 -- Initialize data structures specific to the calling task. Self must be
kono
parents:
diff changeset
79 -- the ID of the calling task. It must be called (once) by the task
kono
parents:
diff changeset
80 -- immediately after creation, while abort is still deferred. The effects
kono
parents:
diff changeset
81 -- of other operations defined below are not defined unless the caller has
kono
parents:
diff changeset
82 -- previously called Initialize_Task.
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 procedure Exit_Task;
kono
parents:
diff changeset
85 pragma Inline (Exit_Task);
kono
parents:
diff changeset
86 -- Destroy the thread of control. Self must be the ID of the calling task.
kono
parents:
diff changeset
87 -- The effects of further calls to operations defined below on the task
kono
parents:
diff changeset
88 -- are undefined thereafter.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 ----------------------------------
kono
parents:
diff changeset
91 -- ATCB allocation/deallocation --
kono
parents:
diff changeset
92 ----------------------------------
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 package ATCB_Allocation is
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 function New_ATCB (Entry_Num : ST.Task_Entry_Index) return ST.Task_Id;
kono
parents:
diff changeset
97 pragma Inline (New_ATCB);
kono
parents:
diff changeset
98 -- Allocate a new ATCB with the specified number of entries
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Free_ATCB (T : ST.Task_Id);
kono
parents:
diff changeset
101 pragma Inline (Free_ATCB);
kono
parents:
diff changeset
102 -- Deallocate an ATCB previously allocated by New_ATCB
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 end ATCB_Allocation;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function New_ATCB (Entry_Num : ST.Task_Entry_Index) return ST.Task_Id
kono
parents:
diff changeset
107 renames ATCB_Allocation.New_ATCB;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 procedure Initialize_TCB (Self_ID : ST.Task_Id; Succeeded : out Boolean);
kono
parents:
diff changeset
110 pragma Inline (Initialize_TCB);
kono
parents:
diff changeset
111 -- Initialize all fields of the TCB
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 procedure Finalize_TCB (T : ST.Task_Id);
kono
parents:
diff changeset
114 pragma Inline (Finalize_TCB);
kono
parents:
diff changeset
115 -- Finalizes Private_Data of ATCB, and then deallocates it. This is also
kono
parents:
diff changeset
116 -- responsible for recovering any storage or other resources that were
kono
parents:
diff changeset
117 -- allocated by Create_Task (the one in this package). This should only be
kono
parents:
diff changeset
118 -- called from Free_Task. After it is called there should be no further
kono
parents:
diff changeset
119 -- reference to the ATCB that corresponds to T.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 procedure Abort_Task (T : ST.Task_Id);
kono
parents:
diff changeset
122 pragma Inline (Abort_Task);
kono
parents:
diff changeset
123 -- Abort the task specified by T (the target task). This causes the target
kono
parents:
diff changeset
124 -- task to asynchronously raise Abort_Signal if abort is not deferred, or
kono
parents:
diff changeset
125 -- if it is blocked on an interruptible system call.
kono
parents:
diff changeset
126 --
kono
parents:
diff changeset
127 -- precondition:
kono
parents:
diff changeset
128 -- the calling task is holding T's lock and has abort deferred
kono
parents:
diff changeset
129 --
kono
parents:
diff changeset
130 -- postcondition:
kono
parents:
diff changeset
131 -- the calling task is holding T's lock and has abort deferred.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- ??? modify GNARL to skip wakeup and always call Abort_Task
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 function Self return ST.Task_Id;
kono
parents:
diff changeset
136 pragma Inline (Self);
kono
parents:
diff changeset
137 -- Return a pointer to the Ada Task Control Block of the calling task
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 type Lock_Level is
kono
parents:
diff changeset
140 (PO_Level,
kono
parents:
diff changeset
141 Global_Task_Level,
kono
parents:
diff changeset
142 RTS_Lock_Level,
kono
parents:
diff changeset
143 ATCB_Level);
kono
parents:
diff changeset
144 -- Type used to describe kind of lock for second form of Initialize_Lock
kono
parents:
diff changeset
145 -- call specified below. See locking rules in System.Tasking (spec) for
kono
parents:
diff changeset
146 -- more details.
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 procedure Initialize_Lock
kono
parents:
diff changeset
149 (Prio : System.Any_Priority;
kono
parents:
diff changeset
150 L : not null access Lock);
kono
parents:
diff changeset
151 procedure Initialize_Lock
kono
parents:
diff changeset
152 (L : not null access RTS_Lock;
kono
parents:
diff changeset
153 Level : Lock_Level);
kono
parents:
diff changeset
154 pragma Inline (Initialize_Lock);
kono
parents:
diff changeset
155 -- Initialize a lock object
kono
parents:
diff changeset
156 --
kono
parents:
diff changeset
157 -- For Lock, Prio is the ceiling priority associated with the lock. For
kono
parents:
diff changeset
158 -- RTS_Lock, the ceiling is implicitly Priority'Last.
kono
parents:
diff changeset
159 --
kono
parents:
diff changeset
160 -- If the underlying system does not support priority ceiling
kono
parents:
diff changeset
161 -- locking, the Prio parameter is ignored.
kono
parents:
diff changeset
162 --
kono
parents:
diff changeset
163 -- The effect of either initialize operation is undefined unless is a lock
kono
parents:
diff changeset
164 -- object that has not been initialized, or which has been finalized since
kono
parents:
diff changeset
165 -- it was last initialized.
kono
parents:
diff changeset
166 --
kono
parents:
diff changeset
167 -- The effects of the other operations on lock objects are undefined
kono
parents:
diff changeset
168 -- unless the lock object has been initialized and has not since been
kono
parents:
diff changeset
169 -- finalized.
kono
parents:
diff changeset
170 --
kono
parents:
diff changeset
171 -- Initialization of the per-task lock is implicit in Create_Task
kono
parents:
diff changeset
172 --
kono
parents:
diff changeset
173 -- These operations raise Storage_Error if a lack of storage is detected
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 procedure Finalize_Lock (L : not null access Lock);
kono
parents:
diff changeset
176 procedure Finalize_Lock (L : not null access RTS_Lock);
kono
parents:
diff changeset
177 pragma Inline (Finalize_Lock);
kono
parents:
diff changeset
178 -- Finalize a lock object, freeing any resources allocated by the
kono
parents:
diff changeset
179 -- corresponding Initialize_Lock operation.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 procedure Write_Lock
kono
parents:
diff changeset
182 (L : not null access Lock;
kono
parents:
diff changeset
183 Ceiling_Violation : out Boolean);
kono
parents:
diff changeset
184 procedure Write_Lock
kono
parents:
diff changeset
185 (L : not null access RTS_Lock;
kono
parents:
diff changeset
186 Global_Lock : Boolean := False);
kono
parents:
diff changeset
187 procedure Write_Lock
kono
parents:
diff changeset
188 (T : ST.Task_Id);
kono
parents:
diff changeset
189 pragma Inline (Write_Lock);
kono
parents:
diff changeset
190 -- Lock a lock object for write access. After this operation returns,
kono
parents:
diff changeset
191 -- the calling task holds write permission for the lock object. No other
kono
parents:
diff changeset
192 -- Write_Lock or Read_Lock operation on the same lock object will return
kono
parents:
diff changeset
193 -- until this task executes an Unlock operation on the same object. The
kono
parents:
diff changeset
194 -- effect is undefined if the calling task already holds read or write
kono
parents:
diff changeset
195 -- permission for the lock object L.
kono
parents:
diff changeset
196 --
kono
parents:
diff changeset
197 -- For the operation on Lock, Ceiling_Violation is set to true iff the
kono
parents:
diff changeset
198 -- operation failed, which will happen if there is a priority ceiling
kono
parents:
diff changeset
199 -- violation.
kono
parents:
diff changeset
200 --
kono
parents:
diff changeset
201 -- For the operation on RTS_Lock, Global_Lock should be set to True
kono
parents:
diff changeset
202 -- if L is a global lock (Single_RTS_Lock, Global_Task_Lock).
kono
parents:
diff changeset
203 --
kono
parents:
diff changeset
204 -- For the operation on ST.Task_Id, the lock is the special lock object
kono
parents:
diff changeset
205 -- associated with that task's ATCB. This lock has effective ceiling
kono
parents:
diff changeset
206 -- priority high enough that it is safe to call by a task with any
kono
parents:
diff changeset
207 -- priority in the range System.Priority. It is implicitly initialized
kono
parents:
diff changeset
208 -- by task creation. The effect is undefined if the calling task already
kono
parents:
diff changeset
209 -- holds T's lock, or has interrupt-level priority. Finalization of the
kono
parents:
diff changeset
210 -- per-task lock is implicit in Exit_Task.
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 procedure Read_Lock
kono
parents:
diff changeset
213 (L : not null access Lock;
kono
parents:
diff changeset
214 Ceiling_Violation : out Boolean);
kono
parents:
diff changeset
215 pragma Inline (Read_Lock);
kono
parents:
diff changeset
216 -- Lock a lock object for read access. After this operation returns,
kono
parents:
diff changeset
217 -- the calling task has non-exclusive read permission for the logical
kono
parents:
diff changeset
218 -- resources that are protected by the lock. No other Write_Lock operation
kono
parents:
diff changeset
219 -- on the same object will return until this task and any other tasks with
kono
parents:
diff changeset
220 -- read permission for this lock have executed Unlock operation(s) on the
kono
parents:
diff changeset
221 -- lock object. A Read_Lock for a lock object may return immediately while
kono
parents:
diff changeset
222 -- there are tasks holding read permission, provided there are no tasks
kono
parents:
diff changeset
223 -- holding write permission for the object. The effect is undefined if
kono
parents:
diff changeset
224 -- the calling task already holds read or write permission for L.
kono
parents:
diff changeset
225 --
kono
parents:
diff changeset
226 -- Alternatively: An implementation may treat Read_Lock identically to
kono
parents:
diff changeset
227 -- Write_Lock. This simplifies the implementation, but reduces the level
kono
parents:
diff changeset
228 -- of concurrency that can be achieved.
kono
parents:
diff changeset
229 --
kono
parents:
diff changeset
230 -- Note that Read_Lock is not defined for RT_Lock and ST.Task_Id.
kono
parents:
diff changeset
231 -- That is because (1) so far Read_Lock has always been implemented
kono
parents:
diff changeset
232 -- the same as Write_Lock, (2) most lock usage inside the RTS involves
kono
parents:
diff changeset
233 -- potential write access, and (3) implementations of priority ceiling
kono
parents:
diff changeset
234 -- locking that make a reader-writer distinction have higher overhead.
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 procedure Unlock
kono
parents:
diff changeset
237 (L : not null access Lock);
kono
parents:
diff changeset
238 procedure Unlock
kono
parents:
diff changeset
239 (L : not null access RTS_Lock;
kono
parents:
diff changeset
240 Global_Lock : Boolean := False);
kono
parents:
diff changeset
241 procedure Unlock
kono
parents:
diff changeset
242 (T : ST.Task_Id);
kono
parents:
diff changeset
243 pragma Inline (Unlock);
kono
parents:
diff changeset
244 -- Unlock a locked lock object
kono
parents:
diff changeset
245 --
kono
parents:
diff changeset
246 -- The effect is undefined unless the calling task holds read or write
kono
parents:
diff changeset
247 -- permission for the lock L, and L is the lock object most recently
kono
parents:
diff changeset
248 -- locked by the calling task for which the calling task still holds
kono
parents:
diff changeset
249 -- read or write permission. (That is, matching pairs of Lock and Unlock
kono
parents:
diff changeset
250 -- operations on each lock object must be properly nested.)
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- For the operation on RTS_Lock, Global_Lock should be set to True if L
kono
parents:
diff changeset
253 -- is a global lock (Single_RTS_Lock, Global_Task_Lock).
kono
parents:
diff changeset
254 --
kono
parents:
diff changeset
255 -- Note that Write_Lock for RTS_Lock does not have an out-parameter.
kono
parents:
diff changeset
256 -- RTS_Locks are used in situations where we have not made provision for
kono
parents:
diff changeset
257 -- recovery from ceiling violations. We do not expect them to occur inside
kono
parents:
diff changeset
258 -- the runtime system, because all RTS locks have ceiling Priority'Last.
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 -- There is one way there can be a ceiling violation. That is if the
kono
parents:
diff changeset
261 -- runtime system is called from a task that is executing in the
kono
parents:
diff changeset
262 -- Interrupt_Priority range.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 -- It is not clear what to do about ceiling violations due to RTS calls
kono
parents:
diff changeset
265 -- done at interrupt priority. In general, it is not acceptable to give
kono
parents:
diff changeset
266 -- all RTS locks interrupt priority, since that would give terrible
kono
parents:
diff changeset
267 -- performance on systems where this has the effect of masking hardware
kono
parents:
diff changeset
268 -- interrupts, though we could get away allowing Interrupt_Priority'last
kono
parents:
diff changeset
269 -- where we are layered on an OS that does not allow us to mask interrupts.
kono
parents:
diff changeset
270 -- Ideally, we would like to raise Program_Error back at the original point
kono
parents:
diff changeset
271 -- of the RTS call, but this would require a lot of detailed analysis and
kono
parents:
diff changeset
272 -- recoding, with almost certain performance penalties.
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 -- For POSIX systems, we considered just skipping setting priority ceiling
kono
parents:
diff changeset
275 -- on RTS locks. This would mean there is no ceiling violation, but we
kono
parents:
diff changeset
276 -- would end up with priority inversions inside the runtime system,
kono
parents:
diff changeset
277 -- resulting in failure to satisfy the Ada priority rules, and possible
kono
parents:
diff changeset
278 -- missed validation tests. This could be compensated-for by explicit
kono
parents:
diff changeset
279 -- priority-change calls to raise the caller to Priority'Last whenever it
kono
parents:
diff changeset
280 -- first enters the runtime system, but the expected overhead seems high,
kono
parents:
diff changeset
281 -- though it might be lower than using locks with ceilings if the
kono
parents:
diff changeset
282 -- underlying implementation of ceiling locks is an inefficient one.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 -- This issue should be reconsidered whenever we get around to checking
kono
parents:
diff changeset
285 -- for calls to potentially blocking operations from within protected
kono
parents:
diff changeset
286 -- operations. If we check for such calls and catch them on entry to the
kono
parents:
diff changeset
287 -- OS, it may be that we can eliminate the possibility of ceiling
kono
parents:
diff changeset
288 -- violations inside the RTS. For this to work, we would have to forbid
kono
parents:
diff changeset
289 -- explicitly setting the priority of a task to anything in the
kono
parents:
diff changeset
290 -- Interrupt_Priority range, at least. We would also have to check that
kono
parents:
diff changeset
291 -- there are no RTS-lock operations done inside any operations that are
kono
parents:
diff changeset
292 -- not treated as potentially blocking.
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 -- The latter approach seems to be the best, i.e. to check on entry to RTS
kono
parents:
diff changeset
295 -- calls that may need to use locks that the priority is not in the
kono
parents:
diff changeset
296 -- interrupt range. If there are RTS operations that NEED to be called
kono
parents:
diff changeset
297 -- from interrupt handlers, those few RTS locks should then be converted
kono
parents:
diff changeset
298 -- to PO-type locks, with ceiling Interrupt_Priority'Last.
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 -- For now, we will just shut down the system if there is ceiling violation
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 procedure Set_Ceiling
kono
parents:
diff changeset
303 (L : not null access Lock;
kono
parents:
diff changeset
304 Prio : System.Any_Priority);
kono
parents:
diff changeset
305 pragma Inline (Set_Ceiling);
kono
parents:
diff changeset
306 -- Change the ceiling priority associated to the lock
kono
parents:
diff changeset
307 --
kono
parents:
diff changeset
308 -- The effect is undefined unless the calling task holds read or write
kono
parents:
diff changeset
309 -- permission for the lock L, and L is the lock object most recently
kono
parents:
diff changeset
310 -- locked by the calling task for which the calling task still holds
kono
parents:
diff changeset
311 -- read or write permission. (That is, matching pairs of Lock and Unlock
kono
parents:
diff changeset
312 -- operations on each lock object must be properly nested.)
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 procedure Yield (Do_Yield : Boolean := True);
kono
parents:
diff changeset
315 pragma Inline (Yield);
kono
parents:
diff changeset
316 -- Yield the processor. Add the calling task to the tail of the ready queue
kono
parents:
diff changeset
317 -- for its active_priority. On most platforms, Yield is a no-op if Do_Yield
kono
parents:
diff changeset
318 -- is False. But on some platforms (notably VxWorks), Do_Yield is ignored.
kono
parents:
diff changeset
319 -- This is only used in some very rare cases where a Yield should have an
kono
parents:
diff changeset
320 -- effect on a specific target and not on regular ones.
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 procedure Set_Priority
kono
parents:
diff changeset
323 (T : ST.Task_Id;
kono
parents:
diff changeset
324 Prio : System.Any_Priority;
kono
parents:
diff changeset
325 Loss_Of_Inheritance : Boolean := False);
kono
parents:
diff changeset
326 pragma Inline (Set_Priority);
kono
parents:
diff changeset
327 -- Set the priority of the task specified by T to Prio. The priority set
kono
parents:
diff changeset
328 -- is what would correspond to the Ada concept of "base priority" in the
kono
parents:
diff changeset
329 -- terms of the lower layer system, but the operation may be used by the
kono
parents:
diff changeset
330 -- upper layer to implement changes in "active priority" that are not due
kono
parents:
diff changeset
331 -- to lock effects. The effect should be consistent with the Ada Reference
kono
parents:
diff changeset
332 -- Manual. In particular, when a task lowers its priority due to the loss
kono
parents:
diff changeset
333 -- of inherited priority, it goes at the head of the queue for its new
kono
parents:
diff changeset
334 -- priority (RM D.2.2 par 9). Loss_Of_Inheritance helps the underlying
kono
parents:
diff changeset
335 -- implementation to do it right when the OS doesn't.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 function Get_Priority (T : ST.Task_Id) return System.Any_Priority;
kono
parents:
diff changeset
338 pragma Inline (Get_Priority);
kono
parents:
diff changeset
339 -- Returns the priority last set by Set_Priority for this task
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 function Monotonic_Clock return Duration;
kono
parents:
diff changeset
342 pragma Inline (Monotonic_Clock);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 -- Returns "absolute" time, represented as an offset relative to an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 -- unspecified Epoch. This clock implementation is immune to the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 -- system's clock changes.
111
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 function RT_Resolution return Duration;
kono
parents:
diff changeset
348 pragma Inline (RT_Resolution);
kono
parents:
diff changeset
349 -- Returns resolution of the underlying clock used to implement RT_Clock
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 ----------------
kono
parents:
diff changeset
352 -- Extensions --
kono
parents:
diff changeset
353 ----------------
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 -- Whoever calls either of the Sleep routines is responsible for checking
kono
parents:
diff changeset
356 -- for pending aborts before the call. Pending priority changes are handled
kono
parents:
diff changeset
357 -- internally.
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 procedure Sleep
kono
parents:
diff changeset
360 (Self_ID : ST.Task_Id;
kono
parents:
diff changeset
361 Reason : System.Tasking.Task_States);
kono
parents:
diff changeset
362 pragma Inline (Sleep);
kono
parents:
diff changeset
363 -- Wait until the current task, T, is signaled to wake up
kono
parents:
diff changeset
364 --
kono
parents:
diff changeset
365 -- precondition:
kono
parents:
diff changeset
366 -- The calling task is holding its own ATCB lock
kono
parents:
diff changeset
367 -- and has abort deferred
kono
parents:
diff changeset
368 --
kono
parents:
diff changeset
369 -- postcondition:
kono
parents:
diff changeset
370 -- The calling task is holding its own ATCB lock and has abort deferred.
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 -- The effect is to atomically unlock T's lock and wait, so that another
kono
parents:
diff changeset
373 -- task that is able to lock T's lock can be assured that the wait has
kono
parents:
diff changeset
374 -- actually commenced, and that a Wakeup operation will cause the waiting
kono
parents:
diff changeset
375 -- task to become ready for execution once again. When Sleep returns, the
kono
parents:
diff changeset
376 -- waiting task will again hold its own ATCB lock. The waiting task may
kono
parents:
diff changeset
377 -- become ready for execution at any time (that is, spurious wakeups are
kono
parents:
diff changeset
378 -- permitted), but it will definitely become ready for execution when a
kono
parents:
diff changeset
379 -- Wakeup operation is performed for the same task.
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 procedure Timed_Sleep
kono
parents:
diff changeset
382 (Self_ID : ST.Task_Id;
kono
parents:
diff changeset
383 Time : Duration;
kono
parents:
diff changeset
384 Mode : ST.Delay_Modes;
kono
parents:
diff changeset
385 Reason : System.Tasking.Task_States;
kono
parents:
diff changeset
386 Timedout : out Boolean;
kono
parents:
diff changeset
387 Yielded : out Boolean);
kono
parents:
diff changeset
388 -- Combination of Sleep (above) and Timed_Delay
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 procedure Timed_Delay
kono
parents:
diff changeset
391 (Self_ID : ST.Task_Id;
kono
parents:
diff changeset
392 Time : Duration;
kono
parents:
diff changeset
393 Mode : ST.Delay_Modes);
kono
parents:
diff changeset
394 -- Implement the semantics of the delay statement.
kono
parents:
diff changeset
395 -- The caller should be abort-deferred and should not hold any locks.
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 procedure Wakeup
kono
parents:
diff changeset
398 (T : ST.Task_Id;
kono
parents:
diff changeset
399 Reason : System.Tasking.Task_States);
kono
parents:
diff changeset
400 pragma Inline (Wakeup);
kono
parents:
diff changeset
401 -- Wake up task T if it is waiting on a Sleep call (of ordinary
kono
parents:
diff changeset
402 -- or timed variety), making it ready for execution once again.
kono
parents:
diff changeset
403 -- If the task T is not waiting on a Sleep, the operation has no effect.
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 function Environment_Task return ST.Task_Id;
kono
parents:
diff changeset
406 pragma Inline (Environment_Task);
kono
parents:
diff changeset
407 -- Return the task ID of the environment task
kono
parents:
diff changeset
408 -- Consider putting this into a variable visible directly
kono
parents:
diff changeset
409 -- by the rest of the runtime system. ???
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 function Get_Thread_Id (T : ST.Task_Id) return OSI.Thread_Id;
kono
parents:
diff changeset
412 -- Return the thread id of the specified task
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 function Is_Valid_Task return Boolean;
kono
parents:
diff changeset
415 pragma Inline (Is_Valid_Task);
kono
parents:
diff changeset
416 -- Does the calling thread have an ATCB?
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 function Register_Foreign_Thread return ST.Task_Id;
kono
parents:
diff changeset
419 -- Allocate and initialize a new ATCB for the current thread
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 -----------------------
kono
parents:
diff changeset
422 -- RTS Entrance/Exit --
kono
parents:
diff changeset
423 -----------------------
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 -- Following two routines are used for possible operations needed to be
kono
parents:
diff changeset
426 -- setup/cleared upon entrance/exit of RTS while maintaining a single
kono
parents:
diff changeset
427 -- thread of control in the RTS. Since we intend these routines to be used
kono
parents:
diff changeset
428 -- for implementing the Single_Lock RTS, Lock_RTS should follow the first
kono
parents:
diff changeset
429 -- Defer_Abort operation entering RTS. In the same fashion Unlock_RTS
kono
parents:
diff changeset
430 -- should precede the last Undefer_Abort exiting RTS.
kono
parents:
diff changeset
431 --
kono
parents:
diff changeset
432 -- These routines also replace the functions Lock/Unlock_All_Tasks_List
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 procedure Lock_RTS;
kono
parents:
diff changeset
435 -- Take the global RTS lock
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 procedure Unlock_RTS;
kono
parents:
diff changeset
438 -- Release the global RTS lock
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 --------------------
kono
parents:
diff changeset
441 -- Stack Checking --
kono
parents:
diff changeset
442 --------------------
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 -- Stack checking in GNAT is done using the concept of stack probes. A
kono
parents:
diff changeset
445 -- stack probe is an operation that will generate a storage error if
kono
parents:
diff changeset
446 -- an insufficient amount of stack space remains in the current task.
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 -- The exact mechanism for a stack probe is target dependent. Typical
kono
parents:
diff changeset
449 -- possibilities are to use a load from a non-existent page, a store to a
kono
parents:
diff changeset
450 -- read-only page, or a comparison with some stack limit constant. Where
kono
parents:
diff changeset
451 -- possible we prefer to use a trap on a bad page access, since this has
kono
parents:
diff changeset
452 -- less overhead. The generation of stack probes is either automatic if
kono
parents:
diff changeset
453 -- the ABI requires it (as on for example DEC Unix), or is controlled by
kono
parents:
diff changeset
454 -- the gcc parameter -fstack-check.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 -- When we are using bad-page accesses, we need a bad page, called guard
kono
parents:
diff changeset
457 -- page, at the end of each task stack. On some systems, this is provided
kono
parents:
diff changeset
458 -- automatically, but on other systems, we need to create the guard page
kono
parents:
diff changeset
459 -- ourselves, and the procedure Stack_Guard is provided for this purpose.
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 procedure Stack_Guard (T : ST.Task_Id; On : Boolean);
kono
parents:
diff changeset
462 -- Ensure guard page is set if one is needed and the underlying thread
kono
parents:
diff changeset
463 -- system does not provide it. The procedure is as follows:
kono
parents:
diff changeset
464 --
kono
parents:
diff changeset
465 -- 1. When we create a task adjust its size so a guard page can
kono
parents:
diff changeset
466 -- safely be set at the bottom of the stack.
kono
parents:
diff changeset
467 --
kono
parents:
diff changeset
468 -- 2. When the thread is created (and its stack allocated by the
kono
parents:
diff changeset
469 -- underlying thread system), get the stack base (and size, depending
kono
parents:
diff changeset
470 -- how the stack is growing), and create the guard page taking care
kono
parents:
diff changeset
471 -- of page boundaries issues.
kono
parents:
diff changeset
472 --
kono
parents:
diff changeset
473 -- 3. When the task is destroyed, remove the guard page.
kono
parents:
diff changeset
474 --
kono
parents:
diff changeset
475 -- If On is true then protect the stack bottom (i.e make it read only)
kono
parents:
diff changeset
476 -- else unprotect it (i.e. On is True for the call when creating a task,
kono
parents:
diff changeset
477 -- and False when a task is destroyed).
kono
parents:
diff changeset
478 --
kono
parents:
diff changeset
479 -- The call to Stack_Guard has no effect if guard pages are not used on
kono
parents:
diff changeset
480 -- the target, or if guard pages are automatically provided by the system.
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 ------------------------
kono
parents:
diff changeset
483 -- Suspension objects --
kono
parents:
diff changeset
484 ------------------------
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 -- These subprograms provide the functionality required for synchronizing
kono
parents:
diff changeset
487 -- on a suspension object. Tasks can suspend execution and relinquish the
kono
parents:
diff changeset
488 -- processors until the condition is signaled.
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 function Current_State (S : Suspension_Object) return Boolean;
kono
parents:
diff changeset
491 -- Return the state of the suspension object
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 procedure Set_False (S : in out Suspension_Object);
kono
parents:
diff changeset
494 -- Set the state of the suspension object to False
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 procedure Set_True (S : in out Suspension_Object);
kono
parents:
diff changeset
497 -- Set the state of the suspension object to True. If a task were
kono
parents:
diff changeset
498 -- suspended on the protected object then this task is released (and
kono
parents:
diff changeset
499 -- the state of the suspension object remains set to False).
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 procedure Suspend_Until_True (S : in out Suspension_Object);
kono
parents:
diff changeset
502 -- If the state of the suspension object is True then the calling task
kono
parents:
diff changeset
503 -- continues its execution, and the state is set to False. If the state
kono
parents:
diff changeset
504 -- of the object is False then the task is suspended on the suspension
kono
parents:
diff changeset
505 -- object until a Set_True operation is executed. Program_Error is raised
kono
parents:
diff changeset
506 -- if another task is already waiting on that suspension object.
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 procedure Initialize (S : in out Suspension_Object);
kono
parents:
diff changeset
509 -- Initialize the suspension object
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 procedure Finalize (S : in out Suspension_Object);
kono
parents:
diff changeset
512 -- Finalize the suspension object
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 -----------------------------------------
kono
parents:
diff changeset
515 -- Runtime System Debugging Interfaces --
kono
parents:
diff changeset
516 -----------------------------------------
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 -- These interfaces have been added to assist in debugging the
kono
parents:
diff changeset
519 -- tasking runtime system.
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 function Check_Exit (Self_ID : ST.Task_Id) return Boolean;
kono
parents:
diff changeset
522 pragma Inline (Check_Exit);
kono
parents:
diff changeset
523 -- Check that the current task is holding only Global_Task_Lock
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 function Check_No_Locks (Self_ID : ST.Task_Id) return Boolean;
kono
parents:
diff changeset
526 pragma Inline (Check_No_Locks);
kono
parents:
diff changeset
527 -- Check that current task is holding no locks
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 function Suspend_Task
kono
parents:
diff changeset
530 (T : ST.Task_Id;
kono
parents:
diff changeset
531 Thread_Self : OSI.Thread_Id) return Boolean;
kono
parents:
diff changeset
532 -- Suspend a specific task when the underlying thread library provides this
kono
parents:
diff changeset
533 -- functionality, unless the thread associated with T is Thread_Self. Such
kono
parents:
diff changeset
534 -- functionality is needed by gdb on some targets (e.g VxWorks) Return True
kono
parents:
diff changeset
535 -- is the operation is successful. On targets where this operation is not
kono
parents:
diff changeset
536 -- available, a dummy body is present which always returns False.
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 function Resume_Task
kono
parents:
diff changeset
539 (T : ST.Task_Id;
kono
parents:
diff changeset
540 Thread_Self : OSI.Thread_Id) return Boolean;
kono
parents:
diff changeset
541 -- Resume a specific task when the underlying thread library provides
kono
parents:
diff changeset
542 -- such functionality, unless the thread associated with T is Thread_Self.
kono
parents:
diff changeset
543 -- Such functionality is needed by gdb on some targets (e.g VxWorks)
kono
parents:
diff changeset
544 -- Return True is the operation is successful
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 procedure Stop_All_Tasks;
kono
parents:
diff changeset
547 -- Stop all tasks when the underlying thread library provides such
kono
parents:
diff changeset
548 -- functionality. Such functionality is needed by gdb on some targets (e.g
kono
parents:
diff changeset
549 -- VxWorks) This function can be run from an interrupt handler. Return True
kono
parents:
diff changeset
550 -- is the operation is successful
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 function Stop_Task (T : ST.Task_Id) return Boolean;
kono
parents:
diff changeset
553 -- Stop a specific task when the underlying thread library provides
kono
parents:
diff changeset
554 -- such functionality. Such functionality is needed by gdb on some targets
kono
parents:
diff changeset
555 -- (e.g VxWorks). Return True is the operation is successful.
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 function Continue_Task (T : ST.Task_Id) return Boolean;
kono
parents:
diff changeset
558 -- Continue a specific task when the underlying thread library provides
kono
parents:
diff changeset
559 -- such functionality. Such functionality is needed by gdb on some targets
kono
parents:
diff changeset
560 -- (e.g VxWorks) Return True is the operation is successful
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 -------------------
kono
parents:
diff changeset
563 -- Task affinity --
kono
parents:
diff changeset
564 -------------------
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 procedure Set_Task_Affinity (T : ST.Task_Id);
kono
parents:
diff changeset
567 -- Enforce at the operating system level the task affinity defined in the
kono
parents:
diff changeset
568 -- Ada Task Control Block. Has no effect if the underlying operating system
kono
parents:
diff changeset
569 -- does not support this capability.
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 end System.Task_Primitives.Operations;