1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . T A S K _ I N F O --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package body contains the routines associated with the implementation
35 -- of the Task_Info pragma.
37 -- This is the SGI specific version of this module.
40 with System.OS_Interface;
42 with Unchecked_Conversion;
44 package body System.Task_Info is
46 use System.OS_Interface;
47 use type Interfaces.C.int;
49 function To_Resource_T is new
50 Unchecked_Conversion (Resource_Vector_T, resource_t);
52 MP_NPROCS : constant := 1;
54 function Sysmp (Cmd : Integer) return Integer;
55 pragma Import (C, Sysmp);
57 function Num_Processors (Cmd : Integer := MP_NPROCS) return Integer
60 function Geteuid return Integer;
61 pragma Import (C, Geteuid);
63 Locking_Map : constant array (Page_Locking) of Interfaces.C.int :=
69 -------------------------------
70 -- Resource_Vector_Functions --
71 -------------------------------
73 package body Resource_Vector_Functions is
79 function "+" (R : Resource_T) return Resource_Vector_T is
80 Result : Resource_Vector_T := NO_RESOURCES;
83 Result (Resource_T'Pos (R)) := True;
87 function "+" (R1, R2 : Resource_T) return Resource_Vector_T is
88 Result : Resource_Vector_T := NO_RESOURCES;
91 Result (Resource_T'Pos (R1)) := True;
92 Result (Resource_T'Pos (R2)) := True;
98 S : Resource_Vector_T)
99 return Resource_Vector_T
101 Result : Resource_Vector_T := S;
104 Result (Resource_T'Pos (R)) := True;
109 (S : Resource_Vector_T;
111 return Resource_Vector_T
113 Result : Resource_Vector_T := S;
116 Result (Resource_T'Pos (R)) := True;
120 function "+" (S1, S2 : Resource_Vector_T) return Resource_Vector_T is
121 Result : Resource_Vector_T;
129 (S : Resource_Vector_T;
131 return Resource_Vector_T
133 Result : Resource_Vector_T := S;
136 Result (Resource_T'Pos (R)) := False;
140 end Resource_Vector_Functions;
146 function New_Sproc (Attr : Sproc_Attributes) return sproc_t is
147 Sproc_Attr : aliased sproc_attr_t;
148 Sproc : aliased sproc_t;
152 Status := sproc_attr_init (Sproc_Attr'Unrestricted_Access);
155 Status := sproc_attr_setresources
156 (Sproc_Attr'Unrestricted_Access,
157 To_Resource_T (Attr.Sproc_Resources));
159 if Attr.CPU /= ANY_CPU then
160 if Attr.CPU > Num_Processors then
161 raise Invalid_CPU_Number;
164 Status := sproc_attr_setcpu
165 (Sproc_Attr'Unrestricted_Access,
169 if Attr.Resident /= NOLOCK then
171 raise Permission_Error;
174 Status := sproc_attr_setresident
175 (Sproc_Attr'Unrestricted_Access,
176 Locking_Map (Attr.Resident));
179 if Attr.NDPRI /= NDP_NONE then
180 -- ??? why is that comment out, should it be removed ?
181 -- if Geteuid /= 0 then
182 -- raise Permission_Error;
185 Status := sproc_attr_setprio
186 (Sproc_Attr'Unrestricted_Access,
190 Status := sproc_create
191 (Sproc'Unrestricted_Access,
192 Sproc_Attr'Unrestricted_Access,
194 System.Null_Address);
197 Status := sproc_attr_destroy (Sproc_Attr'Unrestricted_Access);
198 raise Sproc_Create_Error;
201 Status := sproc_attr_destroy (Sproc_Attr'Unrestricted_Access);
206 raise Sproc_Create_Error;
217 (Sproc_Resources : Resource_Vector_T := NO_RESOURCES;
218 CPU : CPU_Number := ANY_CPU;
219 Resident : Page_Locking := NOLOCK;
220 NDPRI : Non_Degrading_Priority := NDP_NONE)
223 Attr : Sproc_Attributes :=
224 (Sproc_Resources, CPU, Resident, NDPRI);
227 return New_Sproc (Attr);
230 -------------------------------
231 -- Unbound_Thread_Attributes --
232 -------------------------------
234 function Unbound_Thread_Attributes
235 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
236 Thread_Timeslice : Duration := 0.0)
237 return Thread_Attributes
240 return (False, Thread_Resources, Thread_Timeslice);
241 end Unbound_Thread_Attributes;
243 -----------------------------
244 -- Bound_Thread_Attributes --
245 -----------------------------
247 function Bound_Thread_Attributes
248 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
249 Thread_Timeslice : Duration := 0.0;
251 return Thread_Attributes
254 return (True, Thread_Resources, Thread_Timeslice, Sproc);
255 end Bound_Thread_Attributes;
257 -----------------------------
258 -- Bound_Thread_Attributes --
259 -----------------------------
261 function Bound_Thread_Attributes
262 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
263 Thread_Timeslice : Duration := 0.0;
264 Sproc_Resources : Resource_Vector_T := NO_RESOURCES;
265 CPU : CPU_Number := ANY_CPU;
266 Resident : Page_Locking := NOLOCK;
267 NDPRI : Non_Degrading_Priority := NDP_NONE)
268 return Thread_Attributes
270 Sproc : sproc_t := New_Sproc
271 (Sproc_Resources, CPU, Resident, NDPRI);
274 return (True, Thread_Resources, Thread_Timeslice, Sproc);
275 end Bound_Thread_Attributes;
277 -----------------------------------
278 -- New_Unbound_Thread_Attributes --
279 -----------------------------------
281 function New_Unbound_Thread_Attributes
282 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
283 Thread_Timeslice : Duration := 0.0)
284 return Task_Info_Type
287 return new Thread_Attributes'
288 (False, Thread_Resources, Thread_Timeslice);
289 end New_Unbound_Thread_Attributes;
291 ---------------------------------
292 -- New_Bound_Thread_Attributes --
293 ---------------------------------
295 function New_Bound_Thread_Attributes
296 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
297 Thread_Timeslice : Duration := 0.0;
299 return Task_Info_Type
302 return new Thread_Attributes'
303 (True, Thread_Resources, Thread_Timeslice, Sproc);
304 end New_Bound_Thread_Attributes;
306 ---------------------------------
307 -- New_Bound_Thread_Attributes --
308 ---------------------------------
310 function New_Bound_Thread_Attributes
311 (Thread_Resources : Resource_Vector_T := NO_RESOURCES;
312 Thread_Timeslice : Duration := 0.0;
313 Sproc_Resources : Resource_Vector_T := NO_RESOURCES;
314 CPU : CPU_Number := ANY_CPU;
315 Resident : Page_Locking := NOLOCK;
316 NDPRI : Non_Degrading_Priority := NDP_NONE)
317 return Task_Info_Type
319 Sproc : sproc_t := New_Sproc
320 (Sproc_Resources, CPU, Resident, NDPRI);
323 return new Thread_Attributes'
324 (True, Thread_Resources, Thread_Timeslice, Sproc);
325 end New_Bound_Thread_Attributes;
327 end System.Task_Info;