OSDN Git Service

New Language: Ada
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tasini.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
4 --                                                                          --
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        --
6 --                                                                          --
7 --                                  S p e c                                 --
8 --                                                                          --
9 --                             $Revision: 1.24 $
10 --                                                                          --
11 --          Copyright (C) 1992-1999, Free Software Foundation, Inc.         --
12 --                                                                          --
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.                                                      --
23 --                                                                          --
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.                                      --
30 --                                                                          --
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).                                  --
34 --                                                                          --
35 ------------------------------------------------------------------------------
36
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.
40
41 package System.Tasking.Initialization is
42
43    procedure Remove_From_All_Tasks_List (T : Task_ID);
44    --  Remove T from All_Tasks_List.
45
46    ------------------------------------------------
47    -- Static (Compile-Time) Configuration Flags  --
48    ------------------------------------------------
49
50    --  ?????
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.
54
55    Dynamic_Priority_Support : constant Boolean := True;
56    --  Should we poll for pending base priority changes at every
57    --  abort completion point?
58
59    ---------------------------------
60    -- Tasking-Specific Soft Links --
61    ---------------------------------
62
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.
67
68    type Proc_T is access procedure (T : Task_ID);
69
70    procedure Finalize_Attributes (T : Task_ID);
71    procedure Initialize_Attributes (T : Task_ID);
72
73    Finalize_Attributes_Link : Proc_T := Finalize_Attributes'Access;
74    --  should be called with abortion deferred and T.L write-locked
75
76    Initialize_Attributes_Link : Proc_T := Initialize_Attributes'Access;
77    --  should be called with abortion deferred, but holding no locks
78
79    -------------------------
80    -- Abort Defer/Undefer --
81    -------------------------
82
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.
85
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:
89
90    --  1) base priority changes
91
92    --  2) exceptions that need to be raised
93
94    --  3) abort/ATC
95
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.
100
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
106    --  used.
107
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.
112
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
115    --  deferral.
116
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.
120
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.
126
127    --  Non-nestable inline versions  --
128
129    procedure Defer_Abort (Self_ID : Task_ID);
130    pragma Inline (Defer_Abort);
131
132    procedure Undefer_Abort (Self_ID : Task_ID);
133    pragma Inline (Undefer_Abort);
134
135    --  Nestable inline versions  --
136
137    procedure Defer_Abort_Nestable (Self_ID : Task_ID);
138    pragma Inline (Defer_Abort_Nestable);
139
140    procedure Undefer_Abort_Nestable (Self_ID : Task_ID);
141    pragma Inline (Undefer_Abort_Nestable);
142
143    --  NON-INLINE versions without Self_ID for code generated by the
144    --  expander and for hard links
145
146    procedure Defer_Abortion;
147    procedure Undefer_Abortion;
148
149    --  ?????
150    --  Try to phase out all uses of the above versions.
151
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.
155
156    ---------------------------
157    --  Change Base Priority --
158    ---------------------------
159
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.
164
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);
169
170    ----------------------
171    -- Task Lock/Unlock --
172    ----------------------
173
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
177    --  within the GNARL.
178
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.
187
188    procedure Wakeup_Entry_Caller
189      (Self_ID    : Task_ID;
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.
197    --
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.
201    --
202    --  Conditional_Call:
203    --    The caller might be in Wait_For_Completion,
204    --    waiting for a rendezvous (possibly requeued without abort)
205    --    to complete.
206    --
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.
211
212    procedure Locked_Abort_To_Level
213      (Self_ID : Task_ID;
214       T       : Task_ID;
215       L       : ATC_Level);
216    pragma Inline (Locked_Abort_To_Level);
217    --  Abort a task to a specified ATC level.
218    --  Call this only with T locked.
219
220 end System.Tasking.Initialization;