OLD | NEW |
---|---|
(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 namespace base { | |
10 | |
11 // Time ----------------------------------------------------------------------- | |
12 | |
13 // static | |
14 Time Time::Now() { | |
15 const mx_time_t nanos_since_unix_epoch = mx_time_get(MX_CLOCK_UTC); | |
16 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
| |
17 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.
| |
18 nanos_since_unix_epoch / | |
19 static_cast<mx_time_t>(kNanosecondsPerMicrosecond); | |
20 // The following expression will overflow in the year 289938 A.D.: | |
21 return Time(static_cast<int64_t>(usec_since_unix_epoch) + | |
22 kTimeTToMicrosecondsOffset); | |
23 } | |
24 | |
25 // static | |
26 Time Time::NowFromSystemTime() { | |
27 return Now(); | |
28 } | |
29 | |
30 // TimeTicks ------------------------------------------------------------------ | |
31 | |
32 // static | |
33 TimeTicks TimeTicks::Now() { | |
34 const mx_time_t nanos_since_boot = mx_time_get(MX_CLOCK_MONOTONIC); | |
35 CHECK(nanos_since_boot != 0); | |
36 const mx_time_t usec_since_boot = | |
37 nanos_since_boot / static_cast<mx_time_t>(kNanosecondsPerMicrosecond); | |
38 return TimeTicks(static_cast<int64_t>(usec_since_boot)); | |
39 } | |
40 | |
41 // static | |
42 TimeTicks::Clock TimeTicks::GetClock() { | |
43 return Clock::FUCHSIA_MX_CLOCK_MONOTONIC; | |
44 } | |
45 | |
46 // static | |
47 bool TimeTicks::IsHighResolution() { | |
48 return true; | |
49 } | |
50 | |
51 // static | |
52 bool TimeTicks::IsConsistentAcrossProcesses() { | |
53 return true; | |
54 } | |
55 | |
56 // static | |
57 TimeTicks TimeTicks::FromMXTime(mx_time_t nanos_since_boot) { | |
58 const mx_time_t usec_since_boot = | |
59 nanos_since_boot / static_cast<mx_time_t>(kNanosecondsPerMicrosecond); | |
60 return TimeTicks(static_cast<int64_t>(usec_since_boot)); | |
61 } | |
62 | |
63 // static | |
64 ThreadTicks ThreadTicks::Now() { | |
65 const mx_time_t nanos_since_thread_started = mx_time_get(MX_CLOCK_THREAD); | |
66 CHECK(nanos_since_thread_started != 0); | |
67 const mx_time_t usec_since_thread_started = | |
68 nanos_since_thread_started / | |
69 static_cast<mx_time_t>(kNanosecondsPerMicrosecond); | |
70 return ThreadTicks(static_cast<int64_t>(usec_since_thread_started)); | |
71 } | |
72 | |
73 } // namespace base | |
OLD | NEW |