OSDN Git Service

2006-06-07 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-proinf-irix-athread.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                 S Y S T E M . P R O G R A M  _  I N F O                  --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1997-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 is an Irix (old pthread library) version of this package.
35
36 --  This package   contains the parameters  used by   the run-time system at
37 --  program startup.  These parameters are  isolated in this package body to
38 --  facilitate replacement by the end user.
39 --
40 --  To replace the default values, copy this source file into your build
41 --  directory, edit the file to reflect your desired behavior, and recompile
42 --  with the command:
43 --
44 --     % gcc -c -O2 -gnatpg s-proinf.adb
45 --
46 --  then relink your application as usual.
47 --
48
49 pragma Warnings (Off);
50 with GNAT.OS_Lib;
51 pragma Warnings (On);
52
53 package body System.Program_Info is
54
55    Kbytes : constant := 1024;
56
57    Default_Initial_Sproc_Count  : constant := 0;
58    Default_Max_Sproc_Count      : constant := 128;
59    Default_Sproc_Stack_Size     : constant := 16#4000#;
60    Default_Stack_Guard_Pages    : constant := 1;
61    Default_Default_Time_Slice   : constant := 0.0;
62    Default_Default_Task_Stack   : constant := 12 * Kbytes;
63    Default_Pthread_Sched_Signal : constant := 35;
64    Default_Pthread_Arena_Size   : constant := 16#40000#;
65    Default_Os_Default_Priority  : constant := 0;
66
67    -------------------------
68    -- Initial_Sproc_Count --
69    -------------------------
70
71    function Initial_Sproc_Count return Integer is
72
73       function sysmp (P1 : Integer) return Integer;
74       pragma Import (C, sysmp, "sysmp", "sysmp");
75
76       MP_NPROCS : constant := 1; --   # processor in complex
77
78       Pthread_Sproc_Count : constant GNAT.OS_Lib.String_Access :=
79         GNAT.OS_Lib.Getenv ("PTHREAD_SPROC_COUNT");
80
81    begin
82       if Pthread_Sproc_Count.all'Length = 0 then
83          return Default_Initial_Sproc_Count;
84
85       elsif Pthread_Sproc_Count.all = "AUTO" then
86          return sysmp (MP_NPROCS);
87
88       else
89          return Integer'Value (Pthread_Sproc_Count.all);
90       end if;
91    exception
92       when others =>
93          return Default_Initial_Sproc_Count;
94    end Initial_Sproc_Count;
95
96    ---------------------
97    -- Max_Sproc_Count --
98    ---------------------
99
100    function Max_Sproc_Count return Integer is
101       Pthread_Max_Sproc_Count : constant GNAT.OS_Lib.String_Access :=
102         GNAT.OS_Lib.Getenv ("PTHREAD_MAX_SPROC_COUNT");
103
104    begin
105       if Pthread_Max_Sproc_Count.all'Length = 0 then
106          return Default_Max_Sproc_Count;
107       else
108          return Integer'Value (Pthread_Max_Sproc_Count.all);
109       end if;
110    exception
111       when others =>
112          return Default_Max_Sproc_Count;
113    end Max_Sproc_Count;
114
115    ----------------------
116    -- Sproc_Stack_Size --
117    ----------------------
118
119    function Sproc_Stack_Size return Integer is
120    begin
121       return Default_Sproc_Stack_Size;
122    end Sproc_Stack_Size;
123
124    ------------------------
125    -- Default_Time_Slice --
126    ------------------------
127
128    function Default_Time_Slice return Duration is
129       Pthread_Time_Slice_Sec : constant GNAT.OS_Lib.String_Access :=
130         GNAT.OS_Lib.Getenv ("PTHREAD_TIME_SLICE_SEC");
131       Pthread_Time_Slice_Usec : constant GNAT.OS_Lib.String_Access :=
132         GNAT.OS_Lib.Getenv ("PTHREAD_TIME_SLICE_USEC");
133
134       Val_Sec, Val_Usec : Integer := 0;
135
136    begin
137       if Pthread_Time_Slice_Sec.all'Length /= 0 or
138         Pthread_Time_Slice_Usec.all'Length /= 0
139       then
140          if Pthread_Time_Slice_Sec.all'Length /= 0 then
141             Val_Sec := Integer'Value (Pthread_Time_Slice_Sec.all);
142          end if;
143
144          if Pthread_Time_Slice_Usec.all'Length /= 0 then
145             Val_Usec := Integer'Value (Pthread_Time_Slice_Usec.all);
146          end if;
147
148          return Duration (Val_Sec) + Duration (Val_Usec) / 1000.0;
149       else
150          return Default_Default_Time_Slice;
151       end if;
152
153    exception
154       when others =>
155          return Default_Default_Time_Slice;
156    end Default_Time_Slice;
157
158    ------------------------
159    -- Default_Task_Stack --
160    ------------------------
161
162    function Default_Task_Stack return Integer is
163    begin
164       return Default_Default_Task_Stack;
165    end Default_Task_Stack;
166
167    -----------------------
168    -- Stack_Guard_Pages --
169    -----------------------
170
171    function Stack_Guard_Pages return Integer is
172       Pthread_Stack_Guard_Pages : constant GNAT.OS_Lib.String_Access :=
173         GNAT.OS_Lib.Getenv ("PTHREAD_STACK_GUARD_PAGES");
174
175    begin
176       if Pthread_Stack_Guard_Pages.all'Length /= 0 then
177          return Integer'Value (Pthread_Stack_Guard_Pages.all);
178       else
179          return Default_Stack_Guard_Pages;
180       end if;
181    exception
182       when others =>
183          return Default_Stack_Guard_Pages;
184    end Stack_Guard_Pages;
185
186    --------------------------
187    -- Pthread_Sched_Signal --
188    --------------------------
189
190    function Pthread_Sched_Signal return Integer is
191    begin
192       return Default_Pthread_Sched_Signal;
193    end Pthread_Sched_Signal;
194
195    ------------------------
196    -- Pthread_Arena_Size --
197    ------------------------
198
199    function Pthread_Arena_Size  return Integer is
200       Pthread_Arena_Size : constant GNAT.OS_Lib.String_Access :=
201         GNAT.OS_Lib.Getenv ("PTHREAD_ARENA_SIZE");
202
203    begin
204       if Pthread_Arena_Size.all'Length = 0 then
205          return Default_Pthread_Arena_Size;
206       else
207          return Integer'Value (Pthread_Arena_Size.all);
208       end if;
209    exception
210       when others =>
211          return Default_Pthread_Arena_Size;
212    end Pthread_Arena_Size;
213
214    -------------------------
215    -- Os_Default_Priority --
216    -------------------------
217
218    function Os_Default_Priority return Integer is
219    begin
220       return Default_Os_Default_Priority;
221    end Os_Default_Priority;
222
223 end System.Program_Info;