[Lldb-commits] [lldb] r278182 - Fix build on android and Linux.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 9 17:02:59 PDT 2016


Author: zturner
Date: Tue Aug  9 19:02:58 2016
New Revision: 278182

URL: http://llvm.org/viewvc/llvm-project?rev=278182&view=rev
Log:
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.

Modified:
    lldb/trunk/include/lldb/Host/TimeValue.h
    lldb/trunk/source/Host/common/TimeValue.cpp

Modified: lldb/trunk/include/lldb/Host/TimeValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/TimeValue.h?rev=278182&r1=278181&r2=278182&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/TimeValue.h (original)
+++ lldb/trunk/include/lldb/Host/TimeValue.h Tue Aug  9 19:02:58 2016
@@ -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();
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Host/common/TimeValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/TimeValue.cpp?rev=278182&r1=278181&r2=278182&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/TimeValue.cpp (original)
+++ lldb/trunk/source/Host/common/TimeValue.cpp Tue Aug  9 19:02:58 2016
@@ -20,6 +20,8 @@
 #endif
 
 // C++ Includes
+#include <chrono>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/Stream.h"
@@ -48,7 +50,7 @@ TimeValue::TimeValue(const struct timesp
 {
 }
 
-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
 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<std::chrono::nanoseconds>(now.time_since_epoch()).count();
+
+  return TimeValue(0, ns_since_epoch);
 }
 
 //----------------------------------------------------------------------




More information about the lldb-commits mailing list