i386-protos.h (x86_emit_floatuns): Declare.
[official-gcc.git] / gcc / ada / 7sosprim.adb
blob6d4cf22c1f8df8f9cb49dfe2ade0e5769d9c2fdf
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. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This version is for POSIX-like operating systems
37 package body System.OS_Primitives is
39 -- ??? These definitions are duplicated from System.OS_Interface
40 -- because we don't want to depend on any package. Consider removing
41 -- these declarations in System.OS_Interface and move these ones in
42 -- the spec.
44 type struct_timezone is record
45 tz_minuteswest : Integer;
46 tz_dsttime : Integer;
47 end record;
48 pragma Convention (C, struct_timezone);
49 type struct_timezone_ptr is access all struct_timezone;
51 type time_t is new Integer;
53 type struct_timeval is record
54 tv_sec : time_t;
55 tv_usec : Integer;
56 end record;
57 pragma Convention (C, struct_timeval);
59 function gettimeofday
60 (tv : access struct_timeval;
61 tz : struct_timezone_ptr) return Integer;
62 pragma Import (C, gettimeofday, "gettimeofday");
64 type timespec is record
65 tv_sec : time_t;
66 tv_nsec : Long_Integer;
67 end record;
68 pragma Convention (C, timespec);
70 function nanosleep (rqtp, rmtp : access timespec) return Integer;
71 pragma Import (C, nanosleep, "nanosleep");
73 -----------
74 -- Clock --
75 -----------
77 function Clock return Duration is
78 TV : aliased struct_timeval;
79 Result : Integer;
81 begin
82 Result := gettimeofday (TV'Access, null);
83 return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
84 end Clock;
86 ---------------------
87 -- Monotonic_Clock --
88 ---------------------
90 function Monotonic_Clock return Duration renames Clock;
92 -----------------
93 -- To_Timespec --
94 -----------------
96 function To_Timespec (D : Duration) return timespec;
98 function To_Timespec (D : Duration) return timespec is
99 S : time_t;
100 F : Duration;
102 begin
103 S := time_t (Long_Long_Integer (D));
104 F := D - Duration (S);
106 -- If F has negative value due to a round-up, adjust for positive F
107 -- value.
109 if F < 0.0 then
110 S := S - 1;
111 F := F + 1.0;
112 end if;
114 return timespec' (tv_sec => S,
115 tv_nsec => Long_Integer (Long_Long_Integer (F * 10#1#E9)));
116 end To_Timespec;
118 -----------------
119 -- Timed_Delay --
120 -----------------
122 procedure Timed_Delay
123 (Time : Duration;
124 Mode : Integer)
126 Request : aliased timespec;
127 Remaind : aliased timespec;
128 Result : Integer;
129 Rel_Time : Duration;
130 Abs_Time : Duration;
131 Check_Time : Duration := Clock;
132 begin
133 if Mode = Relative then
134 Rel_Time := Time;
135 Abs_Time := Time + Check_Time;
136 else
137 Rel_Time := Time - Check_Time;
138 Abs_Time := Time;
139 end if;
141 if Rel_Time > 0.0 then
142 loop
143 Request := To_Timespec (Rel_Time);
144 Result := nanosleep (Request'Access, Remaind'Access);
145 Check_Time := Clock;
147 exit when Abs_Time <= Check_Time;
149 Rel_Time := Abs_Time - Check_Time;
150 end loop;
151 end if;
152 end Timed_Delay;
154 end System.OS_Primitives;