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

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

Issue 1644753002: Make base work on iOS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 4 years, 10 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.h ('k') | build/config/android/config.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <CoreFoundation/CFDate.h> 7 #include <CoreFoundation/CFDate.h>
8 #include <CoreFoundation/CFTimeZone.h> 8 #include <CoreFoundation/CFTimeZone.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <mach/mach_time.h> 10 #include <mach/mach_time.h>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 result /= timebase_info.denom; 62 result /= timebase_info.denom;
63 63
64 // Don't bother with the rollover handling that the Windows version does. 64 // Don't bother with the rollover handling that the Windows version does.
65 // With numer and denom = 1 (the expected case), the 64-bit absolute time 65 // With numer and denom = 1 (the expected case), the 64-bit absolute time
66 // reported in nanoseconds is enough to last nearly 585 years. 66 // reported in nanoseconds is enough to last nearly 585 years.
67 return base::checked_cast<int64_t>(result.ValueOrDie()); 67 return base::checked_cast<int64_t>(result.ValueOrDie());
68 #endif // defined(OS_IOS) 68 #endif // defined(OS_IOS)
69 } 69 }
70 70
71 int64_t ComputeThreadTicks() { 71 int64_t ComputeThreadTicks() {
72 #if defined(OS_IOS)
73 NOTREACHED();
74 return 0;
75 #else
76 base::mac::ScopedMachSendRight thread(mach_thread_self()); 72 base::mac::ScopedMachSendRight thread(mach_thread_self());
77 mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; 73 mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT;
78 thread_basic_info_data_t thread_info_data; 74 thread_basic_info_data_t thread_info_data;
79 75
80 if (thread.get() == MACH_PORT_NULL) { 76 if (thread.get() == MACH_PORT_NULL) {
81 DLOG(ERROR) << "Failed to get mach_thread_self()"; 77 DLOG(ERROR) << "Failed to get mach_thread_self()";
82 return 0; 78 return 0;
83 } 79 }
84 80
85 kern_return_t kr = thread_info( 81 kern_return_t kr = thread_info(
86 thread, 82 thread,
87 THREAD_BASIC_INFO, 83 THREAD_BASIC_INFO,
88 reinterpret_cast<thread_info_t>(&thread_info_data), 84 reinterpret_cast<thread_info_t>(&thread_info_data),
89 &thread_info_count); 85 &thread_info_count);
90 MACH_DCHECK(kr == KERN_SUCCESS, kr) << "thread_info"; 86 MACH_DCHECK(kr == KERN_SUCCESS, kr) << "thread_info";
91 87
92 base::CheckedNumeric<int64_t> absolute_micros( 88 base::CheckedNumeric<int64_t> absolute_micros(
93 thread_info_data.user_time.seconds); 89 thread_info_data.user_time.seconds);
94 absolute_micros *= base::Time::kMicrosecondsPerSecond; 90 absolute_micros *= base::Time::kMicrosecondsPerSecond;
95 absolute_micros += thread_info_data.user_time.microseconds; 91 absolute_micros += thread_info_data.user_time.microseconds;
96 return absolute_micros.ValueOrDie(); 92 return absolute_micros.ValueOrDie();
97 #endif // defined(OS_IOS)
98 } 93 }
99 94
100 } // namespace 95 } // namespace
101 96
102 namespace base { 97 namespace base {
103 98
104 // The Time routines in this file use Mach and CoreFoundation APIs, since the 99 // The Time routines in this file use Mach and CoreFoundation APIs, since the
105 // POSIX definition of time_t in Mac OS X wraps around after 2038--and 100 // POSIX definition of time_t in Mac OS X wraps around after 2038--and
106 // there are already cookie expiration dates, etc., past that time out in 101 // there are already cookie expiration dates, etc., past that time out in
107 // the field. Using CFDate prevents that problem, and using mach_absolute_time 102 // the field. Using CFDate prevents that problem, and using mach_absolute_time
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 ThreadTicks ThreadTicks::Now() { 225 ThreadTicks ThreadTicks::Now() {
231 return ThreadTicks(ComputeThreadTicks()); 226 return ThreadTicks(ComputeThreadTicks());
232 } 227 }
233 228
234 // static 229 // static
235 TraceTicks TraceTicks::Now() { 230 TraceTicks TraceTicks::Now() {
236 return TraceTicks(ComputeCurrentTicks()); 231 return TraceTicks(ComputeCurrentTicks());
237 } 232 }
238 233
239 } // namespace base 234 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time.h ('k') | build/config/android/config.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698