OLD | NEW |
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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <netdb.h> // NOLINT | 9 #include <netdb.h> // NOLINT |
10 #include <sys/time.h> // NOLINT | 10 #include <sys/time.h> // NOLINT |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 char* StringUtils::Utf8ToConsoleString( | 64 char* StringUtils::Utf8ToConsoleString( |
65 char* utf8, intptr_t len, intptr_t* result_len) { | 65 char* utf8, intptr_t len, intptr_t* result_len) { |
66 UNIMPLEMENTED(); | 66 UNIMPLEMENTED(); |
67 return NULL; | 67 return NULL; |
68 } | 68 } |
69 | 69 |
70 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { | 70 bool ShellUtils::GetUtf8Argv(int argc, char** argv) { |
71 return false; | 71 return false; |
72 } | 72 } |
73 | 73 |
74 int64_t TimerUtils::GetCurrentTimeMilliseconds() { | 74 int64_t TimerUtils::GetCurrentMonotonicMillis() { |
75 return GetCurrentTimeMicros() / 1000; | 75 return GetCurrentMonotonicMicros() / 1000; |
76 } | 76 } |
77 | 77 |
78 int64_t TimerUtils::GetCurrentTimeMicros() { | 78 int64_t TimerUtils::GetCurrentMonotonicMicros() { |
79 struct timeval tv; | 79 struct timespec ts; |
80 if (gettimeofday(&tv, NULL) < 0) { | 80 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
81 UNREACHABLE(); | 81 UNREACHABLE(); |
82 return 0; | 82 return 0; |
83 } | 83 } |
84 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; | 84 // Convert to microseconds. |
| 85 int64_t result = ts.tv_sec; |
| 86 result *= kMicrosecondsPerSecond; |
| 87 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); |
| 88 return result; |
85 } | 89 } |
86 | 90 |
87 void TimerUtils::Sleep(int64_t millis) { | 91 void TimerUtils::Sleep(int64_t millis) { |
88 struct timespec req; // requested. | 92 struct timespec req; // requested. |
89 struct timespec rem; // remainder. | 93 struct timespec rem; // remainder. |
90 int64_t micros = millis * kMicrosecondsPerMillisecond; | 94 int64_t micros = millis * kMicrosecondsPerMillisecond; |
91 int64_t seconds = micros / kMicrosecondsPerSecond; | 95 int64_t seconds = micros / kMicrosecondsPerSecond; |
92 micros = micros - seconds * kMicrosecondsPerSecond; | 96 micros = micros - seconds * kMicrosecondsPerSecond; |
93 int64_t nanos = micros * kNanosecondsPerMicrosecond; | 97 int64_t nanos = micros * kNanosecondsPerMicrosecond; |
94 req.tv_sec = seconds; | 98 req.tv_sec = seconds; |
95 req.tv_nsec = nanos; | 99 req.tv_nsec = nanos; |
96 while (true) { | 100 while (true) { |
97 int r = nanosleep(&req, &rem); | 101 int r = nanosleep(&req, &rem); |
98 if (r == 0) { | 102 if (r == 0) { |
99 break; | 103 break; |
100 } | 104 } |
101 // We should only ever see an interrupt error. | 105 // We should only ever see an interrupt error. |
102 ASSERT(errno == EINTR); | 106 ASSERT(errno == EINTR); |
103 // Copy remainder into requested and repeat. | 107 // Copy remainder into requested and repeat. |
104 req = rem; | 108 req = rem; |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
108 } // namespace bin | 112 } // namespace bin |
109 } // namespace dart | 113 } // namespace dart |
110 | 114 |
111 #endif // defined(TARGET_OS_ANDROID) | 115 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |