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-2009, 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 Solaris (32 and 64 bits).
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
43 tv_sec
: Long_Integer;
44 tv_usec
: Long_Integer;
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
;
77 function Monotonic_Clock
return Duration renames Clock
;
89 Base_Time
: constant Duration := Clock
;
90 Check_Time
: Duration := Base_Time
;
91 timeval
: aliased struct_timeval
;
94 if Mode
= Relative
then
96 Abs_Time
:= Time
+ Check_Time
;
98 Rel_Time
:= Time
- Check_Time
;
102 if Rel_Time
> 0.0 then
104 timeval
.tv_sec
:= Long_Integer (Rel_Time
);
106 if Duration (timeval
.tv_sec
) > Rel_Time
then
107 timeval
.tv_sec
:= timeval
.tv_sec
- 1;
111 Long_Integer ((Rel_Time
- Duration (timeval
.tv_sec
)) * 10#
1#E6
);
113 C_select
(timeout
=> timeval
'Unchecked_Access);
116 exit when Abs_Time
<= Check_Time
or else Check_Time
< Base_Time
;
118 Rel_Time
:= Abs_Time
- Check_Time
;
127 procedure Initialize
is
132 end System
.OS_Primitives
;