* emit-rtl.c (widen_memory_access): New.
[official-gcc.git] / gcc / ada / 5oosprim.adb
blob0531bdec522aec5b23e79fba42b6e5973824821e
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 -- $Revision: 1.7 $
10 -- --
11 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
34 -- --
35 ------------------------------------------------------------------------------
37 -- This is the OS/2 version of this package
39 with Interfaces.C; use Interfaces.C;
40 with Interfaces.OS2Lib; use Interfaces.OS2Lib;
41 with Interfaces.OS2Lib.Synchronization; use Interfaces.OS2Lib.Synchronization;
43 package body System.OS_Primitives is
45 ----------------
46 -- Local Data --
47 ----------------
49 Epoch_Offset : Duration; -- See Set_Epoch_Offset
50 Max_Tick_Count : QWORD := 0.0;
51 -- This is needed to compensate for small glitches in the
52 -- hardware clock or the way it is read by the OS
54 -----------------------
55 -- Local Subprograms --
56 -----------------------
58 procedure Set_Epoch_Offset;
59 -- Initializes the Epoch_1970_Offset to the offset of the System_Clock
60 -- relative to the Unix epoch (Jan 1, 1970), such that
61 -- Clock = System_Clock + Epoch_1970_Offset
63 function System_Clock return Duration;
64 pragma Inline (System_Clock);
65 -- Function returning value of system clock with system-dependent timebase.
66 -- For OS/2 the system clock returns the elapsed time since system boot.
67 -- The clock resolution is approximately 838 ns.
69 ------------------
70 -- System_Clock --
71 ------------------
73 function System_Clock return Duration is
75 -- Implement conversion from tick count to Duration
76 -- using fixed point arithmetic. The frequency of
77 -- the Intel 8254 timer chip is 18.2 * 2**16 Hz.
79 Tick_Duration : constant := 1.0 / (18.2 * 2**16);
80 Tick_Count : aliased QWORD;
82 begin
83 Must_Not_Fail (DosTmrQueryTime (Tick_Count'Access));
84 -- Read nr of clock ticks since boot time
86 Max_Tick_Count := QWORD'Max (Tick_Count, Max_Tick_Count);
88 return Max_Tick_Count * Tick_Duration;
89 end System_Clock;
91 -----------
92 -- Clock --
93 -----------
95 function Clock return Duration is
96 begin
97 return System_Clock + Epoch_Offset;
98 end Clock;
100 ---------------------
101 -- Monotonic_Clock --
102 ---------------------
104 function Monotonic_Clock return Duration renames Clock;
106 ----------------------
107 -- Set_Epoch_Offset --
108 ----------------------
110 procedure Set_Epoch_Offset is
112 -- Interface to Unix C style gettimeofday
114 type timeval is record
115 tv_sec : long;
116 tv_usec : long;
117 end record;
119 procedure gettimeofday
120 (time : access timeval;
121 zone : System.Address := System.Address'Null_Parameter);
122 pragma Import (C, gettimeofday);
124 Time_Of_Day : aliased timeval;
125 Micro_To_Nano : constant := 1.0E3;
126 Sec_To_Nano : constant := 1.0E9;
127 Nanos_Since_Epoch : QWORD;
129 begin
130 gettimeofday (Time_Of_Day'Access);
131 Nanos_Since_Epoch := QWORD (Time_Of_Day.tv_sec) * Sec_To_Nano
132 + QWORD (Time_Of_Day.tv_usec) * Micro_To_Nano;
134 Epoch_Offset :=
135 Duration'(Nanos_Since_Epoch / Sec_To_Nano) - System_Clock;
137 end Set_Epoch_Offset;
139 -----------------
140 -- Timed_Delay --
141 -----------------
143 procedure Timed_Delay
144 (Time : Duration;
145 Mode : Integer)
147 Rel_Time : Duration;
148 Abs_Time : Duration;
149 Check_Time : Duration := Clock;
151 begin
152 if Mode = Relative then
153 Rel_Time := Time;
154 Abs_Time := Time + Check_Time;
155 else
156 Rel_Time := Time - Check_Time;
157 Abs_Time := Time;
158 end if;
160 if Rel_Time > 0.0 then
161 loop
162 Must_Not_Fail (DosSleep (ULONG (Rel_Time * 1000.0)));
164 Check_Time := Clock;
166 exit when Abs_Time <= Check_Time;
168 Rel_Time := Abs_Time - Check_Time;
169 end loop;
170 end if;
171 end Timed_Delay;
173 begin
174 Set_Epoch_Offset;
175 end System.OS_Primitives;