OSDN Git Service

* ifcvt.c (noce_get_alt_condition): Use reg_overlap_mentioned_p.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5posprim.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
4 --                                                                          --
5 --                  S Y S T E M . O S _ P R I M I T I V E S                 --
6 --                                                                          --
7 --                                  B o d y                                 --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1998-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNARL 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. GNARL 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 GNARL; 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 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com).                                  --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 --  This version uses gettimeofday and select
37 --  Currently OpenNT, Dec Unix, Solaris and SCO UnixWare use this file.
38
39 package body System.OS_Primitives is
40
41    --  ??? These definitions are duplicated from System.OS_Interface
42    --  because we don't want to depend on any package. Consider removing
43    --  these declarations in System.OS_Interface and move these ones in
44    --  the spec.
45
46    type struct_timezone is record
47       tz_minuteswest  : Integer;
48       tz_dsttime   : Integer;
49    end record;
50    pragma Convention (C, struct_timezone);
51    type struct_timezone_ptr is access all struct_timezone;
52
53    type struct_timeval is record
54       tv_sec       : Integer;
55       tv_usec      : Integer;
56    end record;
57    pragma Convention (C, struct_timeval);
58
59    function gettimeofday
60      (tv : access struct_timeval;
61       tz : struct_timezone_ptr) return Integer;
62    pragma Import (C, gettimeofday, "gettimeofday");
63
64    type fd_set is null record;
65    type fd_set_ptr is access all fd_set;
66
67    function C_select
68      (n         : Integer    := 0;
69       readfds,
70       writefds,
71       exceptfds : fd_set_ptr := null;
72       timeout   : access struct_timeval) return Integer;
73    pragma Import (C, C_select, "select");
74
75    -----------
76    -- Clock --
77    -----------
78
79    function Clock return Duration is
80       TV     : aliased struct_timeval;
81       Result : Integer;
82
83    begin
84       Result := gettimeofday (TV'Access, null);
85       return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
86    end Clock;
87
88    ---------------------
89    -- Monotonic_Clock --
90    ---------------------
91
92    function Monotonic_Clock return Duration renames Clock;
93
94    -----------------
95    -- Timed_Delay --
96    -----------------
97
98    procedure Timed_Delay
99      (Time : Duration;
100       Mode : Integer)
101    is
102       Result     : Integer;
103       Rel_Time   : Duration;
104       Abs_Time   : Duration;
105       Check_Time : Duration := Clock;
106       timeval    : aliased struct_timeval;
107
108    begin
109       if Mode = Relative then
110          Rel_Time := Time;
111          Abs_Time := Time + Check_Time;
112       else
113          Rel_Time := Time - Check_Time;
114          Abs_Time := Time;
115       end if;
116
117       if Rel_Time > 0.0 then
118          loop
119             timeval.tv_sec := Integer (Rel_Time);
120
121             if Duration (timeval.tv_sec) > Rel_Time then
122                timeval.tv_sec := timeval.tv_sec - 1;
123             end if;
124
125             timeval.tv_usec :=
126               Integer ((Rel_Time - Duration (timeval.tv_sec)) * 10#1#E6);
127
128             Result := C_select (timeout => timeval'Unchecked_Access);
129             Check_Time := Clock;
130
131             exit when Abs_Time <= Check_Time;
132
133             Rel_Time := Abs_Time - Check_Time;
134          end loop;
135       end if;
136    end Timed_Delay;
137
138 end System.OS_Primitives;