diff options
| author | Zachary Turner <zturner@google.com> | 2016-08-10 00:02:58 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2016-08-10 00:02:58 +0000 |
| commit | 1c06bb107bb915b26d7800138569351851d1ec69 (patch) | |
| tree | 1e6b4f8eccd546d9848bba409f628c77345171ea | |
| parent | c682303d6f16accb74c43c252f27172c5e5a20a4 (diff) | |
| download | bcm5719-llvm-1c06bb107bb915b26d7800138569351851d1ec69.tar.gz bcm5719-llvm-1c06bb107bb915b26d7800138569351851d1ec69.zip | |
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
| -rw-r--r-- | lldb/include/lldb/Host/TimeValue.h | 2 | ||||
| -rw-r--r-- | 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 2ddea46e33f..d8e3f8a6469 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 b471a3dd1f1..db74527950b 100644 --- a/lldb/source/Host/common/TimeValue.cpp +++ b/lldb/source/Host/common/TimeValue.cpp @@ -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 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<std::chrono::nanoseconds>(now.time_since_epoch()).count(); + + return TimeValue(0, ns_since_epoch); } //---------------------------------------------------------------------- |

