PR 53456 clock_gettime fallback for gf_gettime
authorJanne Blomqvist <jb@gcc.gnu.org>
Wed, 23 May 2012 18:52:47 +0000 (21:52 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Wed, 23 May 2012 18:52:47 +0000 (21:52 +0300)
2012-05-23  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/53456
* intrinsics/time_1.h (gf_gettime): Fallback for clock_gettime.

From-SVN: r187806

libgfortran/ChangeLog
libgfortran/intrinsics/time_1.h

index e5f79e0cd3d22e9463eae43b472bc60a1a9f7fbd..3dfde053eadcaececcc030e3b43f7c5d8f3d3b14 100644 (file)
@@ -1,3 +1,8 @@
+2012-05-23  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR fortran/53456
+       * intrinsics/time_1.h (gf_gettime): Fallback for clock_gettime.
+
 2012-05-23  Robert Mason  <rbmj@verizon.net>
            Tobias Burnus  <burnus@net-b.de>
 
index aaca56ac54ae38af6492a26e00822a2a4ba3f4ae..ca5b26b4fbb88c39d3c8ab59e7131f8912baa8a9 100644 (file)
@@ -181,8 +181,8 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec
 #endif
 
 
-/* Realtime clock with microsecond resolution, falling back to less
-   precise functions if the target does not support gettimeofday().
+/* Realtime clock with microsecond resolution, falling back to other
+   functions if the target does not support gettimeofday().
 
    Arguments:
    secs     - OUTPUT, seconds
@@ -204,6 +204,12 @@ gf_gettime (time_t * secs, long * usecs)
   *secs = tv.tv_sec;
   *usecs = tv.tv_usec;
   return err;
+#elif defined(HAVE_CLOCK_GETTIME)
+  struct timespec ts;
+  int err = clock_gettime (CLOCK_REALTIME, &ts);
+  *secs = ts.tv_sec;
+  *usecs = ts.tv_nsec / 1000;
+  return err;
 #else
   time_t t = time (NULL);
   *secs = t;