1 ------------------------------------------------------------------------------
3 -- GNU ADA 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-2003 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 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. --
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. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This version uses gettimeofday and select
35 -- This file is suitable for Solaris (32 and 64 bits).
37 package body System
.OS_Primitives
is
39 -- ??? These definitions are duplicated from System.OS_Interface
40 -- because we don't want to depend on any package. Consider removing
41 -- these declarations in System.OS_Interface and move these ones in
44 type struct_timeval
is record
45 tv_sec
: Long_Integer;
46 tv_usec
: Long_Integer;
48 pragma Convention
(C
, struct_timeval
);
50 procedure gettimeofday
51 (tv
: access struct_timeval
;
52 tz
: Address
:= Null_Address
);
53 pragma Import
(C
, gettimeofday
, "gettimeofday");
59 exceptfds
: Address
:= Null_Address
;
60 timeout
: access struct_timeval
);
61 pragma Import
(C
, C_select
, "select");
67 function Clock
return Duration is
68 TV
: aliased struct_timeval
;
71 gettimeofday
(TV
'Access);
72 return Duration (TV
.tv_sec
) + Duration (TV
.tv_usec
) / 10#
1#E6
;
79 function Monotonic_Clock
return Duration renames Clock
;
91 Check_Time
: Duration := Clock
;
92 timeval
: aliased struct_timeval
;
95 if Mode
= Relative
then
97 Abs_Time
:= Time
+ Check_Time
;
99 Rel_Time
:= Time
- Check_Time
;
103 if Rel_Time
> 0.0 then
105 timeval
.tv_sec
:= Long_Integer (Rel_Time
);
107 if Duration (timeval
.tv_sec
) > Rel_Time
then
108 timeval
.tv_sec
:= timeval
.tv_sec
- 1;
112 Long_Integer ((Rel_Time
- Duration (timeval
.tv_sec
)) * 10#
1#E6
);
114 C_select
(timeout
=> timeval
'Unchecked_Access);
117 exit when Abs_Time
<= Check_Time
;
119 Rel_Time
:= Abs_Time
- Check_Time
;
124 end System
.OS_Primitives
;