Skip to content
Permalink
Browse files

src: use uv_gettimeofday() to get microseconds

Use uv_gettimeofday() in GetCurrentTimeInMicroseconds() to
remove the need for #ifdef logic.

PR-URL: #27029
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information...
cjihrig committed Apr 15, 2019
1 parent af35d40 commit 8e1e9946a9f251fd943de1777fd9b598979e5a23
Showing with 4 additions and 17 deletions.
  1. +4 −17 src/util.cc
@@ -50,9 +50,6 @@ static std::atomic_int seq = {0}; // Sequence number for diagnostic filenames.

namespace node {

// Microseconds in a second, as a float.
#define MICROS_PER_SEC 1e6

using v8::ArrayBufferView;
using v8::Isolate;
using v8::Local;
@@ -166,20 +163,10 @@ void ThrowErrStringTooLong(Isolate* isolate) {
}

double GetCurrentTimeInMicroseconds() {
#ifdef _WIN32
// The difference between the Unix Epoch and the Windows Epoch in 100-ns ticks.
#define TICKS_TO_UNIX_EPOCH 116444736000000000LL
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
uint64_t filetime_int =
static_cast<uint64_t>(ft.dwHighDateTime) << 32 | ft.dwLowDateTime;
// FILETIME is measured in terms of 100 ns. Convert that to 1 us (1000 ns).
return (filetime_int - TICKS_TO_UNIX_EPOCH) / 10.;
#else
struct timeval tp;
gettimeofday(&tp, nullptr);
return MICROS_PER_SEC * tp.tv_sec + tp.tv_usec;
#endif
constexpr double kMicrosecondsPerSecond = 1e6;
uv_timeval64_t tv;
CHECK_EQ(0, uv_gettimeofday(&tv));
return kMicrosecondsPerSecond * tv.tv_sec + tv.tv_usec;
}

int WriteFileSync(const char* path, uv_buf_t buf) {

0 comments on commit 8e1e994

Please sign in to comment.
You can’t perform that action at this time.