diff options
author | Doug Rupp <rupp@adacore.com> | 2018-05-31 10:44:56 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-31 10:44:56 +0000 |
commit | 4cfb305e9c5c3fb8f7e9afd184802265f8a0e665 (patch) | |
tree | f03511652865c5959605982cfcce944f74752ad1 /gcc | |
parent | ade649b2bfd24a1adcc28d96fa4b81878efe1c0b (diff) | |
download | gcc-4cfb305e9c5c3fb8f7e9afd184802265f8a0e665.zip gcc-4cfb305e9c5c3fb8f7e9afd184802265f8a0e665.tar.gz gcc-4cfb305e9c5c3fb8f7e9afd184802265f8a0e665.tar.bz2 |
[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 <rupp@adacore.com>
gcc/ada/
* libgnat/s-osprim__posix2008.adb (Clock): Implement using
clock_gettime.
From-SVN: r260995
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/libgnat/s-osprim__posix2008.adb | 50 |
2 files changed, 21 insertions, 34 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index acf2c17..bee06e3 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-05-31 Doug Rupp <rupp@adacore.com> + + * libgnat/s-osprim__posix2008.adb (Clock): Implement using + clock_gettime. + 2018-05-31 Ed Schonberg <schonberg@adacore.com> * 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 2e717a9..ae791c2 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; ----------------- |