| 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 "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 #include <malloc.h> // NOLINT | 10 #include <malloc.h> // NOLINT |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 int64_t t_; | 116 int64_t t_; |
| 117 }; | 117 }; |
| 118 TimeStamp time; | 118 TimeStamp time; |
| 119 GetSystemTimeAsFileTime(&time.ft_); | 119 GetSystemTimeAsFileTime(&time.ft_); |
| 120 return (time.t_ - kTimeEpoc) / kTimeScaler; | 120 return (time.t_ - kTimeEpoc) / kTimeScaler; |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 static int64_t qpc_ticks_per_second = 0; | 124 static int64_t qpc_ticks_per_second = 0; |
| 125 | 125 |
| 126 int64_t OS::GetCurrentMonotonicMicros() { | 126 |
| 127 int64_t OS::GetCurrentMonotonicTicks() { |
| 127 if (qpc_ticks_per_second == 0) { | 128 if (qpc_ticks_per_second == 0) { |
| 128 // QueryPerformanceCounter not supported, fallback. | 129 // QueryPerformanceCounter not supported, fallback. |
| 129 return GetCurrentTimeMicros(); | 130 return GetCurrentTimeMicros(); |
| 130 } | 131 } |
| 131 // Grab performance counter value. | 132 // Grab performance counter value. |
| 132 LARGE_INTEGER now; | 133 LARGE_INTEGER now; |
| 133 QueryPerformanceCounter(&now); | 134 QueryPerformanceCounter(&now); |
| 134 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); | 135 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); |
| 136 } |
| 137 |
| 138 |
| 139 int64_t OS::GetCurrentMonotonicFrequency() { |
| 140 if (qpc_ticks_per_second == 0) { |
| 141 // QueryPerformanceCounter not supported, fallback. |
| 142 return kMicrosecondsPerSecond; |
| 143 } |
| 144 return qpc_ticks_per_second; |
| 145 } |
| 146 |
| 147 |
| 148 int64_t OS::GetCurrentMonotonicMicros() { |
| 149 int64_t ticks = GetCurrentMonotonicTicks(); |
| 150 int64_t frequency = GetCurrentMonotonicFrequency(); |
| 151 |
| 135 // Convert to microseconds. | 152 // Convert to microseconds. |
| 136 int64_t seconds = qpc_value / qpc_ticks_per_second; | 153 int64_t seconds = ticks / frequency; |
| 137 int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second); | 154 int64_t leftover_ticks = ticks - (seconds * frequency); |
| 138 int64_t result = seconds * kMicrosecondsPerSecond; | 155 int64_t result = seconds * kMicrosecondsPerSecond; |
| 139 result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second); | 156 result += ((leftover_ticks * kMicrosecondsPerSecond) / frequency); |
| 140 return result; | 157 return result; |
| 141 } | 158 } |
| 142 | 159 |
| 143 | 160 |
| 144 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 161 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 145 const int kMinimumAlignment = 16; | 162 const int kMinimumAlignment = 16; |
| 146 ASSERT(Utils::IsPowerOfTwo(alignment)); | 163 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 147 ASSERT(alignment >= kMinimumAlignment); | 164 ASSERT(alignment >= kMinimumAlignment); |
| 148 void* p = _aligned_malloc(size, alignment); | 165 void* p = _aligned_malloc(size, alignment); |
| 149 if (p == NULL) { | 166 if (p == NULL) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 408 } |
| 392 | 409 |
| 393 | 410 |
| 394 void OS::Exit(int code) { | 411 void OS::Exit(int code) { |
| 395 exit(code); | 412 exit(code); |
| 396 } | 413 } |
| 397 | 414 |
| 398 } // namespace dart | 415 } // namespace dart |
| 399 | 416 |
| 400 #endif // defined(TARGET_OS_WINDOWS) | 417 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |