| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 union TimeStamp { | 114 union TimeStamp { |
| 115 FILETIME ft_; | 115 FILETIME ft_; |
| 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; |
| 125 |
| 126 int64_t OS::GetCurrentTraceMicros() { |
| 127 if (qpc_ticks_per_second == 0) { |
| 128 // QueryPerformanceCounter not supported, fallback. |
| 129 return GetCurrentTimeMicros(); |
| 130 } |
| 131 // Grab performance counter value. |
| 132 LARGE_INTEGER now; |
| 133 QueryPerformanceCounter(&now); |
| 134 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); |
| 135 // Convert to microseconds. |
| 136 int64_t seconds = qpc_value / qpc_ticks_per_second; |
| 137 int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second); |
| 138 int64_t result = seconds * kMicrosecondsPerSecond; |
| 139 result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second); |
| 140 return result; |
| 141 } |
| 142 |
| 143 |
| 124 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 144 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 125 const int kMinimumAlignment = 16; | 145 const int kMinimumAlignment = 16; |
| 126 ASSERT(Utils::IsPowerOfTwo(alignment)); | 146 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 127 ASSERT(alignment >= kMinimumAlignment); | 147 ASSERT(alignment >= kMinimumAlignment); |
| 128 void* p = _aligned_malloc(size, alignment); | 148 void* p = _aligned_malloc(size, alignment); |
| 129 if (p == NULL) { | 149 if (p == NULL) { |
| 130 UNREACHABLE(); | 150 UNREACHABLE(); |
| 131 } | 151 } |
| 132 return p; | 152 return p; |
| 133 } | 153 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // TODO(5411554): For now we check that initonce is called only once, | 363 // TODO(5411554): For now we check that initonce is called only once, |
| 344 // Once there is more formal mechanism to call InitOnce we can move | 364 // Once there is more formal mechanism to call InitOnce we can move |
| 345 // this check there. | 365 // this check there. |
| 346 static bool init_once_called = false; | 366 static bool init_once_called = false; |
| 347 ASSERT(init_once_called == false); | 367 ASSERT(init_once_called == false); |
| 348 init_once_called = true; | 368 init_once_called = true; |
| 349 // Do not pop up a message box when abort is called. | 369 // Do not pop up a message box when abort is called. |
| 350 _set_abort_behavior(0, _WRITE_ABORT_MSG); | 370 _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| 351 MonitorWaitData::monitor_wait_data_key_ = OSThread::CreateThreadLocal(); | 371 MonitorWaitData::monitor_wait_data_key_ = OSThread::CreateThreadLocal(); |
| 352 MonitorData::GetMonitorWaitDataForThread(); | 372 MonitorData::GetMonitorWaitDataForThread(); |
| 373 LARGE_INTEGER ticks_per_sec; |
| 374 if (!QueryPerformanceFrequency(&ticks_per_sec)) { |
| 375 qpc_ticks_per_second = 0; |
| 376 } else { |
| 377 qpc_ticks_per_second = static_cast<int64_t>(ticks_per_sec.QuadPart); |
| 378 } |
| 353 } | 379 } |
| 354 | 380 |
| 355 | 381 |
| 356 void OS::Shutdown() { | 382 void OS::Shutdown() { |
| 357 } | 383 } |
| 358 | 384 |
| 359 | 385 |
| 360 void OS::Abort() { | 386 void OS::Abort() { |
| 361 abort(); | 387 abort(); |
| 362 } | 388 } |
| 363 | 389 |
| 364 | 390 |
| 365 void OS::Exit(int code) { | 391 void OS::Exit(int code) { |
| 366 exit(code); | 392 exit(code); |
| 367 } | 393 } |
| 368 | 394 |
| 369 } // namespace dart | 395 } // namespace dart |
| 370 | 396 |
| 371 #endif // defined(TARGET_OS_WINDOWS) | 397 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |