Hi jroelofs,

The system_clock::now() function currently uses gettimeofday(). The problem 
with gettimeofday() is that it is an obsolete XSI function, hence unavailable 
on CloudABI. See:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html

Change this code to use clock_gettime() with CLOCK_REALTIME instead, which is 
more consistent, as clock_gettime() is already used for steady_clock.

A previous version of this change actually attempted to change 
system_clock::duration, but I reverted this part as it breaks the existing ABI.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8253

Files:
  src/chrono.cpp

Index: src/chrono.cpp
===================================================================
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -8,13 +8,13 @@
 
//===----------------------------------------------------------------------===//
 
 #include "chrono"
-#include <sys/time.h>        //for gettimeofday and timeval
 #ifdef __APPLE__
+#include <sys/time.h>        // for gettimeofday and timeval
 #include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
 #else  /* !__APPLE__ */
 #include <cerrno>  // errno
 #include <system_error>  // __throw_system_error
-#include <time.h>  // clock_gettime, CLOCK_MONOTONIC
+#include <time.h>  // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
 #endif  // __APPLE__
 
 _LIBCPP_BEGIN_NAMESPACE_STD
@@ -29,9 +29,16 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
+#ifdef __APPLE__
     timeval tv;
     gettimeofday(&tv, 0);
     return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
+#else  // __APPLE__
+    struct timespec tp;
+    if (0 != clock_gettime(CLOCK_REALTIME, &tp))
+        __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
+    return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#endif  // __APPLE__
 }
 
 time_t

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: src/chrono.cpp
===================================================================
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -8,13 +8,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "chrono"
-#include <sys/time.h>        //for gettimeofday and timeval
 #ifdef __APPLE__
+#include <sys/time.h>        // for gettimeofday and timeval
 #include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
 #else  /* !__APPLE__ */
 #include <cerrno>  // errno
 #include <system_error>  // __throw_system_error
-#include <time.h>  // clock_gettime, CLOCK_MONOTONIC
+#include <time.h>  // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
 #endif  // __APPLE__
 
 _LIBCPP_BEGIN_NAMESPACE_STD
@@ -29,9 +29,16 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
+#ifdef __APPLE__
     timeval tv;
     gettimeofday(&tv, 0);
     return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
+#else  // __APPLE__
+    struct timespec tp;
+    if (0 != clock_gettime(CLOCK_REALTIME, &tp))
+        __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
+    return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#endif  // __APPLE__
 }
 
 time_t
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to