This change removes incorrect obsolete code for CLOCK_MONOTONIC support
on AIX, and fixes a wrong mapping of the clockid_t type on that target.

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-10-13  Thomas Quinot  <qui...@adacore.com>

        * s-oscons-tmplt.c (CLOCK_RT_Ada): Set to CLOCK_MONOTONIC when
        building on AIX 5.3 or later, and to CLOCK_REALTIME on older
        versions of AIX.
        * init.c (pthread_condattr_setclock): Remove now useless weak symbol.
        * thread.c(__gnat_pthread_condattr_setup): Remove bogus AIX 5.2
        compatibility shim.
        * s-osinte-aix.ads(clock_id_t): Fix C mapping (this is a 64-bit
        type).
        (clock_gettime): Import from C runtime library.
        * s-osinte-aix.adb (clock_gettime): Remove bogus emulation body,
        this routine is provided by the system in current supported
        versions of AIX.

Index: s-osinte-aix.adb
===================================================================
--- s-osinte-aix.adb    (revision 203500)
+++ s-osinte-aix.adb    (working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                  B o d y                                 --
 --                                                                          --
---          Copyright (C) 1997-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1997-2013, 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- --
@@ -99,48 +99,6 @@
                        tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
    end To_Timespec;
 
-   -------------------
-   -- clock_gettime --
-   -------------------
-
-   function clock_gettime
-     (clock_id : clockid_t;
-      tp       : access timespec)
-      return     int
-   is
-      pragma Unreferenced (clock_id);
-
-      --  Older AIX don't have clock_gettime, so use gettimeofday
-
-      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);
-      timeval_to_duration (TV'Access, sec'Access, usec'Access);
-      tp.all := To_Timespec (Duration (sec) + Duration (usec) / Micro);
-      return Result;
-   end clock_gettime;
-
    -----------------
    -- sched_yield --
    -----------------
Index: s-osinte-aix.ads
===================================================================
--- s-osinte-aix.ads    (revision 203500)
+++ s-osinte-aix.ads    (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT 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- --
@@ -41,6 +41,7 @@
 with Ada.Unchecked_Conversion;
 
 with Interfaces.C;
+with Interfaces.C.Extensions;
 
 package System.OS_Interface is
    pragma Preelaborate;
@@ -55,6 +56,7 @@
    subtype int            is Interfaces.C.int;
    subtype short          is Interfaces.C.short;
    subtype long           is Interfaces.C.long;
+   subtype long_long      is Interfaces.C.Extensions.long_long;
    subtype unsigned       is Interfaces.C.unsigned;
    subtype unsigned_short is Interfaces.C.unsigned_short;
    subtype unsigned_long  is Interfaces.C.unsigned_long;
@@ -197,11 +199,12 @@
 
    type timespec is private;
 
-   type clockid_t is new int;
+   type clockid_t is new long_long;
 
    function clock_gettime
      (clock_id : clockid_t;
       tp       : access timespec) return int;
+   pragma Import (C, clock_gettime, "clock_gettime");
 
    function To_Duration (TS : timespec) return Duration;
    pragma Inline (To_Duration);
Index: thread.c
===================================================================
--- thread.c    (revision 203500)
+++ thread.c    (working copy)
@@ -40,27 +40,8 @@
 # include <pthread.h>
 # include <time.h>
 
-#ifndef _AIXVERSION_530
-/* We use the same runtime library for AIX 5.2 and 5.3, but pthread_condattr_
- * setclock exists only on the latter, so for the former provide a dummy
- * implementation (declared below, weak symbol defined in init.c).
- *
- * Note: this means that under AIX 5.2 we'll be using CLOCK_MONOTONIC
- * timestamps from clock_gettime() as arguments to pthread_cond_timedwait,
- * which expects a CLOCK_REALTIME value, which is technically wrong, but
- * inocuous in practice on that particular platform since both clocks happen
- * to use close epochs.
- */
-
-extern int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t cl);
-#endif
-
 int
 __gnat_pthread_condattr_setup(pthread_condattr_t *attr) {
-/*
- * If using a clock other than CLOCK_REALTIME for the Ada Monotonic_Clock,
- * the corresponding clock id must be set for condition variables.
- */
   return pthread_condattr_setclock (attr, CLOCK_RT_Ada);
 }
 
Index: s-oscons-tmplt.c
===================================================================
--- s-oscons-tmplt.c    (revision 203500)
+++ s-oscons-tmplt.c    (working copy)
@@ -1407,11 +1407,15 @@
 #endif
 CND(CLOCK_THREAD_CPUTIME_ID, "Thread CPU clock")
 
-
-#if defined(__FreeBSD__) || defined(_AIX)
+#if defined(__FreeBSD__) || (defined(_AIX) && defined(_AIXVERSION_530))
 /** On these platforms use system provided monotonic clock instead of
- ** the default CLOCK_REALTIME. Note: We then need to set up cond var
- ** attributes appropriately (see thread.c).
+ ** the default CLOCK_REALTIME. We then need to set up cond var attributes
+ ** appropriately (see thread.c).
+ **
+ ** Note that AIX 5.2 does not support CLOCK_MONOTONIC timestamps for
+ ** pthread_cond_timedwait (and does not have pthread_condattr_setclock),
+ ** hence the conditionalization on AIX version above). _AIXVERSION_530
+ ** is defined in AIX 5.3 and more recent versions.
  **/
 # define CLOCK_RT_Ada "CLOCK_MONOTONIC"
 
Index: init.c
===================================================================
--- init.c      (revision 203500)
+++ init.c      (working copy)
@@ -226,19 +226,6 @@
 
 #endif /* _AIXVERSION_430 */
 
-/* Version of AIX before 5.3 don't have pthread_condattr_setclock:
- * supply it as a weak symbol here so that if linking on a 5.3 or newer
- * machine, we get the real one.
- */
-
-#ifndef _AIXVERSION_530
-#pragma weak pthread_condattr_setclock
-int
-pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t cl) {
-  return 0;
-}
-#endif
-
 static void
 __gnat_error_handler (int sig,
                      siginfo_t *si ATTRIBUTE_UNUSED,

Reply via email to