Index: base/time/time_fuchsia.cc |
diff --git a/base/time/time_fuchsia.cc b/base/time/time_fuchsia.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1baffd1ec9d56c5b6df91d6193324c588dbdf2b3 |
--- /dev/null |
+++ b/base/time/time_fuchsia.cc |
@@ -0,0 +1,73 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/time/time.h" |
+ |
+#include <magenta/syscalls.h> |
+ |
+namespace base { |
+ |
+// Time ----------------------------------------------------------------------- |
+ |
+// static |
+Time Time::Now() { |
+ const mx_time_t nanos_since_unix_epoch = mx_time_get(MX_CLOCK_UTC); |
+ CHECK(nanos_since_unix_epoch != 0); |
Lei Zhang
2017/05/17 08:34:17
We handle gettimeofday() failures in time_now_posi
miu
2017/05/18 02:52:38
Done (changes to time_now_posix.cc, to not tolerat
|
+ const mx_time_t usec_since_unix_epoch = |
Lei Zhang
2017/05/17 08:34:17
What is mx_time_t underneath? Can we get away with
miu
2017/05/18 02:52:38
Good point. I had looked into that, and it's uint6
Lei Zhang
2017/05/18 19:06:12
Ya, I can't remember all the rules off the top of
miu
2017/05/18 20:39:04
Done.
|
+ nanos_since_unix_epoch / |
+ static_cast<mx_time_t>(kNanosecondsPerMicrosecond); |
+ // The following expression will overflow in the year 289938 A.D.: |
+ return Time(static_cast<int64_t>(usec_since_unix_epoch) + |
+ kTimeTToMicrosecondsOffset); |
+} |
+ |
+// static |
+Time Time::NowFromSystemTime() { |
+ return Now(); |
+} |
+ |
+// TimeTicks ------------------------------------------------------------------ |
+ |
+// static |
+TimeTicks TimeTicks::Now() { |
+ const mx_time_t nanos_since_boot = mx_time_get(MX_CLOCK_MONOTONIC); |
+ CHECK(nanos_since_boot != 0); |
+ const mx_time_t usec_since_boot = |
+ nanos_since_boot / static_cast<mx_time_t>(kNanosecondsPerMicrosecond); |
+ return TimeTicks(static_cast<int64_t>(usec_since_boot)); |
+} |
+ |
+// static |
+TimeTicks::Clock TimeTicks::GetClock() { |
+ return Clock::FUCHSIA_MX_CLOCK_MONOTONIC; |
+} |
+ |
+// static |
+bool TimeTicks::IsHighResolution() { |
+ return true; |
+} |
+ |
+// static |
+bool TimeTicks::IsConsistentAcrossProcesses() { |
+ return true; |
+} |
+ |
+// static |
+TimeTicks TimeTicks::FromMXTime(mx_time_t nanos_since_boot) { |
+ const mx_time_t usec_since_boot = |
+ nanos_since_boot / static_cast<mx_time_t>(kNanosecondsPerMicrosecond); |
+ return TimeTicks(static_cast<int64_t>(usec_since_boot)); |
+} |
+ |
+// static |
+ThreadTicks ThreadTicks::Now() { |
+ const mx_time_t nanos_since_thread_started = mx_time_get(MX_CLOCK_THREAD); |
+ CHECK(nanos_since_thread_started != 0); |
+ const mx_time_t usec_since_thread_started = |
+ nanos_since_thread_started / |
+ static_cast<mx_time_t>(kNanosecondsPerMicrosecond); |
+ return ThreadTicks(static_cast<int64_t>(usec_since_thread_started)); |
+} |
+ |
+} // namespace base |