OSDN Git Service

2004-05-17 Steve Kargl <kargls@comcast.net>
[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-1999 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 with GNAT.OS_Lib;
50
51 package body System.Program_Info is
52
53    Kbytes : constant := 1024;
54
55    Default_Initial_Sproc_Count  : constant := 0;
56    Default_Max_Sproc_Count      : constant := 128;
57    Default_Sproc_Stack_Size     : constant := 16#4000#;
58    Default_Stack_Guard_Pages    : constant := 1;
59    Default_Default_Time_Slice   : constant := 0.0;
60    Default_Default_Task_Stack   : constant := 12 * Kbytes;
61    Default_Pthread_Sched_Signal : constant := 35;
62    Default_Pthread_Arena_Size   : constant := 16#40000#;
63    Default_Os_Default_Priority  : constant := 0;
64
65    -------------------------
66    -- Initial_Sproc_Count --
67    -------------------------
68
69    function Initial_Sproc_Count return Integer is
70
71       function sysmp (P1 : Integer) return Integer;
72       pragma Import (C, sysmp, "sysmp", "sysmp");
73
74       MP_NPROCS : constant := 1; --   # processor in complex
75
76       Pthread_Sproc_Count : constant GNAT.OS_Lib.String_Access :=
77         GNAT.OS_Lib.Getenv ("PTHREAD_SPROC_COUNT");
78
79    begin
80       if Pthread_Sproc_Count.all'Length = 0 then
81          return Default_Initial_Sproc_Count;
82
83       elsif Pthread_Sproc_Count.all = "AUTO" then
84          return sysmp (MP_NPROCS);
85
86       else
87          return Integer'Value (Pthread_Sproc_Count.all);
88       end if;
89    exception
90       when others =>
91          return Default_Initial_Sproc_Count;
92    end Initial_Sproc_Count;
93
94    ---------------------
95    -- Max_Sproc_Count --
96    ---------------------
97
98    function Max_Sproc_Count return Integer is
99       Pthread_Max_Sproc_Count : constant GNAT.OS_Lib.String_Access :=
100         GNAT.OS_Lib.Getenv ("PTHREAD_MAX_SPROC_COUNT");
101
102    begin
103       if Pthread_Max_Sproc_Count.all'Length = 0 then
104          return Default_Max_Sproc_Count;
105       else
106          return Integer'Value (Pthread_Max_Sproc_Count.all);
107       end if;
108    exception
109       when others =>
110          return Default_Max_Sproc_Count;
111    end Max_Sproc_Count;
112
113    ----------------------
114    -- Sproc_Stack_Size --
115    ----------------------
116
117    function Sproc_Stack_Size return Integer is
118    begin
119       return Default_Sproc_Stack_Size;
120    end Sproc_Stack_Size;
121
122    ------------------------
123    -- Default_Time_Slice --
124    ------------------------
125
126    function Default_Time_Slice return Duration is
127       Pthread_Time_Slice_Sec : constant GNAT.OS_Lib.String_Access :=
128         GNAT.OS_Lib.Getenv ("PTHREAD_TIME_SLICE_SEC");
129       Pthread_Time_Slice_Usec : constant GNAT.OS_Lib.String_Access :=
130         GNAT.OS_Lib.Getenv ("PTHREAD_TIME_SLICE_USEC");
131
132       Val_Sec, Val_Usec : Integer := 0;
133
134    begin
135       if Pthread_Time_Slice_Sec.all'Length /= 0 or
136         Pthread_Time_Slice_Usec.all'Length /= 0
137       then
138          if Pthread_Time_Slice_Sec.all'Length /= 0 then
139             Val_Sec := Integer'Value (Pthread_Time_Slice_Sec.all);
140          end if;
141
142          if Pthread_Time_Slice_Usec.all'Length /= 0 then
143             Val_Usec := Integer'Value (Pthread_Time_Slice_Usec.all);
144          end if;
145
146          return Duration (Val_Sec) + Duration (Val_Usec) / 1000.0;
147       else
148          return Default_Default_Time_Slice;
149       end if;
150
151    exception
152       when others =>
153          return Default_Default_Time_Slice;
154    end Default_Time_Slice;
155
156    ------------------------
157    -- Default_Task_Stack --
158    ------------------------
159
160    function Default_Task_Stack return Integer is
161    begin
162       return Default_Default_Task_Stack;
163    end Default_Task_Stack;
164
165    -----------------------
166    -- Stack_Guard_Pages --
167    -----------------------
168
169    function Stack_Guard_Pages return Integer is
170       Pthread_Stack_Guard_Pages : constant GNAT.OS_Lib.String_Access :=
171         GNAT.OS_Lib.Getenv ("PTHREAD_STACK_GUARD_PAGES");
172
173    begin
174       if Pthread_Stack_Guard_Pages.all'Length /= 0 then
175          return Integer'Value (Pthread_Stack_Guard_Pages.all);
176       else
177          return Default_Stack_Guard_Pages;
178       end if;
179    exception
180       when others =>
181          return Default_Stack_Guard_Pages;
182    end Stack_Guard_Pages;
183
184    --------------------------
185    -- Pthread_Sched_Signal --
186    --------------------------
187
188    function Pthread_Sched_Signal return Integer is
189    begin
190       return Default_Pthread_Sched_Signal;
191    end Pthread_Sched_Signal;
192
193    ------------------------
194    -- Pthread_Arena_Size --
195    ------------------------
196
197    function Pthread_Arena_Size  return Integer is
198       Pthread_Arena_Size : constant GNAT.OS_Lib.String_Access :=
199         GNAT.OS_Lib.Getenv ("PTHREAD_ARENA_SIZE");
200
201    begin
202       if Pthread_Arena_Size.all'Length = 0 then
203          return Default_Pthread_Arena_Size;
204       else
205          return Integer'Value (Pthread_Arena_Size.all);
206       end if;
207    exception
208       when others =>
209          return Default_Pthread_Arena_Size;
210    end Pthread_Arena_Size;
211
212    -------------------------
213    -- Os_Default_Priority --
214    -------------------------
215
216    function Os_Default_Priority return Integer is
217    begin
218       return Default_Os_Default_Priority;
219    end Os_Default_Priority;
220
221 end System.Program_Info;