From: Doug Rupp Date: Thu, 31 May 2018 10:44:56 +0000 (+0000) Subject: [Ada] Posix 2008: reimplement System.OS_Primitives.Clock using clock_gettime X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4cfb305e9c5c3fb8f7e9afd184802265f8a0e665;p=gcc.git [Ada] Posix 2008: reimplement System.OS_Primitives.Clock using clock_gettime gettimeofday is deprecated in Posix 2008, clock_gettime is the recommended replacement. 2018-05-31 Doug Rupp gcc/ada/ * libgnat/s-osprim__posix2008.adb (Clock): Implement using clock_gettime. From-SVN: r260995 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index acf2c17bf8c..bee06e3e791 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-05-31 Doug Rupp + + * libgnat/s-osprim__posix2008.adb (Clock): Implement using + clock_gettime. + 2018-05-31 Ed Schonberg * exp_unst.ads, exp_unst.adb (In_Synchronized_Unit): New predicate to diff --git a/gcc/ada/libgnat/s-osprim__posix2008.adb b/gcc/ada/libgnat/s-osprim__posix2008.adb index 2e717a912a0..ae791c20488 100644 --- a/gcc/ada/libgnat/s-osprim__posix2008.adb +++ b/gcc/ada/libgnat/s-osprim__posix2008.adb @@ -32,8 +32,11 @@ -- This version is for POSIX.1-2008-like operating systems with System.CRTL; +with System.OS_Constants; package body System.OS_Primitives is + subtype int is System.CRTL.int; + -- ??? These definitions are duplicated from System.OS_Interface because -- we don't want to depend on any package. Consider removing these -- declarations in System.OS_Interface and move these ones to the spec. @@ -54,43 +57,22 @@ package body System.OS_Primitives is ----------- function Clock return Duration is + TS : aliased timespec; + Result : int; - type timeval is array (1 .. 3) of Long_Integer; - -- The timeval array is sized to contain Long_Long_Integer sec and - -- Long_Integer usec. If Long_Long_Integer'Size = Long_Integer'Size then - -- it will be overly large but that will not effect the implementation - -- since it is not accessed directly. - - procedure timeval_to_duration - (T : not null access timeval; - sec : not null access Long_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_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 - -- EINVAL Timezone (or something else) is invalid - -- EFAULT One of tv or tz pointed outside accessible address space + type clockid_t is new int; + CLOCK_REALTIME : constant clockid_t := + System.OS_Constants.CLOCK_REALTIME; - -- None of these codes signal a potential clock skew, hence the return - -- value is never checked. + function clock_gettime + (clock_id : clockid_t; + tp : access timespec) return int; + pragma Import (C, clock_gettime, "clock_gettime"); - Result := gettimeofday (TV'Access, System.Null_Address); - timeval_to_duration (TV'Access, sec'Access, usec'Access); - return Duration (sec) + Duration (usec) / Micro; + begin + Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access); + pragma Assert (Result = 0); + return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9; end Clock; -----------------