| 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_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
| 9 #include <time.h> // NOLINT | 9 #include <time.h> // NOLINT |
| 10 | 10 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // 100-nanosecond intervals since January 1, 1601. | 180 // 100-nanosecond intervals since January 1, 1601. |
| 181 union TimeStamp { | 181 union TimeStamp { |
| 182 FILETIME ft_; | 182 FILETIME ft_; |
| 183 int64_t t_; | 183 int64_t t_; |
| 184 }; | 184 }; |
| 185 TimeStamp time; | 185 TimeStamp time; |
| 186 GetSystemTimeAsFileTime(&time.ft_); | 186 GetSystemTimeAsFileTime(&time.ft_); |
| 187 return (time.t_ - kTimeEpoc) / kTimeScaler; | 187 return (time.t_ - kTimeEpoc) / kTimeScaler; |
| 188 } | 188 } |
| 189 | 189 |
| 190 static int64_t qpc_ticks_per_second = 0; |
| 191 |
| 192 void TimerUtils::InitOnce() { |
| 193 LARGE_INTEGER ticks_per_sec; |
| 194 if (!QueryPerformanceFrequency(&ticks_per_sec)) { |
| 195 qpc_ticks_per_second = 0; |
| 196 } else { |
| 197 qpc_ticks_per_second = static_cast<int64_t>(ticks_per_sec.QuadPart); |
| 198 } |
| 199 } |
| 200 |
| 190 int64_t TimerUtils::GetCurrentMonotonicMillis() { | 201 int64_t TimerUtils::GetCurrentMonotonicMillis() { |
| 191 return GetCurrentMonotonicMicros() / 1000; | 202 return GetCurrentMonotonicMicros() / 1000; |
| 192 } | 203 } |
| 193 | 204 |
| 194 static int64_t qpc_ticks_per_second = 0; | |
| 195 | |
| 196 int64_t TimerUtils::GetCurrentMonotonicMicros() { | 205 int64_t TimerUtils::GetCurrentMonotonicMicros() { |
| 197 if (qpc_ticks_per_second == 0) { | 206 if (qpc_ticks_per_second == 0) { |
| 198 // QueryPerformanceCounter not supported, fallback. | 207 // QueryPerformanceCounter not supported, fallback. |
| 199 return GetCurrentTimeMicros(); | 208 return GetCurrentTimeMicros(); |
| 200 } | 209 } |
| 201 // Grab performance counter value. | 210 // Grab performance counter value. |
| 202 LARGE_INTEGER now; | 211 LARGE_INTEGER now; |
| 203 QueryPerformanceCounter(&now); | 212 QueryPerformanceCounter(&now); |
| 204 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); | 213 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); |
| 205 // Convert to microseconds. | 214 // Convert to microseconds. |
| 206 int64_t seconds = qpc_value / qpc_ticks_per_second; | 215 int64_t seconds = qpc_value / qpc_ticks_per_second; |
| 207 int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second); | 216 int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second); |
| 208 int64_t result = seconds * kMicrosecondsPerSecond; | 217 int64_t result = seconds * kMicrosecondsPerSecond; |
| 209 result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second); | 218 result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second); |
| 210 return result; | 219 return result; |
| 211 } | 220 } |
| 212 | 221 |
| 213 void TimerUtils::Sleep(int64_t millis) { | 222 void TimerUtils::Sleep(int64_t millis) { |
| 214 ::Sleep(millis); | 223 ::Sleep(millis); |
| 215 } | 224 } |
| 216 | 225 |
| 217 } // namespace bin | 226 } // namespace bin |
| 218 } // namespace dart | 227 } // namespace dart |
| 219 | 228 |
| 220 #endif // defined(TARGET_OS_WINDOWS) | 229 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |