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 --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
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. --
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. --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 -- This package provides overall initialization of the tasking portion of the
36 -- RTS. This package must be elaborated before any tasking features are used.
38 package System
.Tasking
.Initialization
is
40 procedure Remove_From_All_Tasks_List
(T
: Task_ID
);
41 -- Remove T from All_Tasks_List.
42 -- Call this function with RTS_Lock taken.
44 ---------------------------------
45 -- Tasking-Specific Soft Links --
46 ---------------------------------
48 -- These permit us to leave out certain portions of the tasking
49 -- run-time system if they are not used. They are only used internally
50 -- by the tasking run-time system.
51 -- So far, the only example is support for Ada.Task_Attributes.
53 type Proc_T
is access procedure (T
: Task_ID
);
55 procedure Finalize_Attributes
(T
: Task_ID
);
56 procedure Initialize_Attributes
(T
: Task_ID
);
58 Finalize_Attributes_Link
: Proc_T
:= Finalize_Attributes
'Access;
59 -- should be called with abortion deferred and T.L write-locked
61 Initialize_Attributes_Link
: Proc_T
:= Initialize_Attributes
'Access;
62 -- should be called with abortion deferred, but holding no locks
64 -------------------------
65 -- Abort Defer/Undefer --
66 -------------------------
68 -- Defer_Abort defers the affects of low-level abort and priority change
69 -- in the calling task until a matching Undefer_Abort call is executed.
71 -- Undefer_Abort DOES MORE than just undo the effects of one call to
72 -- Defer_Abort. It is the universal "polling point" for deferred
73 -- processing, including the following:
75 -- 1) base priority changes
79 -- Abort deferral MAY be nested (Self_ID.Deferral_Level is a count),
80 -- but to avoid waste and undetected errors, it generally SHOULD NOT
81 -- be nested. The symptom of over-deferring abort is that an exception
82 -- may fail to be raised, or an abort may fail to take place.
84 -- Therefore, there are two sets of the inlinable defer/undefer
85 -- routines, which are the ones to be used inside GNARL.
86 -- One set allows nesting. The other does not. People who
87 -- maintain the GNARL should try to avoid using the nested versions,
88 -- or at least look very critically at the places where they are
91 -- In general, any GNARL call that is potentially blocking, or
92 -- whose semantics require that it sometimes raise an exception,
93 -- or that is required to be an abort completion point, must be
94 -- made with abort Deferral_Level = 1.
96 -- In general, non-blocking GNARL calls, which may be made from inside
97 -- a protected action, are likely to need to allow nested abort
100 -- With some critical exceptions (which are supposed to be documented),
101 -- internal calls to the tasking runtime system assume abort is already
102 -- deferred, and do not modify the deferral level.
104 -- There is also a set of non-linable defer/undefer routines,
105 -- for direct call from the compiler. These are not in-lineable
106 -- because they may need to be called via pointers ("soft links").
107 -- For the sake of efficiency, the version with Self_ID as parameter
108 -- should used wherever possible. These are all nestable.
110 -- Non-nestable inline versions --
112 procedure Defer_Abort
(Self_ID
: Task_ID
);
113 pragma Inline
(Defer_Abort
);
115 procedure Undefer_Abort
(Self_ID
: Task_ID
);
116 pragma Inline
(Undefer_Abort
);
118 -- Nestable inline versions --
120 procedure Defer_Abort_Nestable
(Self_ID
: Task_ID
);
121 pragma Inline
(Defer_Abort_Nestable
);
123 procedure Undefer_Abort_Nestable
(Self_ID
: Task_ID
);
124 pragma Inline
(Undefer_Abort_Nestable
);
126 -- NON-INLINE versions without Self_ID for code generated by the
127 -- expander and for soft links
129 procedure Defer_Abortion
;
130 procedure Undefer_Abortion
;
133 -- Try to phase out all uses of the above versions.
135 function Check_Abort_Status
return Integer;
136 -- Returns Boolean'Pos (True) iff abort signal should raise
137 -- Standard.Abort_Signal. Only used by IRIX currently.
139 ---------------------------
140 -- Change Base Priority --
141 ---------------------------
143 procedure Change_Base_Priority
(T
: Task_ID
);
144 -- Change the base priority of T.
145 -- Has to be called with the affected task's ATCB write-locked.
146 -- May temporariliy release the lock.
148 procedure Poll_Base_Priority_Change
(Self_ID
: Task_ID
);
149 -- Has to be called with Self_ID's ATCB write-locked.
150 -- May temporariliy release the lock.
151 pragma Inline
(Poll_Base_Priority_Change
);
153 ----------------------
154 -- Task Lock/Unlock --
155 ----------------------
157 procedure Task_Lock
(Self_ID
: Task_ID
);
158 pragma Inline
(Task_Lock
);
160 procedure Task_Unlock
(Self_ID
: Task_ID
);
161 pragma Inline
(Task_Unlock
);
162 -- These are versions of Lock_Task and Unlock_Task created for use
165 procedure Final_Task_Unlock
(Self_ID
: Task_ID
);
166 -- This version is only for use in Terminate_Task, when the task
167 -- is relinquishing further rights to its own ATCB.
168 -- There is a very interesting potential race condition there, where
169 -- the old task may run concurrently with a new task that is allocated
170 -- the old tasks (now reused) ATCB. The critical thing here is to
171 -- not make any reference to the ATCB after the lock is released.
172 -- See also comments on Terminate_Task and Unlock.
174 procedure Wakeup_Entry_Caller
176 Entry_Call
: Entry_Call_Link
;
177 New_State
: Entry_Call_State
);
178 pragma Inline
(Wakeup_Entry_Caller
);
179 -- This is called at the end of service of an entry call,
180 -- to abort the caller if he is in an abortable part, and
181 -- to wake up the caller if he is on Entry_Caller_Sleep.
182 -- Call it holding the lock of Entry_Call.Self.
184 -- Timed_Call or Simple_Call:
185 -- The caller is waiting on Entry_Caller_Sleep, in
186 -- Wait_For_Completion, or Wait_For_Completion_With_Timeout.
189 -- The caller might be in Wait_For_Completion,
190 -- waiting for a rendezvous (possibly requeued without abort)
193 -- Asynchronous_Call:
194 -- The caller may be executing in the abortable part o
195 -- an async. select, or on a time delay,
196 -- if Entry_Call.State >= Was_Abortable.
198 procedure Locked_Abort_To_Level
202 pragma Inline
(Locked_Abort_To_Level
);
203 -- Abort a task to a specified ATC level.
204 -- Call this only with T locked.
206 end System
.Tasking
.Initialization
;