1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G . I N I T I A L I Z A T I O N --
11 -- Copyright (C) 1992-1999, 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 overall initialization of the tasking portion of the
38 -- RTS. This package must be elaborated before any tasking features are used.
39 -- It also contains initialization for Ada Task Control Block (ATCB) records.
41 package System
.Tasking
.Initialization
is
43 procedure Remove_From_All_Tasks_List
(T
: Task_ID
);
44 -- Remove T from All_Tasks_List.
46 ------------------------------------------------
47 -- Static (Compile-Time) Configuration Flags --
48 ------------------------------------------------
51 -- Maybe this does not belong here? Where else?
52 -- For now, it is here because so is Change_Base_Priority,
53 -- and the two are used together.
55 Dynamic_Priority_Support
: constant Boolean := True;
56 -- Should we poll for pending base priority changes at every
57 -- abort completion point?
59 ---------------------------------
60 -- Tasking-Specific Soft Links --
61 ---------------------------------
63 -- These permit us to leave out certain portions of the tasking
64 -- run-time system if they are not used. They are only used internally
65 -- by the tasking run-time system.
66 -- So far, the only example is support for Ada.Task_Attributes.
68 type Proc_T
is access procedure (T
: Task_ID
);
70 procedure Finalize_Attributes
(T
: Task_ID
);
71 procedure Initialize_Attributes
(T
: Task_ID
);
73 Finalize_Attributes_Link
: Proc_T
:= Finalize_Attributes
'Access;
74 -- should be called with abortion deferred and T.L write-locked
76 Initialize_Attributes_Link
: Proc_T
:= Initialize_Attributes
'Access;
77 -- should be called with abortion deferred, but holding no locks
79 -------------------------
80 -- Abort Defer/Undefer --
81 -------------------------
83 -- Defer_Abort defers the affects of low-level abort and priority change
84 -- in the calling task until a matching Undefer_Abort call is executed.
86 -- Undefer_Abort DOES MORE than just undo the effects of one call to
87 -- Defer_Abort. It is the universal "polling point" for deferred
88 -- processing, including the following:
90 -- 1) base priority changes
92 -- 2) exceptions that need to be raised
96 -- Abort deferral MAY be nested (Self_ID.Deferral_Level is a count),
97 -- but to avoid waste and undetected errors, it generally SHOULD NOT
98 -- be nested. The symptom of over-deferring abort is that an exception
99 -- may fail to be raised, or an abort may fail to take place.
101 -- Therefore, there are two sets of the inlinable defer/undefer
102 -- routines, which are the ones to be used inside GNARL.
103 -- One set allows nesting. The other does not. People who
104 -- maintain the GNARL should try to avoid using the nested versions,
105 -- or at least look very critically at the places where they are
108 -- In general, any GNARL call that is potentially blocking, or
109 -- whose semantics require that it sometimes raise an exception,
110 -- or that is required to be an abort completion point, must be
111 -- made with abort Deferral_Level = 1.
113 -- In general, non-blocking GNARL calls, which may be made from inside
114 -- a protected action, are likely to need to allow nested abort
117 -- With some critical exceptions (which are supposed to be documented),
118 -- internal calls to the tasking runtime system assume abort is already
119 -- deferred, and do not modify the deferral level.
121 -- There is also a set of non-linable defer/undefer routines,
122 -- for direct call from the compiler. These are not in-lineable
123 -- because they may need to be called via pointers ("soft links").
124 -- For the sake of efficiency, the version with Self_ID as parameter
125 -- should used wherever possible. These are all nestable.
127 -- Non-nestable inline versions --
129 procedure Defer_Abort
(Self_ID
: Task_ID
);
130 pragma Inline
(Defer_Abort
);
132 procedure Undefer_Abort
(Self_ID
: Task_ID
);
133 pragma Inline
(Undefer_Abort
);
135 -- Nestable inline versions --
137 procedure Defer_Abort_Nestable
(Self_ID
: Task_ID
);
138 pragma Inline
(Defer_Abort_Nestable
);
140 procedure Undefer_Abort_Nestable
(Self_ID
: Task_ID
);
141 pragma Inline
(Undefer_Abort_Nestable
);
143 -- NON-INLINE versions without Self_ID for code generated by the
144 -- expander and for hard links
146 procedure Defer_Abortion
;
147 procedure Undefer_Abortion
;
150 -- Try to phase out all uses of the above versions.
152 function Check_Abort_Status
return Integer;
153 -- Returns Boolean'Pos (True) iff abort signal should raise
154 -- Standard.Abort_Signal. Only used by IRIX currently.
156 ---------------------------
157 -- Change Base Priority --
158 ---------------------------
160 procedure Change_Base_Priority
(T
: Task_ID
);
161 -- Change the base priority of T.
162 -- Has to be called with the affected task's ATCB write-locked.
163 -- May temporariliy release the lock.
165 procedure Poll_Base_Priority_Change
(Self_ID
: Task_ID
);
166 -- Has to be called with Self_ID's ATCB write-locked.
167 -- May temporariliy release the lock.
168 pragma Inline
(Poll_Base_Priority_Change
);
170 ----------------------
171 -- Task Lock/Unlock --
172 ----------------------
174 procedure Task_Lock
(Self_ID
: Task_ID
);
175 procedure Task_Unlock
(Self_ID
: Task_ID
);
176 -- These are versions of Lock_Task and Unlock_Task created for use
179 procedure Final_Task_Unlock
(Self_ID
: Task_ID
);
180 -- This version is only for use in Terminate_Task, when the task
181 -- is relinquishing further rights to its own ATCB.
182 -- There is a very interesting potential race condition there, where
183 -- the old task may run concurrently with a new task that is allocated
184 -- the old tasks (now reused) ATCB. The critical thing here is to
185 -- not make any reference to the ATCB after the lock is released.
186 -- See also comments on Terminate_Task and Unlock.
188 procedure Wakeup_Entry_Caller
190 Entry_Call
: Entry_Call_Link
;
191 New_State
: Entry_Call_State
);
192 pragma Inline
(Wakeup_Entry_Caller
);
193 -- This is called at the end of service of an entry call,
194 -- to abort the caller if he is in an abortable part, and
195 -- to wake up the caller if he is on Entry_Caller_Sleep.
196 -- Call it holding the lock of Entry_Call.Self.
198 -- Timed_Call or Simple_Call:
199 -- The caller is waiting on Entry_Caller_Sleep, in
200 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
203 -- The caller might be in Wait_For_Completion,
204 -- waiting for a rendezvous (possibly requeued without abort)
207 -- Asynchronous_Call:
208 -- The caller may be executing in the abortable part o
209 -- an async. select, or on a time delay,
210 -- if Entry_Call.State >= Was_Abortable.
212 procedure Locked_Abort_To_Level
216 pragma Inline
(Locked_Abort_To_Level
);
217 -- Abort a task to a specified ATC level.
218 -- Call this only with T locked.
220 end System
.Tasking
.Initialization
;