Index: webrtc/base/timeutils.cc |
diff --git a/webrtc/base/timeutils.cc b/webrtc/base/timeutils.cc |
index a9fe49d6075a2341a387247ccb8e941677ee3544..ecd0911a510dde654177bb368108d189ccc04645 100644 |
--- a/webrtc/base/timeutils.cc |
+++ b/webrtc/base/timeutils.cc |
@@ -30,8 +30,17 @@ |
namespace rtc { |
+ClockInterface* g_clock = nullptr; |
+ |
+void SetClock(ClockInterface* clock) { |
+ g_clock = clock; |
+} |
+ |
uint64_t TimeNanos() { |
- int64_t ticks = 0; |
+ if (g_clock) { |
+ return g_clock->TimeNanos(); |
+ } |
+ int64_t ticks; |
#if defined(WEBRTC_MAC) |
static mach_timebase_info_data_t timebase; |
if (timebase.denom == 0) { |
@@ -45,8 +54,8 @@ uint64_t TimeNanos() { |
ticks = mach_absolute_time() * timebase.numer / timebase.denom; |
#elif defined(WEBRTC_POSIX) |
struct timespec ts; |
- // TODO: Do we need to handle the case when CLOCK_MONOTONIC |
- // is not supported? |
+ // TODO(deadbeef): Do we need to handle the case when CLOCK_MONOTONIC is not |
+ // supported? |
clock_gettime(CLOCK_MONOTONIC, &ts); |
ticks = kNumNanosecsPerSec * static_cast<int64_t>(ts.tv_sec) + |
static_cast<int64_t>(ts.tv_nsec); |
@@ -58,8 +67,7 @@ uint64_t TimeNanos() { |
// Atomically update the last gotten time |
DWORD old = InterlockedExchange(last_timegettime_ptr, now); |
if (now < old) { |
- // If now is earlier than old, there may have been a race between |
- // threads. |
+ // If now is earlier than old, there may have been a race between threads. |
// 0x0fffffff ~3.1 days, the code will not take that long to execute |
// so it must have been a wrap around. |
if (old > 0xf0000000 && now < 0x0fffffff) { |
@@ -67,8 +75,8 @@ uint64_t TimeNanos() { |
} |
} |
ticks = now + (num_wrap_timegettime << 32); |
- // TODO: Calculate with nanosecond precision. Otherwise, we're just |
- // wasting a multiply and divide when doing Time() on Windows. |
+ // TODO(deadbeef): Calculate with nanosecond precision. Otherwise, we're |
+ // just wasting a multiply and divide when doing Time() on Windows. |
ticks = ticks * kNumNanosecsPerMillisec; |
#else |
#error Unsupported platform. |