]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/libgfortran/lib/contrib/intrinsics/time_1.h
Update
[l4.git] / l4 / pkg / libgfortran / lib / contrib / intrinsics / time_1.h
index aaca56ac54ae38af6492a26e00822a2a4ba3f4ae..185ab5873e14e971f3e69d3fc3059e73e7381e07 100644 (file)
@@ -1,5 +1,5 @@
 /* Wrappers for platform timing functions.
-   Copyright (C) 2003, 2007, 2009, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2003-2015 Free Software Foundation, Inc.
 
 This file is part of the GNU Fortran runtime library (libgfortran).
 
@@ -101,7 +101,7 @@ localtime_r (const time_t * timep, struct tm * result)
    CPU_TIME intrinsics.  Returns 0 for success or -1 if no
    CPU time could be computed.  */
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(__CYGWIN__)
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
@@ -158,18 +158,34 @@ gf_cputime (long *user_sec, long *user_usec, long *system_sec, long *system_usec
   struct tms buf;
   clock_t err;
   err = times (&buf);
-  *user_sec = buf.tms_utime / HZ;
-  *user_usec = buf.tms_utime % HZ * (1000000. / HZ);
-  *system_sec = buf.tms_stime / HZ;
-  *system_usec = buf.tms_stime % HZ * (1000000. / HZ);
+  long hz = HZ;
+  *user_sec = buf.tms_utime / hz;
+  *user_usec = (buf.tms_utime % hz) * (1000000. / hz);
+  *system_sec = buf.tms_stime / hz;
+  *system_usec = (buf.tms_stime % hz) * (1000000. / hz);
   if ((err == (clock_t) -1) && errno != 0)
     return -1;
   return 0;
 
+#elif defined(HAVE_CLOCK_GETTIME) && (defined(CLOCK_PROCESS_CPUTIME_ID) \
+                                     || defined(CLOCK_THREAD_CPUTIME_ID))
+  /* Newer versions of VxWorks have CLOCK_THREAD_CPUTIME_ID giving
+     per-thread CPU time.  CLOCK_PROCESS_CPUTIME_ID would be better
+     but is not available.  */
+#ifndef CLOCK_PROCESS_CPUTIME_ID
+#define CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID
+#endif
+  struct timespec ts;
+  int err = clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts);
+  *user_sec = ts.tv_sec;
+  *user_usec = ts.tv_nsec / 1000;
+  *system_sec = *system_usec = 0;
+  return err;
+
 #else 
   clock_t c = clock ();
   *user_sec = c / CLOCKS_PER_SEC;
-  *user_usec = c % CLOCKS_PER_SEC * (1000000. / CLOCKS_PER_SEC);
+  *user_usec = (c % CLOCKS_PER_SEC) * (1000000. / CLOCKS_PER_SEC);
   *system_sec = *system_usec = 0;
   if (c == (clock_t) -1)
     return -1;
@@ -181,15 +197,15 @@ 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
    usecs    - OUTPUT, microseconds
 
    The OUTPUT arguments shall represent the number of seconds and
-   nanoseconds since the Epoch.
+   microseconds since the Epoch.
 
    Return value: 0 for success, -1 for error. In case of error, errno
    is set.
@@ -204,6 +220,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;