forked from OSchip/llvm-project
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
This commit is contained in:
parent
c682303d6f
commit
1c06bb107b
|
@ -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();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
using namespace std::chrono;
|
||||
auto now = system_clock::now();
|
||||
auto ns_since_epoch = duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
|
||||
|
||||
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;
|
||||
return TimeValue(0, ns_since_epoch);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue