Update concepts branch to revision 131834
[official-gcc.git] / gcc / ada / s-osprim-vms.adb
blob93138414571f7fb71a0d6e5a53241e82d6e82bec
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 is the OpenVMS/Alpha version of this file
36 with System.Aux_DEC;
38 package body System.OS_Primitives is
40 --------------------------------------
41 -- Local functions and declarations --
42 --------------------------------------
44 function Get_GMToff return Integer;
45 pragma Import (C, Get_GMToff, "get_gmtoff");
46 -- Get the offset from GMT for this timezone
48 function VMS_Epoch_Offset return Long_Integer;
49 pragma Inline (VMS_Epoch_Offset);
50 -- The offset between the Unix Epoch and the VMS Epoch
52 subtype Cond_Value_Type is System.Aux_DEC.Unsigned_Longword;
53 -- Condition Value return type
55 ----------------------
56 -- VMS_Epoch_Offset --
57 ----------------------
59 function VMS_Epoch_Offset return Long_Integer is
60 begin
61 return 10_000_000 * (3_506_716_800 + Long_Integer (Get_GMToff));
62 end VMS_Epoch_Offset;
64 ----------------
65 -- Sys_Schdwk --
66 ----------------
68 -- Schedule Wakeup
70 -- status = returned status
71 -- pidadr = address of process id to be woken up
72 -- prcnam = name of process to be woken up
73 -- daytim = time to wake up
74 -- reptim = repetition interval of wakeup calls
77 procedure Sys_Schdwk
79 Status : out Cond_Value_Type;
80 Pidadr : Address := Null_Address;
81 Prcnam : String := String'Null_Parameter;
82 Daytim : Long_Integer;
83 Reptim : Long_Integer := Long_Integer'Null_Parameter
86 pragma Interface (External, Sys_Schdwk);
87 -- VMS system call to schedule a wakeup event
88 pragma Import_Valued_Procedure
89 (Sys_Schdwk, "SYS$SCHDWK",
90 (Cond_Value_Type, Address, String, Long_Integer, Long_Integer),
91 (Value, Value, Descriptor (S), Reference, Reference)
94 ----------------
95 -- Sys_Gettim --
96 ----------------
98 -- Get System Time
100 -- status = returned status
101 -- tim = current system time
104 procedure Sys_Gettim
106 Status : out Cond_Value_Type;
107 Tim : out OS_Time
109 -- VMS system call to get the current system time
110 pragma Interface (External, Sys_Gettim);
111 pragma Import_Valued_Procedure
112 (Sys_Gettim, "SYS$GETTIM",
113 (Cond_Value_Type, OS_Time),
114 (Value, Reference)
117 ---------------
118 -- Sys_Hiber --
119 ---------------
121 -- Hibernate (until woken up)
123 -- status = returned status
125 procedure Sys_Hiber (Status : out Cond_Value_Type);
126 -- VMS system call to hibernate the current process
127 pragma Interface (External, Sys_Hiber);
128 pragma Import_Valued_Procedure
129 (Sys_Hiber, "SYS$HIBER",
130 (Cond_Value_Type),
131 (Value)
134 -----------
135 -- Clock --
136 -----------
138 function OS_Clock return OS_Time is
139 Status : Cond_Value_Type;
140 T : OS_Time;
141 begin
142 Sys_Gettim (Status, T);
143 return (T);
144 end OS_Clock;
146 -----------
147 -- Clock --
148 -----------
150 function Clock return Duration is
151 begin
152 return To_Duration (OS_Clock, Absolute_Calendar);
153 end Clock;
155 ----------------
156 -- Initialize --
157 ----------------
159 procedure Initialize is
160 begin
161 null;
162 end Initialize;
164 ---------------------
165 -- Monotonic_Clock --
166 ---------------------
168 function Monotonic_Clock return Duration renames Clock;
170 -----------------
171 -- Timed_Delay --
172 -----------------
174 procedure Timed_Delay
175 (Time : Duration;
176 Mode : Integer)
178 Sleep_Time : OS_Time;
179 Status : Cond_Value_Type;
180 pragma Unreferenced (Status);
182 begin
183 Sleep_Time := To_OS_Time (Time, Mode);
184 Sys_Schdwk (Status => Status, Daytim => Sleep_Time);
185 Sys_Hiber (Status);
186 end Timed_Delay;
188 -----------------
189 -- To_Duration --
190 -----------------
192 function To_Duration (T : OS_Time; Mode : Integer) return Duration is
193 pragma Warnings (Off, Mode);
194 begin
195 return Duration'Fixed_Value (T - VMS_Epoch_Offset) * 100;
196 end To_Duration;
198 ----------------
199 -- To_OS_Time --
200 ----------------
202 function To_OS_Time (D : Duration; Mode : Integer) return OS_Time is
203 begin
204 if Mode = Relative then
205 return -(Long_Integer'Integer_Value (D) / 100);
206 else
207 return Long_Integer'Integer_Value (D) / 100 + VMS_Epoch_Offset;
208 end if;
209 end To_OS_Time;
211 end System.OS_Primitives;