rmaprath updated this revision to Diff 90025.
rmaprath added a comment.

Fixed minor omission.


https://reviews.llvm.org/D29818

Files:
  src/chrono.cpp


Index: src/chrono.cpp
===================================================================
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -11,6 +11,7 @@
 #include "cerrno"        // errno
 #include "system_error"  // __throw_system_error
 #include <time.h>        // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
+#include "__threading_support"
 
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
@@ -50,7 +51,8 @@
 #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 #if __APPLE__
 #include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
+#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) && \
+      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #error "Monotonic clock not implemented"
 #endif
 #endif
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+    struct timespec tp;
+    if (0 != __libcpp_clock_realtime(&tp))
+        __throw_system_error(errno, "__libcpp_clock_realtime() failed");
+    return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
       _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
                        static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
     struct timespec tp;
     if (0 != clock_gettime(CLOCK_REALTIME, &tp))
         __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
     gettimeofday(&tv, 0);
     return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+    struct timespec tp;
+    if (0 != __libcpp_clock_monotonic(&tp))
+        __throw_system_error(errno, "__libcpp_clock_monotonic() failed");
+    return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
+#elif defined(__APPLE__)
 
 // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
 #if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)


Index: src/chrono.cpp
===================================================================
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -11,6 +11,7 @@
 #include "cerrno"        // errno
 #include "system_error"  // __throw_system_error
 #include <time.h>        // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
+#include "__threading_support"
 
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
@@ -50,7 +51,8 @@
 #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 #if __APPLE__
 #include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
+#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) && \
+      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #error "Monotonic clock not implemented"
 #endif
 #endif
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+    struct timespec tp;
+    if (0 != __libcpp_clock_realtime(&tp))
+        __throw_system_error(errno, "__libcpp_clock_realtime() failed");
+    return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
       _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
                        static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
     struct timespec tp;
     if (0 != clock_gettime(CLOCK_REALTIME, &tp))
         __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
     gettimeofday(&tv, 0);
     return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+    struct timespec tp;
+    if (0 != __libcpp_clock_monotonic(&tp))
+        __throw_system_error(errno, "__libcpp_clock_monotonic() failed");
+    return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
+#elif defined(__APPLE__)
 
 // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
 #if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to