OSDN Git Service

41dbc218fb29830f64e78bf9d1301a38b9583735
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tasini.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNAT 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-2005, 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, 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. Call this function with RTS_Lock taken
41
42    ---------------------------------
43    -- Tasking-Specific Soft Links --
44    ---------------------------------
45
46    --  These permit us to leave out certain portions of the tasking
47    --  run-time system if they are not used.  They are only used internally
48    --  by the tasking run-time system.
49
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 abort deferred and T.L write-locked
59
60    Initialize_Attributes_Link : Proc_T := Initialize_Attributes'Access;
61    --  should be called with abort 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), but
79    --  to avoid waste and undetected errors, it generally SHOULD NOT be
80    --  nested. The symptom of over-deferring abort is that an exception may
81    --  fail to be raised, or an abort may fail to take place.
82
83    --  Therefore, there are two sets of the inlinable defer/undefer routines,
84    --  which are the ones to be used inside GNARL. One set allows nesting. The
85    --  other does not. People who maintain the GNARL should try to avoid using
86    --  the nested versions, or at least look very critically at the places
87    --  where they are used.
88
89    --  In general, any GNARL call that is potentially blocking, or whose
90    --  semantics require that it sometimes raise an exception, or that is
91    --  required to be an abort completion point, must be made with abort
92    --  Deferral_Level = 1.
93
94    --  In general, non-blocking GNARL calls, which may be made from inside a
95    --  protected action, are likely to need to allow nested abort deferral.
96
97    --  With some critical exceptions (which are supposed to be documented),
98    --  internal calls to the tasking runtime system assume abort is already
99    --  deferred, and do not modify the deferral level.
100
101    --  There is also a set of non-linable defer/undefer routines, for direct
102    --  call from the compiler. These are not in-lineable because they may need
103    --  to be called via pointers ("soft links"). For the sake of efficiency,
104    --  the version with Self_ID as parameter should used wherever possible.
105    --  These are all nestable.
106
107    --  Non-nestable inline versions
108
109    procedure Defer_Abort (Self_ID : Task_Id);
110    pragma Inline (Defer_Abort);
111
112    procedure Undefer_Abort (Self_ID : Task_Id);
113    pragma Inline (Undefer_Abort);
114
115    --  Nestable inline versions
116
117    procedure Defer_Abort_Nestable (Self_ID : Task_Id);
118    pragma Inline (Defer_Abort_Nestable);
119
120    procedure Undefer_Abort_Nestable (Self_ID : Task_Id);
121    pragma Inline (Undefer_Abort_Nestable);
122
123    procedure Do_Pending_Action (Self_ID : Task_Id);
124    --  Only call with no locks, and when Self_ID.Pending_Action = True Perform
125    --  necessary pending actions (e.g. abort, priority change). This procedure
126    --  is usually called when needed as a result of calling Undefer_Abort,
127    --  although in the case of e.g. No_Abort restriction, it can be necessary
128    --  to force execution of pending actions.
129
130    function Check_Abort_Status return Integer;
131    --  Returns Boolean'Pos (True) iff abort signal should raise
132    --  Standard.Abort_Signal. Only used by IRIX currently.
133
134    --------------------------
135    -- Change Base Priority --
136    --------------------------
137
138    procedure Change_Base_Priority (T : Task_Id);
139    --  Change the base priority of T. Has to be called with the affected
140    --  task's ATCB write-locked. May temporariliy release the lock.
141
142    ----------------------
143    -- Task Lock/Unlock --
144    ----------------------
145
146    procedure Task_Lock (Self_ID : Task_Id);
147    pragma Inline (Task_Lock);
148
149    procedure Task_Unlock (Self_ID : Task_Id);
150    pragma Inline (Task_Unlock);
151    --  These are versions of Lock_Task and Unlock_Task created for use
152    --  within the GNARL.
153
154    procedure Final_Task_Unlock (Self_ID : Task_Id);
155    --  This version is only for use in Terminate_Task, when the task is
156    --  relinquishing further rights to its own ATCB. There is a very
157    --  interesting potential race condition there, where the old task may run
158    --  concurrently with a new task that is allocated the old tasks (now
159    --  reused) ATCB. The critical thing here is to not make any reference to
160    --  the ATCB after the lock is released. See also comments on
161    --  Terminate_Task and Unlock.
162
163    procedure Wakeup_Entry_Caller
164      (Self_ID    : Task_Id;
165       Entry_Call : Entry_Call_Link;
166       New_State  : Entry_Call_State);
167    pragma Inline (Wakeup_Entry_Caller);
168    --  This is called at the end of service of an entry call, to abort the
169    --  caller if he is in an abortable part, and to wake up the caller if he
170    --  is on Entry_Caller_Sleep. Call it holding the lock of Entry_Call.Self.
171    --
172    --  Timed_Call or Simple_Call:
173    --    The caller is waiting on Entry_Caller_Sleep, in Wait_For_Completion,
174    --    or Wait_For_Completion_With_Timeout.
175    --
176    --  Conditional_Call:
177    --    The caller might be in Wait_For_Completion,
178    --    waiting for a rendezvous (possibly requeued without abort) to
179    --    complete.
180    --
181    --  Asynchronous_Call:
182    --    The caller may be executing in the abortable part an async. select,
183    --    or on a time delay, if Entry_Call.State >= Was_Abortable.
184
185    procedure Locked_Abort_To_Level
186      (Self_ID : Task_Id;
187       T       : Task_Id;
188       L       : ATC_Level);
189    pragma Inline (Locked_Abort_To_Level);
190    --  Abort a task to a specified ATC level. Call this only with T locked
191
192 end System.Tasking.Initialization;