s-osinte-linux.ads (struct_timeval, [...]): Delete.

2009-11-21  Eric Botcazou  <ebotcazou@adacore.com>
            Laurent GUERBY  <laurent@guerby.net>

        * s-osinte-linux.ads (struct_timeval, To_Duration, To_Timeval,
        gettimeofday): Delete.
        * s-osinte-posix.adb (To_Duration, To_Timeval): Delete.
        * s-osprim-posix.adb (struct_timezone, struct_timeval, 
        gettimeofday): Delete.
        (Clock): Use cal.c timeval_to_duration.
        * s-taprop-linux.adb (Monotonic_Clock): Likewise.


Co-Authored-By: Laurent GUERBY <laurent@guerby.net>

From-SVN: r154407
This commit is contained in:
Eric Botcazou 2009-11-21 12:01:11 +00:00 committed by Laurent Guerby
parent e81f2ecf58
commit 435697aae7
5 changed files with 53 additions and 68 deletions

View File

@ -1,3 +1,14 @@
2009-11-21 Eric Botcazou <ebotcazou@adacore.com>
Laurent GUERBY <laurent@guerby.net>
* s-osinte-linux.ads (struct_timeval, To_Duration, To_Timeval,
gettimeofday): Delete.
* s-osinte-posix.adb (To_Duration, To_Timeval): Delete.
* s-osprim-posix.adb (struct_timezone, struct_timeval,
gettimeofday): Delete.
(Clock): Use cal.c timeval_to_duration.
* s-taprop-linux.adb (Monotonic_Clock): Likewise.
2009-11-12 Eric Botcazou <ebotcazou@adacore.com>
Laurent GUERBY <laurent@guerby.net>

View File

@ -228,19 +228,6 @@ package System.OS_Interface is
function To_Timespec (D : Duration) return timespec;
pragma Inline (To_Timespec);
type struct_timeval is private;
function To_Duration (TV : struct_timeval) return Duration;
pragma Inline (To_Duration);
function To_Timeval (D : Duration) return struct_timeval;
pragma Inline (To_Timeval);
function gettimeofday
(tv : access struct_timeval;
tz : System.Address := System.Null_Address) return int;
pragma Import (C, gettimeofday, "gettimeofday");
function sysconf (name : int) return long;
pragma Import (C, sysconf);

View File

@ -74,11 +74,6 @@ package body System.OS_Interface is
return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
end To_Duration;
function To_Duration (TV : struct_timeval) return Duration is
begin
return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
end To_Duration;
------------------------
-- To_Target_Priority --
------------------------
@ -114,30 +109,4 @@ package body System.OS_Interface is
tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
end To_Timespec;
----------------
-- To_Timeval --
----------------
function To_Timeval (D : Duration) return struct_timeval is
S : time_t;
F : Duration;
begin
S := time_t (Long_Long_Integer (D));
F := D - Duration (S);
-- If F has negative value due to a round-up, adjust for positive F
-- value.
if F < 0.0 then
S := S - 1;
F := F + 1.0;
end if;
return
struct_timeval'
(tv_sec => S,
tv_usec => time_t (Long_Long_Integer (F * 10#1#E6)));
end To_Timeval;
end System.OS_Interface;

View File

@ -38,26 +38,8 @@ package body System.OS_Primitives is
-- these declarations in System.OS_Interface and move these ones in
-- the spec.
type struct_timezone is record
tz_minuteswest : Integer;
tz_dsttime : Integer;
end record;
pragma Convention (C, struct_timezone);
type struct_timezone_ptr is access all struct_timezone;
type time_t is new Long_Integer;
type struct_timeval is record
tv_sec : time_t;
tv_usec : Long_Integer;
end record;
pragma Convention (C, struct_timeval);
function gettimeofday
(tv : not null access struct_timeval;
tz : struct_timezone_ptr) return Integer;
pragma Import (C, gettimeofday, "gettimeofday");
type timespec is record
tv_sec : time_t;
tv_nsec : Long_Integer;
@ -72,11 +54,26 @@ package body System.OS_Primitives is
-----------
function Clock return Duration is
TV : aliased struct_timeval;
type timeval is array (1 .. 2) of Long_Integer;
procedure timeval_to_duration
(T : not null access timeval;
sec : not null access Long_Integer;
usec : not null access Long_Integer);
pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");
Micro : constant := 10**6;
sec : aliased Long_Integer;
usec : aliased Long_Integer;
TV : aliased timeval;
Result : Integer;
pragma Unreferenced (Result);
function gettimeofday
(Tv : access timeval;
Tz : System.Address := System.Null_Address) return Integer;
pragma Import (C, gettimeofday, "gettimeofday");
begin
-- The return codes for gettimeofday are as follows (from man pages):
-- EPERM settimeofday is called by someone other than the superuser
@ -86,8 +83,9 @@ package body System.OS_Primitives is
-- None of these codes signal a potential clock skew, hence the return
-- value is never checked.
Result := gettimeofday (TV'Access, null);
return Duration (TV.tv_sec) + Duration (TV.tv_usec) / 10#1#E6;
Result := gettimeofday (TV'Access, System.Null_Address);
timeval_to_duration (TV'Access, sec'Access, usec'Access);
return Duration (sec) + Duration (usec) / Micro;
end Clock;
---------------------

View File

@ -589,12 +589,32 @@ package body System.Task_Primitives.Operations is
---------------------
function Monotonic_Clock return Duration is
TV : aliased struct_timeval;
Result : Interfaces.C.int;
use Interfaces;
type timeval is array (1 .. 2) of C.long;
procedure timeval_to_duration
(T : not null access timeval;
sec : not null access C.long;
usec : not null access C.long);
pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");
Micro : constant := 10**6;
sec : aliased C.long;
usec : aliased C.long;
TV : aliased timeval;
Result : int;
function gettimeofday
(Tv : access timeval;
Tz : System.Address := System.Null_Address) return int;
pragma Import (C, gettimeofday, "gettimeofday");
begin
Result := gettimeofday (TV'Access, System.Null_Address);
pragma Assert (Result = 0);
return To_Duration (TV);
timeval_to_duration (TV'Access, sec'Access, usec'Access);
return Duration (sec) + Duration (usec) / Micro;
end Monotonic_Clock;
-------------------