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