OSDN Git Service

PR c++/9704
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5gtasinf.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                     S Y S T E M . T A S K _ I N F O                      --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT 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.  GNAT 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 GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
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.                                      --
29 --                                                                          --
30 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This package contains the definitions and routines associated with the
36 --  implementation of the Task_Info pragma.
37
38 --  This is the SGI (libathread) specific version of this module.
39
40 with System.OS_Interface;
41 with Unchecked_Deallocation;
42
43 package System.Task_Info is
44 pragma Elaborate_Body;
45 --  To ensure that a body is allowed
46
47    ---------------------------------------------------------
48    -- Binding of Tasks to sprocs and sprocs to processors --
49    ---------------------------------------------------------
50
51    --  The SGI implementation of the GNU Low-Level Interface (GNULLI)
52    --  implements each Ada task as a Posix thread (Pthread). The SGI
53    --  Pthread library distributes threads across one or more processes
54    --  that are members of a common share group. Irix distributes
55    --  processes across the available CPUs on a given machine. The
56    --  pragma Task_Info provides the mechanism to control the distribution
57    --  of tasks to sprocs, and sprocs to processors.
58
59    --  Each thread has a number of attributes that dictate it's scheduling.
60    --  These attributes are:
61    --
62    --      Bound_To_Sproc:  whether the thread is bound to a specific sproc
63    --                       for its entire lifetime.
64    --
65    --      Timeslice:       Amount of time that a thread is allowed to execute
66    --                       before the system yeilds control to another thread
67    --                       of equal priority.
68    --
69    --      Resource_Vector: A bitmask used to control the binding of threads
70    --                       to sprocs.
71    --
72
73    --  Each share group process (sproc)
74
75    --  The Task_Info pragma:
76
77    --    pragma Task_Info (EXPRESSION);
78
79    --  allows the specification on a task by task basis of a value of type
80    --  System.Task_Info.Task_Info_Type to be passed to a task when it is
81    --  created. The specification of this type, and the effect on the task
82    --  that is created is target dependent.
83
84    --  The Task_Info pragma appears within a task definition (compare the
85    --  definition and implementation of pragma Priority). If no such pragma
86    --  appears, then the value Task_Info_Unspecified is passed. If a pragma
87    --  is present, then it supplies an alternative value. If the argument of
88    --  the pragma is a discriminant reference, then the value can be set on
89    --  a task by task basis by supplying the appropriate discriminant value.
90
91    --  Note that this means that the type used for Task_Info_Type must be
92    --  suitable for use as a discriminant (i.e. a scalar or access type).
93
94    ----------------------
95    -- Resource Vectors --
96    ----------------------
97
98    --  <discussion>
99
100    type Resource_Vector_T is array (0 .. 31) of Boolean;
101    pragma Pack (Resource_Vector_T);
102
103    NO_RESOURCES : constant Resource_Vector_T := (others => False);
104
105    generic
106       type Resource_T is (<>);
107       --  Discrete type up to 32 entries
108
109    package Resource_Vector_Functions is
110       function "+"
111         (R    : Resource_T)
112          return Resource_Vector_T;
113
114       function "+"
115         (R1   : Resource_T;
116          R2   : Resource_T)
117          return Resource_Vector_T;
118
119       function "+"
120         (R    : Resource_T;
121          S    : Resource_Vector_T)
122          return Resource_Vector_T;
123
124       function "+"
125         (S    : Resource_Vector_T;
126          R    : Resource_T)
127          return Resource_Vector_T;
128
129       function "+"
130         (S1   : Resource_Vector_T;
131          S2   : Resource_Vector_T)
132          return Resource_Vector_T;
133
134       function "-"
135         (S    : Resource_Vector_T;
136          R    : Resource_T)
137          return Resource_Vector_T;
138    end Resource_Vector_Functions;
139
140    ----------------------
141    -- Sproc Attributes --
142    ----------------------
143
144    subtype sproc_t is System.OS_Interface.sproc_t;
145
146    subtype CPU_Number is Integer range -1 .. Integer'Last;
147
148    ANY_CPU : constant CPU_Number := CPU_Number'First;
149
150    type Non_Degrading_Priority is range 0 .. 255;
151    --  Specification of IRIX Non Degrading Priorities.
152    --
153    --  WARNING: IRIX priorities have the reverse meaning of Ada priorities.
154    --           The lower the priority value, the greater the greater the
155    --           scheduling preference.
156    --
157    --  See the schedctl(2) man page for a complete discussion of non-degrading
158    --  priorities.
159
160    NDPHIMAX : constant Non_Degrading_Priority := 30;
161    NDPHIMIN : constant Non_Degrading_Priority := 39;
162    --  These priorities are higher than ALL normal user process priorities
163
164    subtype NDP_High is Non_Degrading_Priority range NDPHIMAX .. NDPHIMIN;
165
166    NDPNORMMAX : constant Non_Degrading_Priority := 40;
167    NDPNORMMIN : constant Non_Degrading_Priority := 127;
168    --  These priorities overlap normal user process priorities
169
170    subtype NDP_Norm is Non_Degrading_Priority range NDPNORMMAX .. NDPNORMMIN;
171
172    NDPLOMAX : constant Non_Degrading_Priority := 128;
173    NDPLOMIN : constant Non_Degrading_Priority := 254;
174    --  These priorities are below ALL normal user process priorities
175
176    NDP_NONE   : constant Non_Degrading_Priority := 255;
177
178    subtype NDP_LOW is Non_Degrading_Priority range NDPLOMAX .. NDPLOMIN;
179
180    type Page_Locking is
181       (NOLOCK,     --  Do not lock pages in memory
182        PROCLOCK,   --  Lock text and data segments into memory (process lock)
183        TXTLOCK,    --  Lock text segment into memory (text lock)
184        DATLOCK     --  Lock data segment into memory (data lock)
185       );
186
187    type Sproc_Attributes is record
188       Sproc_Resources : Resource_Vector_T      := NO_RESOURCES;
189       CPU             : CPU_Number             := ANY_CPU;
190       Resident        : Page_Locking           := NOLOCK;
191       NDPRI           : Non_Degrading_Priority := NDP_NONE;
192 --  ??? why is that commented out, should it be removed ?
193 --       Sproc_Slice     : Duration               := 0.0;
194 --       Deadline_Period : Duration               := 0.0;
195 --       Deadline_Alloc  : Duration               := 0.0;
196    end record;
197
198    Default_Sproc_Attributes : constant Sproc_Attributes :=
199       (NO_RESOURCES, ANY_CPU, NOLOCK, NDP_NONE);
200
201    function New_Sproc (Attr : Sproc_Attributes) return sproc_t;
202    function New_Sproc
203      (Sproc_Resources : Resource_Vector_T      := NO_RESOURCES;
204       CPU             : CPU_Number             := ANY_CPU;
205       Resident        : Page_Locking           := NOLOCK;
206       NDPRI           : Non_Degrading_Priority := NDP_NONE)
207       return            sproc_t;
208    --  Allocates a sproc_t control structure and creates the
209    --  corresponding sproc.
210
211    Invalid_CPU_Number : exception;
212    Permission_Error   : exception;
213    Sproc_Create_Error : exception;
214
215    -----------------------
216    -- Thread Attributes --
217    -----------------------
218
219    type Thread_Attributes (Bound_To_Sproc : Boolean) is record
220       Thread_Resources : Resource_Vector_T := NO_RESOURCES;
221
222       Thread_Timeslice : Duration          := 0.0;
223
224       case Bound_To_Sproc is
225          when False =>
226             null;
227          when True   =>
228             Sproc : sproc_t;
229       end case;
230    end record;
231
232    Default_Thread_Attributes : constant Thread_Attributes :=
233      (False, NO_RESOURCES, 0.0);
234
235    function Unbound_Thread_Attributes
236      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
237       Thread_Timeslice : Duration          := 0.0)
238       return             Thread_Attributes;
239
240    function Bound_Thread_Attributes
241      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
242       Thread_Timeslice : Duration          := 0.0;
243       Sproc            : sproc_t)
244       return             Thread_Attributes;
245
246    function Bound_Thread_Attributes
247      (Thread_Resources : Resource_Vector_T      := NO_RESOURCES;
248       Thread_Timeslice : Duration               := 0.0;
249       Sproc_Resources  : Resource_Vector_T      := NO_RESOURCES;
250       CPU              : CPU_Number             := ANY_CPU;
251       Resident         : Page_Locking           := NOLOCK;
252       NDPRI            : Non_Degrading_Priority := NDP_NONE)
253       return             Thread_Attributes;
254
255    type Task_Info_Type is access all Thread_Attributes;
256
257    function New_Unbound_Thread_Attributes
258      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
259       Thread_Timeslice : Duration          := 0.0)
260       return             Task_Info_Type;
261
262    function New_Bound_Thread_Attributes
263      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
264       Thread_Timeslice : Duration          := 0.0;
265       Sproc            : sproc_t)
266       return             Task_Info_Type;
267
268    function New_Bound_Thread_Attributes
269      (Thread_Resources : Resource_Vector_T      := NO_RESOURCES;
270       Thread_Timeslice : Duration               := 0.0;
271       Sproc_Resources  : Resource_Vector_T      := NO_RESOURCES;
272       CPU              : CPU_Number             := ANY_CPU;
273       Resident         : Page_Locking           := NOLOCK;
274       NDPRI            : Non_Degrading_Priority := NDP_NONE)
275       return             Task_Info_Type;
276
277    type Task_Image_Type is access String;
278    --  Used to generate a meaningful identifier for tasks that are variables
279    --  and components of variables.
280
281    procedure Free_Task_Image is new
282      Unchecked_Deallocation (String, Task_Image_Type);
283
284    Unspecified_Task_Info : constant Task_Info_Type := null;
285
286 end System.Task_Info;