* config/xtensa/lib2funcs.S: Fix whitespace.
[official-gcc.git] / gcc / ada / 5posprim.adb
blob1dfb37110cec0c646dda2cb8dd762995f3f9eed7
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 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
10 -- --
11 -- GNARL 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. GNARL 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 GNARL; 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 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This version uses gettimeofday and select
35 -- Currently OpenNT, Dec Unix, Solaris and SCO UnixWare use this file.
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 struct_timeval is record
52 tv_sec : Integer;
53 tv_usec : Integer;
54 end record;
55 pragma Convention (C, struct_timeval);
57 function gettimeofday
58 (tv : access struct_timeval;
59 tz : struct_timezone_ptr) return Integer;
60 pragma Import (C, gettimeofday, "gettimeofday");
62 type fd_set is null record;
63 type fd_set_ptr is access all fd_set;
65 function C_select
66 (n : Integer := 0;
67 readfds,
68 writefds,
69 exceptfds : fd_set_ptr := null;
70 timeout : access struct_timeval) return Integer;
71 pragma Import (C, C_select, "select");
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 -- Timed_Delay --
94 -----------------
96 procedure Timed_Delay
97 (Time : Duration;
98 Mode : Integer)
100 Result : Integer;
101 Rel_Time : Duration;
102 Abs_Time : Duration;
103 Check_Time : Duration := Clock;
104 timeval : aliased struct_timeval;
106 begin
107 if Mode = Relative then
108 Rel_Time := Time;
109 Abs_Time := Time + Check_Time;
110 else
111 Rel_Time := Time - Check_Time;
112 Abs_Time := Time;
113 end if;
115 if Rel_Time > 0.0 then
116 loop
117 timeval.tv_sec := Integer (Rel_Time);
119 if Duration (timeval.tv_sec) > Rel_Time then
120 timeval.tv_sec := timeval.tv_sec - 1;
121 end if;
123 timeval.tv_usec :=
124 Integer ((Rel_Time - Duration (timeval.tv_sec)) * 10#1#E6);
126 Result := C_select (timeout => timeval'Unchecked_Access);
127 Check_Time := Clock;
129 exit when Abs_Time <= Check_Time;
131 Rel_Time := Abs_Time - Check_Time;
132 end loop;
133 end if;
134 end Timed_Delay;
136 end System.OS_Primitives;