diff gcc/ada/libgnat/s-osprim__posix2008.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line diff
--- a/gcc/ada/libgnat/s-osprim__posix2008.adb	Fri Oct 27 22:46:09 2017 +0900
+++ b/gcc/ada/libgnat/s-osprim__posix2008.adb	Thu Oct 25 07:37:49 2018 +0900
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                  B o d y                                 --
 --                                                                          --
---          Copyright (C) 1998-2017, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2018, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNARL is free software; you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -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 @@
    -----------
 
    function Clock return Duration is
-
-      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.
+      TS     : aliased timespec;
+      Result : int;
 
-      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");
+      type clockid_t is new int;
+      CLOCK_REALTIME : constant clockid_t :=
+         System.OS_Constants.CLOCK_REALTIME;
 
-      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");
+      function clock_gettime
+        (clock_id : clockid_t;
+         tp       : access timespec) return int;
+      pragma Import (C, clock_gettime, "clock_gettime");
 
    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
-
-      --  None of these codes signal a potential clock skew, hence the return
-      --  value is never checked.
-
-      Result := gettimeofday (TV'Access, System.Null_Address);
-      timeval_to_duration (TV'Access, sec'Access, usec'Access);
-      return Duration (sec) + Duration (usec) / Micro;
+      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;
 
    -----------------
@@ -127,38 +109,7 @@
    procedure Timed_Delay
      (Time : Duration;
       Mode : Integer)
-   is
-      Request    : aliased timespec;
-      Remaind    : aliased timespec;
-      Rel_Time   : Duration;
-      Abs_Time   : Duration;
-      Base_Time  : constant Duration := Clock;
-      Check_Time : Duration := Base_Time;
-
-      Result : Integer;
-      pragma Unreferenced (Result);
-
-   begin
-      if Mode = Relative then
-         Rel_Time := Time;
-         Abs_Time := Time + Check_Time;
-      else
-         Rel_Time := Time - Check_Time;
-         Abs_Time := Time;
-      end if;
-
-      if Rel_Time > 0.0 then
-         loop
-            Request := To_Timespec (Rel_Time);
-            Result := nanosleep (Request'Access, Remaind'Access);
-            Check_Time := Clock;
-
-            exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
-
-            Rel_Time := Abs_Time - Check_Time;
-         end loop;
-      end if;
-   end Timed_Delay;
+   is separate;
 
    ----------------
    -- Initialize --