OSDN Git Service

2004-05-17 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
[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 --          Copyright (C) 1992-2004, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNARL is free software; you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNARL was developed by the GNARL team at Florida State University.       --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package provides overall initialization of the tasking portion of the
35 --  RTS. This package must be elaborated before any tasking features are used.
36
37 package System.Tasking.Initialization is
38
39    procedure Remove_From_All_Tasks_List (T : Task_Id);
40    --  Remove T from All_Tasks_List.
41    --  Call this function with RTS_Lock taken.
42
43    ---------------------------------
44    -- Tasking-Specific Soft Links --
45    ---------------------------------
46
47    --  These permit us to leave out certain portions of the tasking
48    --  run-time system if they are not used.  They are only used internally
49    --  by the tasking run-time system.
50    --  So far, the only example is support for Ada.Task_Attributes.
51
52    type Proc_T is access procedure (T : Task_Id);
53
54    procedure Finalize_Attributes (T : Task_Id);
55    procedure Initialize_Attributes (T : Task_Id);
56
57    Finalize_Attributes_Link : Proc_T := Finalize_Attributes'Access;
58    --  should be called with abortion deferred and T.L write-locked
59
60    Initialize_Attributes_Link : Proc_T := Initialize_Attributes'Access;
61    --  should be called with abortion deferred, but holding no locks
62
63    -------------------------
64    -- Abort Defer/Undefer --
65    -------------------------
66
67    --  Defer_Abort defers the affects of low-level abort and priority change
68    --  in the calling task until a matching Undefer_Abort call is executed.
69
70    --  Undefer_Abort DOES MORE than just undo the effects of one call to
71    --  Defer_Abort.  It is the universal "polling point" for deferred
72    --  processing, including the following:
73
74    --  1) base priority changes
75
76    --  2) abort/ATC
77
78    --  Abort deferral MAY be nested (Self_ID.Deferral_Level is a count),
79    --  but to avoid waste and undetected errors, it generally SHOULD NOT
80    --  be nested.  The symptom of over-deferring abort is that an exception
81    --  may fail to be raised, or an abort may fail to take place.
82
83    --  Therefore, there are two sets of the inlinable defer/undefer
84    --  routines, which are the ones to be used inside GNARL.
85    --  One set allows nesting.  The other does not.  People who
86    --  maintain the GNARL should try to avoid using the nested versions,
87    --  or at least look very critically at the places where they are
88    --  used.
89
90    --  In general, any GNARL call that is potentially blocking, or
91    --  whose semantics require that it sometimes raise an exception,
92    --  or that is required to be an abort completion point, must be
93    --  made with abort Deferral_Level = 1.
94
95    --  In general, non-blocking GNARL calls, which may be made from inside
96    --  a protected action, are likely to need to allow nested abort
97    --  deferral.
98
99    --  With some critical exceptions (which are supposed to be documented),
100    --  internal calls to the tasking runtime system assume abort is already
101    --  deferred, and do not modify the deferral level.
102
103    --  There is also a set of non-linable defer/undefer routines,
104    --  for direct call from the compiler. These are not in-lineable
105    --  because they may need to be called via pointers ("soft links").
106    --  For the sake of efficiency, the version with Self_ID as parameter
107    --  should used wherever possible. These are all nestable.
108
109    --  Non-nestable inline versions  --
110
111    procedure Defer_Abort (Self_ID : Task_Id);
112    pragma Inline (Defer_Abort);
113
114    procedure Undefer_Abort (Self_ID : Task_Id);
115    pragma Inline (Undefer_Abort);
116
117    --  Nestable inline versions  --
118
119    procedure Defer_Abort_Nestable (Self_ID : Task_Id);
120    pragma Inline (Defer_Abort_Nestable);
121
122    procedure Undefer_Abort_Nestable (Self_ID : Task_Id);
123    pragma Inline (Undefer_Abort_Nestable);
124
125    --  NON-INLINE versions without Self_ID for code generated by the
126    --  expander and for soft links
127
128    procedure Defer_Abortion;
129    procedure Undefer_Abortion;
130
131    --  ?????
132    --  Try to phase out all uses of the above versions.
133
134    function Check_Abort_Status return Integer;
135    --  Returns Boolean'Pos (True) iff abort signal should raise
136    --  Standard.Abort_Signal. Only used by IRIX currently.
137
138    ---------------------------
139    --  Change Base Priority --
140    ---------------------------
141
142    procedure Change_Base_Priority (T : Task_Id);
143    --  Change the base priority of T.
144    --  Has to be called with the affected task's ATCB write-locked.
145    --  May temporariliy release the lock.
146
147    procedure Poll_Base_Priority_Change (Self_ID : Task_Id);
148    --  Has to be called with Self_ID's ATCB write-locked.
149    --  May temporariliy release the lock.
150    pragma Inline (Poll_Base_Priority_Change);
151
152    ----------------------
153    -- Task Lock/Unlock --
154    ----------------------
155
156    procedure Task_Lock (Self_ID : Task_Id);
157    pragma Inline (Task_Lock);
158
159    procedure Task_Unlock (Self_ID : Task_Id);
160    pragma Inline (Task_Unlock);
161    --  These are versions of Lock_Task and Unlock_Task created for use
162    --  within the GNARL.
163
164    procedure Final_Task_Unlock (Self_ID : Task_Id);
165    --  This version is only for use in Terminate_Task, when the task
166    --  is relinquishing further rights to its own ATCB.
167    --  There is a very interesting potential race condition there, where
168    --  the old task may run concurrently with a new task that is allocated
169    --  the old tasks (now reused) ATCB.  The critical thing here is to
170    --  not make any reference to the ATCB after the lock is released.
171    --  See also comments on Terminate_Task and Unlock.
172
173    procedure Wakeup_Entry_Caller
174      (Self_ID    : Task_Id;
175       Entry_Call : Entry_Call_Link;
176       New_State  : Entry_Call_State);
177    pragma Inline (Wakeup_Entry_Caller);
178    --  This is called at the end of service of an entry call,
179    --  to abort the caller if he is in an abortable part, and
180    --  to wake up the caller if he is on Entry_Caller_Sleep.
181    --  Call it holding the lock of Entry_Call.Self.
182    --
183    --  Timed_Call or Simple_Call:
184    --    The caller is waiting on Entry_Caller_Sleep, in
185    --    Wait_For_Completion, or Wait_For_Completion_With_Timeout.
186    --
187    --  Conditional_Call:
188    --    The caller might be in Wait_For_Completion,
189    --    waiting for a rendezvous (possibly requeued without abort)
190    --    to complete.
191    --
192    --  Asynchronous_Call:
193    --    The caller may be executing in the abortable part o
194    --    an async. select, or on a time delay,
195    --    if Entry_Call.State >= Was_Abortable.
196
197    procedure Locked_Abort_To_Level
198      (Self_ID : Task_Id;
199       T       : Task_Id;
200       L       : ATC_Level);
201    pragma Inline (Locked_Abort_To_Level);
202    --  Abort a task to a specified ATC level.
203    --  Call this only with T locked.
204
205 end System.Tasking.Initialization;