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

Side by Side Diff: runtime/bin/utils_macos.cc

Issue 1571343003: Fix iOS implementation of |GetCurrentMonotonicMicros|. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | 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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <netdb.h> // NOLINT 9 #include <netdb.h> // NOLINT
10 #include <mach/mach.h> // NOLINT 10 #include <mach/mach.h> // NOLINT
11 #include <mach/clock.h> // NOLINT 11 #include <mach/clock.h> // NOLINT
12 #include <mach/mach_time.h> // NOLINT 12 #include <mach/mach_time.h> // NOLINT
13 #include <sys/time.h> // NOLINT 13 #include <sys/time.h> // NOLINT
14 #include <time.h> // NOLINT 14 #include <time.h> // NOLINT
15 15
16 #if TARGET_OS_IOS
17 #include <sys/sysctl.h> // NOLINT
18 #endif
19
16 #include "bin/utils.h" 20 #include "bin/utils.h"
17 #include "platform/assert.h" 21 #include "platform/assert.h"
18 #include "platform/utils.h" 22 #include "platform/utils.h"
19 23
20 24
21 namespace dart { 25 namespace dart {
22 namespace bin { 26 namespace bin {
23 27
24 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) { 28 OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) {
25 set_sub_system(kSystem); 29 set_sub_system(kSystem);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 82
79 void TimerUtils::InitOnce() { 83 void TimerUtils::InitOnce() {
80 kern_return_t kr = mach_timebase_info(&timebase_info); 84 kern_return_t kr = mach_timebase_info(&timebase_info);
81 ASSERT(KERN_SUCCESS == kr); 85 ASSERT(KERN_SUCCESS == kr);
82 } 86 }
83 87
84 int64_t TimerUtils::GetCurrentMonotonicMillis() { 88 int64_t TimerUtils::GetCurrentMonotonicMillis() {
85 return GetCurrentMonotonicMicros() / 1000; 89 return GetCurrentMonotonicMicros() / 1000;
86 } 90 }
87 91
92 #if TARGET_OS_IOS
93
94 static int64_t GetCurrentTimeMicros() {
95 // gettimeofday has microsecond resolution.
96 struct timeval tv;
97 if (gettimeofday(&tv, NULL) < 0) {
98 UNREACHABLE();
99 return 0;
100 }
101 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
102 }
103
104 #endif // TARGET_OS_IOS
105
88 int64_t TimerUtils::GetCurrentMonotonicMicros() { 106 int64_t TimerUtils::GetCurrentMonotonicMicros() {
89 #if TARGET_OS_IOS 107 #if TARGET_OS_IOS
90 // On iOS mach_absolute_time stops while the device is sleeping. Instead use 108 // On iOS mach_absolute_time stops while the device is sleeping. Instead use
91 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock 109 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
92 // changes. KERN_BOOTTIME will be updated by the system whenever the system 110 // changes. KERN_BOOTTIME will be updated by the system whenever the system
93 // clock change. 111 // clock change.
94 struct timeval boottime; 112 struct timeval boottime;
95 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; 113 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
96 size_t size = sizeof(boottime); 114 size_t size = sizeof(boottime);
97 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); 115 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 ASSERT(errno == EINTR); 147 ASSERT(errno == EINTR);
130 // Copy remainder into requested and repeat. 148 // Copy remainder into requested and repeat.
131 req = rem; 149 req = rem;
132 } 150 }
133 } 151 }
134 152
135 } // namespace bin 153 } // namespace bin
136 } // namespace dart 154 } // namespace dart
137 155
138 #endif // defined(TARGET_OS_MACOS) 156 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698