OSDN Git Service

2005-11-14 Cyrille Comar <comar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tasinf-irix-athread.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 --          Copyright (C) 1992-2005 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT 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.  GNAT 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 GNAT;  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 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package contains the definitions and routines associated with the
35 --  implementation and use of the Task_Info pragma. It is specialized
36 --  appropriately for targets that make use of this pragma.
37
38 --  Note: the compiler generates direct calls to this interface, via Rtsfind.
39 --  Any changes to this interface may require corresponding compiler changes.
40
41 --  This unit may be used directly from an application program by providing
42 --  an appropriate WITH, and the interface can be expected to remain stable.
43
44 --  This is the SGI (libathread) specific version of this module
45
46 with System.OS_Interface;
47
48 package System.Task_Info is
49    pragma Preelaborate;
50    pragma Elaborate_Body;
51    --  To ensure that a body is allowed
52
53    ---------------------------------------------------------
54    -- Binding of Tasks to sprocs and sprocs to processors --
55    ---------------------------------------------------------
56
57    --  The SGI implementation of the GNU Low-Level Interface (GNULLI)
58    --  implements each Ada task as a Posix thread (Pthread). The SGI
59    --  Pthread library distributes threads across one or more processes
60    --  that are members of a common share group. Irix distributes
61    --  processes across the available CPUs on a given machine. The
62    --  pragma Task_Info provides the mechanism to control the distribution
63    --  of tasks to sprocs, and sprocs to processors.
64
65    --  Each thread has a number of attributes that dictate it's scheduling.
66    --  These attributes are:
67
68    --      Bound_To_Sproc:  whether the thread is bound to a specific sproc
69    --                       for its entire lifetime.
70
71    --      Timeslice:       Amount of time that a thread is allowed to execute
72    --                       before the system yeilds control to another thread
73    --                       of equal priority.
74
75    --      Resource_Vector: A bitmask used to control the binding of threads
76    --                       to sprocs.
77    --
78
79    --  Each share group process (sproc)
80
81    --  The Task_Info pragma:
82
83    --    pragma Task_Info (EXPRESSION);
84
85    --  allows the specification on a task by task basis of a value of type
86    --  System.Task_Info.Task_Info_Type to be passed to a task when it is
87    --  created. The specification of this type, and the effect on the task
88    --  that is created is target dependent.
89
90    --  The Task_Info pragma appears within a task definition (compare the
91    --  definition and implementation of pragma Priority). If no such pragma
92    --  appears, then the value Task_Info_Unspecified is passed. If a pragma
93    --  is present, then it supplies an alternative value. If the argument of
94    --  the pragma is a discriminant reference, then the value can be set on
95    --  a task by task basis by supplying the appropriate discriminant value.
96
97    --  Note that this means that the type used for Task_Info_Type must be
98    --  suitable for use as a discriminant (i.e. a scalar or access type).
99
100    ----------------------
101    -- Resource Vectors --
102    ----------------------
103
104    --  <discussion>
105
106    type Resource_Vector_T is array (0 .. 31) of Boolean;
107    pragma Pack (Resource_Vector_T);
108
109    NO_RESOURCES : constant Resource_Vector_T := (others => False);
110
111    generic
112       type Resource_T is (<>);
113       --  Discrete type up to 32 entries
114
115    package Resource_Vector_Functions is
116       function "+"
117         (R : Resource_T) return Resource_Vector_T;
118
119       function "+"
120         (R1 : Resource_T;
121          R2 : Resource_T) return Resource_Vector_T;
122
123       function "+"
124         (R : Resource_T;
125          S : Resource_Vector_T) return Resource_Vector_T;
126
127       function "+"
128         (S : Resource_Vector_T;
129          R : Resource_T) return Resource_Vector_T;
130
131       function "+"
132         (S1 : Resource_Vector_T;
133          S2 : Resource_Vector_T) return Resource_Vector_T;
134
135       function "-"
136         (S : Resource_Vector_T;
137          R : Resource_T) 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) return sproc_t;
207    --  Allocates a sproc_t control structure and creates corresponding sproc
208
209    Invalid_CPU_Number : exception;
210    Permission_Error   : exception;
211    Sproc_Create_Error : exception;
212
213    -----------------------
214    -- Thread Attributes --
215    -----------------------
216
217    type Thread_Attributes (Bound_To_Sproc : Boolean) is record
218       Thread_Resources : Resource_Vector_T := NO_RESOURCES;
219
220       Thread_Timeslice : Duration          := 0.0;
221
222       case Bound_To_Sproc is
223          when False =>
224             null;
225          when True   =>
226             Sproc : sproc_t;
227       end case;
228    end record;
229
230    Default_Thread_Attributes : constant Thread_Attributes :=
231      (False, NO_RESOURCES, 0.0);
232
233    function Unbound_Thread_Attributes
234      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
235       Thread_Timeslice : Duration          := 0.0) return Thread_Attributes;
236
237    function Bound_Thread_Attributes
238      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
239       Thread_Timeslice : Duration          := 0.0;
240       Sproc            : sproc_t) return Thread_Attributes;
241
242    function Bound_Thread_Attributes
243      (Thread_Resources : Resource_Vector_T      := NO_RESOURCES;
244       Thread_Timeslice : Duration               := 0.0;
245       Sproc_Resources  : Resource_Vector_T      := NO_RESOURCES;
246       CPU              : CPU_Number             := ANY_CPU;
247       Resident         : Page_Locking           := NOLOCK;
248       NDPRI            : Non_Degrading_Priority := NDP_NONE)
249       return Thread_Attributes;
250
251    type Task_Info_Type is access all Thread_Attributes;
252
253    function New_Unbound_Thread_Attributes
254      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
255       Thread_Timeslice : Duration          := 0.0)
256       return Task_Info_Type;
257
258    function New_Bound_Thread_Attributes
259      (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
260       Thread_Timeslice : Duration          := 0.0;
261       Sproc            : sproc_t) return Task_Info_Type;
262
263    function New_Bound_Thread_Attributes
264      (Thread_Resources : Resource_Vector_T      := NO_RESOURCES;
265       Thread_Timeslice : Duration               := 0.0;
266       Sproc_Resources  : Resource_Vector_T      := NO_RESOURCES;
267       CPU              : CPU_Number             := ANY_CPU;
268       Resident         : Page_Locking           := NOLOCK;
269       NDPRI            : Non_Degrading_Priority := NDP_NONE)
270       return Task_Info_Type;
271
272    Unspecified_Task_Info : constant Task_Info_Type := null;
273
274 end System.Task_Info;