1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . O S _ P R I M I T I V E S --
9 -- Copyright (C) 1998-2017, Free Software Foundation, Inc. --
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 3, or (at your option) any later ver- --
14 -- sion. GNAT 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This version uses gettimeofday and select
33 -- This file is suitable for OpenNT, Dec Unix and SCO UnixWare.
35 package body System
.OS_Primitives
is
37 -- ??? These definitions are duplicated from System.OS_Interface
38 -- because we don't want to depend on any package. Consider removing
39 -- these declarations in System.OS_Interface and move these ones in
42 type struct_timeval
is record
46 pragma Convention
(C
, struct_timeval
);
48 procedure gettimeofday
49 (tv
: not null access struct_timeval
;
50 tz
: Address
:= Null_Address
);
51 pragma Import
(C
, gettimeofday
, "gettimeofday");
57 exceptfds
: Address
:= Null_Address
;
58 timeout
: not null access struct_timeval
);
59 pragma Import
(C
, C_select
, "select");
65 function Clock
return Duration is
66 TV
: aliased struct_timeval
;
69 gettimeofday
(TV
'Access);
70 return Duration (TV
.tv_sec
) + Duration (TV
.tv_usec
) / 10#
1#E6
;
83 Base_Time
: constant Duration := Clock
;
84 Check_Time
: Duration := Base_Time
;
85 timeval
: aliased struct_timeval
;
88 if Mode
= Relative
then
90 Abs_Time
:= Time
+ Check_Time
;
92 Rel_Time
:= Time
- Check_Time
;
96 if Rel_Time
> 0.0 then
98 timeval
.tv_sec
:= Integer (Rel_Time
);
100 if Duration (timeval
.tv_sec
) > Rel_Time
then
101 timeval
.tv_sec
:= timeval
.tv_sec
- 1;
105 Integer ((Rel_Time
- Duration (timeval
.tv_sec
)) * 10#
1#E6
);
107 C_select
(timeout
=> timeval
'Unchecked_Access);
110 exit when Abs_Time
<= Check_Time
or else Check_Time
< Base_Time
;
112 Rel_Time
:= Abs_Time
- Check_Time
;
121 procedure Initialize
is
126 end System
.OS_Primitives
;