| 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 "bin/thread.h" | 8 #include "bin/thread.h" |
| 9 #include "bin/thread_win.h" | 9 #include "bin/thread_win.h" |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 ASSERT(sizeof(id) <= sizeof(intptr_t)); | 107 ASSERT(sizeof(id) <= sizeof(intptr_t)); |
| 108 return static_cast<intptr_t>(id); | 108 return static_cast<intptr_t>(id); |
| 109 } | 109 } |
| 110 | 110 |
| 111 | 111 |
| 112 bool Thread::Compare(ThreadId a, ThreadId b) { | 112 bool Thread::Compare(ThreadId a, ThreadId b) { |
| 113 return (a == b); | 113 return (a == b); |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | |
| 118 static const int64_t kTimeEpoc = 116444736000000000LL; | |
| 119 static const int64_t kTimeScaler = 10; // 100 ns to us. | |
| 120 // Although win32 uses 64-bit integers for representing timestamps, | |
| 121 // these are packed into a FILETIME structure. The FILETIME | |
| 122 // structure is just a struct representing a 64-bit integer. The | |
| 123 // TimeStamp union allows access to both a FILETIME and an integer | |
| 124 // representation of the timestamp. The Windows timestamp is in | |
| 125 // 100-nanosecond intervals since January 1, 1601. | |
| 126 union TimeStamp { | |
| 127 FILETIME ft_; | |
| 128 int64_t t_; | |
| 129 }; | |
| 130 ASSERT(cpu_usage != NULL); | |
| 131 TimeStamp created; | |
| 132 TimeStamp exited; | |
| 133 TimeStamp kernel; | |
| 134 TimeStamp user; | |
| 135 HANDLE handle = OpenThread(THREAD_QUERY_INFORMATION, false, thread_id); | |
| 136 BOOL result = | |
| 137 GetThreadTimes(handle, &created.ft_, &exited.ft_, &kernel.ft_, &user.ft_); | |
| 138 CloseHandle(handle); | |
| 139 if (!result) { | |
| 140 FATAL1("GetThreadCpuUsage failed %d\n", GetLastError()); | |
| 141 } | |
| 142 *cpu_usage = (user.t_ - kTimeEpoc) / kTimeScaler; | |
| 143 } | |
| 144 | |
| 145 | |
| 146 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { | 117 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { |
| 147 ASSERT(key != kUnsetThreadLocalKey); | 118 ASSERT(key != kUnsetThreadLocalKey); |
| 148 BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value)); | 119 BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value)); |
| 149 if (!result) { | 120 if (!result) { |
| 150 FATAL1("TlsSetValue failed %d", GetLastError()); | 121 FATAL1("TlsSetValue failed %d", GetLastError()); |
| 151 } | 122 } |
| 152 } | 123 } |
| 153 | 124 |
| 154 | 125 |
| 155 void Thread::InitOnce() { | 126 void Thread::InitOnce() { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // signal. This will be treated as a spurious wake-up and is OK | 399 // signal. This will be treated as a spurious wake-up and is OK |
| 429 // since all uses of monitors should recheck the condition after a | 400 // since all uses of monitors should recheck the condition after a |
| 430 // Wait. | 401 // Wait. |
| 431 data_.SignalAndRemoveAllWaiters(); | 402 data_.SignalAndRemoveAllWaiters(); |
| 432 } | 403 } |
| 433 | 404 |
| 434 } // namespace bin | 405 } // namespace bin |
| 435 } // namespace dart | 406 } // namespace dart |
| 436 | 407 |
| 437 #endif // defined(TARGET_OS_WINDOWS) | 408 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |