From 1c06bb107bb915b26d7800138569351851d1ec69 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 10 Aug 2016 00:02:58 +0000 Subject: [PATCH] Fix build on android and Linux. gettimeofday() isn't defined without a special header. Rather than rely on C apis, let's just use modern C++11 to do this portably on all platforms using std::chrono. llvm-svn: 278182 --- lldb/include/lldb/Host/TimeValue.h | 2 +- lldb/source/Host/common/TimeValue.cpp | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lldb/include/lldb/Host/TimeValue.h b/lldb/include/lldb/Host/TimeValue.h index 2ddea46..d8e3f8a 100644 --- a/lldb/include/lldb/Host/TimeValue.h +++ b/lldb/include/lldb/Host/TimeValue.h @@ -35,7 +35,7 @@ public: TimeValue(); TimeValue(const TimeValue& rhs); TimeValue(const struct timespec& ts); - explicit TimeValue(uint32_t seconds, uint32_t nanos = 0); + explicit TimeValue(uint32_t seconds, uint64_t nanos = 0); ~TimeValue(); //------------------------------------------------------------------ diff --git a/lldb/source/Host/common/TimeValue.cpp b/lldb/source/Host/common/TimeValue.cpp index b471a3d..db74527 100644 --- a/lldb/source/Host/common/TimeValue.cpp +++ b/lldb/source/Host/common/TimeValue.cpp @@ -20,6 +20,8 @@ #endif // C++ Includes +#include + // Other libraries and framework includes // Project includes #include "lldb/Core/Stream.h" @@ -48,7 +50,7 @@ TimeValue::TimeValue(const struct timespec& ts) : { } -TimeValue::TimeValue(uint32_t seconds, uint32_t nanos) : +TimeValue::TimeValue(uint32_t seconds, uint64_t nanos) : m_nano_seconds((uint64_t) seconds * NanoSecPerSec + nanos) { } @@ -123,23 +125,11 @@ TimeValue::OffsetWithNanoSeconds (uint64_t nsec) TimeValue TimeValue::Now() { - uint32_t seconds, nanoseconds; -#if _MSC_VER - SYSTEMTIME st; - GetSystemTime(&st); - nanoseconds = st.wMilliseconds * 1000000; - FILETIME ft; - SystemTimeToFileTime(&st, &ft); - - seconds = ((((uint64_t)ft.dwHighDateTime) << 32 | ft.dwLowDateTime) / 10000000) - 11644473600ULL; -#else - struct timeval tv; - gettimeofday(&tv, NULL); - seconds = tv.tv_sec; - nanoseconds = tv.tv_usec * NanoSecPerMicroSec; -#endif - TimeValue now(seconds, nanoseconds); - return now; + using namespace std::chrono; + auto now = system_clock::now(); + auto ns_since_epoch = duration_cast(now.time_since_epoch()).count(); + + return TimeValue(0, ns_since_epoch); } //---------------------------------------------------------------------- -- 2.7.4