summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2017-01-01 20:20:43 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2017-01-01 20:20:43 +0000
commit78f51f95a47f0552ff9c1c86737b69417d660976 (patch)
tree2e4d8c55b0abfd2b913029a3b54ff8abaae8c746 /libcxx
parent6e3a0cc404a74b7b9d7dd4228606d72f45114739 (diff)
downloadbcm5719-llvm-78f51f95a47f0552ff9c1c86737b69417d660976.tar.gz
bcm5719-llvm-78f51f95a47f0552ff9c1c86737b69417d660976.zip
chrono: give Windows a steady_clock
Provide a definition for a steady monotonic clock by wrapping QueryPerformanceCounter. llvm-svn: 290804
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/src/chrono.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 578b0a9017b..e9030f1ee3d 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -25,10 +25,10 @@
#endif
#endif
-#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(CLOCK_MONOTONIC)
+#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
#if __APPLE__
#include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t
-#else
+#elif !defined(_WIN32) && !defined(CLOCK_MONOTONIC)
#error "Monotonic clock not implemented"
#endif
#endif
@@ -101,18 +101,7 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
const bool steady_clock::is_steady;
-#ifdef CLOCK_MONOTONIC
-
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
- struct timespec tp;
- if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
- __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
- return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
-}
-
-#elif defined(__APPLE__)
+#if defined(__APPLE__)
// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
@@ -166,6 +155,32 @@ steady_clock::now() _NOEXCEPT
return time_point(duration(fp()));
}
+#elif defined(_WIN32)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+ static LARGE_INTEGER liFreq;
+ static BOOL bQPFRun = FALSE;
+ if (bQPFRun == FALSE)
+ bQPFRun = QueryPerformanceFrequency(&liFreq);
+
+ LARGE_INTEGER liCntr;
+ QueryPerformanceCounter(&liCntr);
+ return time_point(duration(liCntr.QuadPart * nano::den / liFreq.QuadPart));
+}
+
+#elif defined(CLOCK_MONOTONIC)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+ struct timespec tp;
+ if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
+ __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
+ return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
#else
#error "Monotonic clock not implemented"
#endif
OpenPOWER on IntegriCloud