FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / 5vosprim.adb
blobd06eca3f09e5f2c555a6aa43ae1a76cb6c76c65f
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 is the OpenVMS/Alpha version of this file
37 with System.Aux_DEC;
39 package body System.OS_Primitives is
41 --------------------------------------
42 -- Local functions and declarations --
43 --------------------------------------
45 function Get_GMToff return Integer;
46 pragma Import (C, Get_GMToff, "get_gmtoff");
47 -- Get the offset from GMT for this timezone
49 VMS_Epoch_Offset : constant Long_Integer :=
50 10_000_000 *
51 (3_506_716_800 + Long_Integer (Get_GMToff));
52 -- The offset between the Unix Epoch and the VMS Epoch
54 subtype Cond_Value_Type is System.Aux_DEC.Unsigned_Longword;
55 -- Condition Value return type
57 ----------------
58 -- Sys_Schdwk --
59 ----------------
61 -- Schedule Wakeup
63 -- status = returned status
64 -- pidadr = address of process id to be woken up
65 -- prcnam = name of process to be woken up
66 -- daytim = time to wake up
67 -- reptim = repitition interval of wakeup calls
70 procedure Sys_Schdwk
72 Status : out Cond_Value_Type;
73 Pidadr : in Address := Null_Address;
74 Prcnam : in String := String'Null_Parameter;
75 Daytim : in Long_Integer;
76 Reptim : in Long_Integer := Long_Integer'Null_Parameter
79 pragma Interface (External, Sys_Schdwk);
80 -- VMS system call to schedule a wakeup event
81 pragma Import_Valued_Procedure
82 (Sys_Schdwk, "SYS$SCHDWK",
83 (Cond_Value_Type, Address, String, Long_Integer, Long_Integer),
84 (Value, Value, Descriptor (S), Reference, Reference)
87 ----------------
88 -- Sys_Gettim --
89 ----------------
91 -- Get System Time
93 -- status = returned status
94 -- tim = current system time
97 procedure Sys_Gettim
99 Status : out Cond_Value_Type;
100 Tim : out OS_Time
102 -- VMS system call to get the current system time
103 pragma Interface (External, Sys_Gettim);
104 pragma Import_Valued_Procedure
105 (Sys_Gettim, "SYS$GETTIM",
106 (Cond_Value_Type, OS_Time),
107 (Value, Reference)
110 ---------------
111 -- Sys_Hiber --
112 ---------------
114 -- Hibernate (until woken up)
116 -- status = returned status
119 procedure Sys_Hiber (Status : out Cond_Value_Type);
120 -- VMS system call to hibernate the current process
121 pragma Interface (External, Sys_Hiber);
122 pragma Import_Valued_Procedure
123 (Sys_Hiber, "SYS$HIBER",
124 (Cond_Value_Type),
125 (Value)
128 -----------
129 -- Clock --
130 -----------
132 function OS_Clock return OS_Time is
133 Status : Cond_Value_Type;
134 T : OS_Time;
135 begin
136 Sys_Gettim (Status, T);
137 return (T);
138 end OS_Clock;
140 -----------
141 -- Clock --
142 -----------
144 function Clock return Duration is
145 begin
146 return To_Duration (OS_Clock, Absolute_Calendar);
147 end Clock;
149 ---------------------
150 -- Monotonic_Clock --
151 ---------------------
153 function Monotonic_Clock return Duration renames Clock;
155 -----------------
156 -- Timed_Delay --
157 -----------------
159 procedure Timed_Delay
160 (Time : Duration;
161 Mode : Integer)
163 Sleep_Time : OS_Time;
164 Status : Cond_Value_Type;
166 begin
167 Sleep_Time := To_OS_Time (Time, Mode);
168 Sys_Schdwk (Status => Status, Daytim => Sleep_Time);
169 Sys_Hiber (Status);
170 end Timed_Delay;
172 -----------------
173 -- To_Duration --
174 -----------------
176 function To_Duration (T : OS_Time; Mode : Integer) return Duration is
177 begin
178 return Duration'Fixed_Value (T - VMS_Epoch_Offset) * 100;
179 end To_Duration;
181 ----------------
182 -- To_OS_Time --
183 ----------------
185 function To_OS_Time (D : Duration; Mode : Integer) return OS_Time is
186 begin
187 if Mode = Relative then
188 return -(Long_Integer'Integer_Value (D) / 100);
189 else
190 return Long_Integer'Integer_Value (D) / 100 + VMS_Epoch_Offset;
191 end if;
192 end To_OS_Time;
194 end System.OS_Primitives;