OSDN Git Service

2004-09-17 Jeffrey D. Oldham <oldham@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osprim-vms.adb
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-2002 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 ------------------------------------------------------------------------------
33
34 --  This is the OpenVMS/Alpha version of this file
35
36 with System.Aux_DEC;
37
38 package body System.OS_Primitives is
39
40    --------------------------------------
41    -- Local functions and declarations --
42    --------------------------------------
43
44    function Get_GMToff return Integer;
45    pragma Import (C, Get_GMToff, "get_gmtoff");
46    --  Get the offset from GMT for this timezone
47
48    VMS_Epoch_Offset : constant Long_Integer :=
49                         10_000_000 *
50                           (3_506_716_800 + Long_Integer (Get_GMToff));
51    --  The offset between the Unix Epoch and the VMS Epoch
52
53    subtype Cond_Value_Type is System.Aux_DEC.Unsigned_Longword;
54    --  Condition Value return type
55
56    ----------------
57    -- Sys_Schdwk --
58    ----------------
59    --
60    --  Schedule Wakeup
61    --
62    --  status = returned status
63    --  pidadr = address of process id to be woken up
64    --  prcnam = name of process to be woken up
65    --  daytim = time to wake up
66    --  reptim = repitition interval of wakeup calls
67    --
68
69    procedure Sys_Schdwk
70      (
71       Status : out Cond_Value_Type;
72       Pidadr : in Address := Null_Address;
73       Prcnam : in String := String'Null_Parameter;
74       Daytim : in Long_Integer;
75       Reptim : in Long_Integer := Long_Integer'Null_Parameter
76      );
77
78    pragma Interface (External, Sys_Schdwk);
79    --  VMS system call to schedule a wakeup event
80    pragma Import_Valued_Procedure
81      (Sys_Schdwk, "SYS$SCHDWK",
82       (Cond_Value_Type, Address, String,         Long_Integer, Long_Integer),
83       (Value,           Value,   Descriptor (S), Reference,    Reference)
84      );
85
86    ----------------
87    -- Sys_Gettim --
88    ----------------
89    --
90    --  Get System Time
91    --
92    --  status = returned status
93    --  tim    = current system time
94    --
95
96    procedure Sys_Gettim
97      (
98       Status : out Cond_Value_Type;
99       Tim    : out OS_Time
100      );
101    --  VMS system call to get the current system time
102    pragma Interface (External, Sys_Gettim);
103    pragma Import_Valued_Procedure
104      (Sys_Gettim, "SYS$GETTIM",
105       (Cond_Value_Type, OS_Time),
106       (Value,           Reference)
107      );
108
109    ---------------
110    -- Sys_Hiber --
111    ---------------
112
113    --  Hibernate (until woken up)
114
115    --  status = returned status
116
117    procedure Sys_Hiber (Status : out Cond_Value_Type);
118    --  VMS system call to hibernate the current process
119    pragma Interface (External, Sys_Hiber);
120    pragma Import_Valued_Procedure
121      (Sys_Hiber, "SYS$HIBER",
122       (Cond_Value_Type),
123       (Value)
124      );
125
126    -----------
127    -- Clock --
128    -----------
129
130    function OS_Clock return OS_Time is
131       Status : Cond_Value_Type;
132       T      : OS_Time;
133    begin
134       Sys_Gettim (Status, T);
135       return (T);
136    end OS_Clock;
137
138    -----------
139    -- Clock --
140    -----------
141
142    function Clock return Duration is
143    begin
144       return To_Duration (OS_Clock, Absolute_Calendar);
145    end Clock;
146
147    ---------------------
148    -- Monotonic_Clock --
149    ---------------------
150
151    function Monotonic_Clock return Duration renames Clock;
152
153    -----------------
154    -- Timed_Delay --
155    -----------------
156
157    procedure Timed_Delay
158      (Time : Duration;
159       Mode : Integer)
160    is
161       Sleep_Time : OS_Time;
162       Status     : Cond_Value_Type;
163
164    begin
165       Sleep_Time := To_OS_Time (Time, Mode);
166       Sys_Schdwk (Status => Status, Daytim => Sleep_Time);
167       Sys_Hiber (Status);
168    end Timed_Delay;
169
170    -----------------
171    -- To_Duration --
172    -----------------
173
174    function To_Duration (T : OS_Time; Mode : Integer) return Duration is
175       pragma Warnings (Off, Mode);
176    begin
177       return Duration'Fixed_Value (T - VMS_Epoch_Offset) * 100;
178    end To_Duration;
179
180    ----------------
181    -- To_OS_Time --
182    ----------------
183
184    function To_OS_Time (D : Duration; Mode : Integer) return OS_Time is
185    begin
186       if Mode = Relative then
187          return -(Long_Integer'Integer_Value (D) / 100);
188       else
189          return Long_Integer'Integer_Value (D) / 100 + VMS_Epoch_Offset;
190       end if;
191    end To_OS_Time;
192
193 end System.OS_Primitives;