Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: base/time/time_fuchsia.cc

Issue 2891583002: Fuchsia port of base/time, with some refactoring of POSIX time modules. (Closed)
Patch Set: REBASE before commit. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/time/time_exploded_posix.cc ('k') | base/time/time_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/time/time.h"
6
7 #include <magenta/syscalls.h>
8
9 #include "base/compiler_specific.h"
10
11 namespace base {
12
13 namespace {
14
15 // Helper function to map an unsigned integer with nanosecond timebase to a
16 // signed integer with microsecond timebase.
17 ALWAYS_INLINE int64_t MxTimeToMicroseconds(mx_time_t nanos) {
18 const mx_time_t micros =
19 nanos / static_cast<mx_time_t>(base::Time::kNanosecondsPerMicrosecond);
20 return static_cast<int64_t>(micros);
21 }
22
23 } // namespace
24
25 // Time -----------------------------------------------------------------------
26
27 // static
28 Time Time::Now() {
29 const mx_time_t nanos_since_unix_epoch = mx_time_get(MX_CLOCK_UTC);
30 CHECK(nanos_since_unix_epoch != 0);
31 // The following expression will overflow in the year 289938 A.D.:
32 return Time(MxTimeToMicroseconds(nanos_since_unix_epoch) +
33 kTimeTToMicrosecondsOffset);
34 }
35
36 // static
37 Time Time::NowFromSystemTime() {
38 return Now();
39 }
40
41 // TimeTicks ------------------------------------------------------------------
42
43 // static
44 TimeTicks TimeTicks::Now() {
45 const mx_time_t nanos_since_boot = mx_time_get(MX_CLOCK_MONOTONIC);
46 CHECK(nanos_since_boot != 0);
47 return TimeTicks(MxTimeToMicroseconds(nanos_since_boot));
48 }
49
50 // static
51 TimeTicks::Clock TimeTicks::GetClock() {
52 return Clock::FUCHSIA_MX_CLOCK_MONOTONIC;
53 }
54
55 // static
56 bool TimeTicks::IsHighResolution() {
57 return true;
58 }
59
60 // static
61 bool TimeTicks::IsConsistentAcrossProcesses() {
62 return true;
63 }
64
65 // static
66 TimeTicks TimeTicks::FromMXTime(mx_time_t nanos_since_boot) {
67 return TimeTicks(MxTimeToMicroseconds(nanos_since_boot));
68 }
69
70 // static
71 ThreadTicks ThreadTicks::Now() {
72 const mx_time_t nanos_since_thread_started = mx_time_get(MX_CLOCK_THREAD);
73 CHECK(nanos_since_thread_started != 0);
74 return ThreadTicks(MxTimeToMicroseconds(nanos_since_thread_started));
75 }
76
77 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time_exploded_posix.cc ('k') | base/time/time_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698