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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 union TimeStamp { | 126 union TimeStamp { |
127 FILETIME ft_; | 127 FILETIME ft_; |
128 int64_t t_; | 128 int64_t t_; |
129 }; | 129 }; |
130 ASSERT(cpu_usage != NULL); | 130 ASSERT(cpu_usage != NULL); |
131 TimeStamp created; | 131 TimeStamp created; |
132 TimeStamp exited; | 132 TimeStamp exited; |
133 TimeStamp kernel; | 133 TimeStamp kernel; |
134 TimeStamp user; | 134 TimeStamp user; |
135 HANDLE handle = OpenThread(THREAD_QUERY_INFORMATION, false, thread_id); | 135 HANDLE handle = OpenThread(THREAD_QUERY_INFORMATION, false, thread_id); |
136 BOOL result = GetThreadTimes(handle, | 136 BOOL result = |
137 &created.ft_, | 137 GetThreadTimes(handle, &created.ft_, &exited.ft_, &kernel.ft_, &user.ft_); |
138 &exited.ft_, | |
139 &kernel.ft_, | |
140 &user.ft_); | |
141 CloseHandle(handle); | 138 CloseHandle(handle); |
142 if (!result) { | 139 if (!result) { |
143 FATAL1("GetThreadCpuUsage failed %d\n", GetLastError()); | 140 FATAL1("GetThreadCpuUsage failed %d\n", GetLastError()); |
144 } | 141 } |
145 *cpu_usage = (user.t_ - kTimeEpoc) / kTimeScaler; | 142 *cpu_usage = (user.t_ - kTimeEpoc) / kTimeScaler; |
146 } | 143 } |
147 | 144 |
148 | 145 |
149 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { | 146 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { |
150 ASSERT(key != kUnsetThreadLocalKey); | 147 ASSERT(key != kUnsetThreadLocalKey); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EnterCriticalSection(&data_.cs_); | 224 EnterCriticalSection(&data_.cs_); |
228 } | 225 } |
229 | 226 |
230 | 227 |
231 void Monitor::Exit() { | 228 void Monitor::Exit() { |
232 LeaveCriticalSection(&data_.cs_); | 229 LeaveCriticalSection(&data_.cs_); |
233 } | 230 } |
234 | 231 |
235 | 232 |
236 void MonitorWaitData::ThreadExit() { | 233 void MonitorWaitData::ThreadExit() { |
237 if (MonitorWaitData::monitor_wait_data_key_ != | 234 if (MonitorWaitData::monitor_wait_data_key_ != Thread::kUnsetThreadLocalKey) { |
238 Thread::kUnsetThreadLocalKey) { | |
239 uword raw_wait_data = | 235 uword raw_wait_data = |
240 Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); | 236 Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); |
241 if (raw_wait_data != 0) { | 237 if (raw_wait_data != 0) { |
242 MonitorWaitData* wait_data = | 238 MonitorWaitData* wait_data = |
243 reinterpret_cast<MonitorWaitData*>(raw_wait_data); | 239 reinterpret_cast<MonitorWaitData*>(raw_wait_data); |
244 delete wait_data; | 240 delete wait_data; |
245 } | 241 } |
246 } | 242 } |
247 } | 243 } |
248 | 244 |
249 | 245 |
250 void MonitorData::AddWaiter(MonitorWaitData* wait_data) { | 246 void MonitorData::AddWaiter(MonitorWaitData* wait_data) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 340 |
345 MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() { | 341 MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() { |
346 // Ensure that the thread local key for monitor wait data objects is | 342 // Ensure that the thread local key for monitor wait data objects is |
347 // initialized. | 343 // initialized. |
348 ASSERT(MonitorWaitData::monitor_wait_data_key_ != | 344 ASSERT(MonitorWaitData::monitor_wait_data_key_ != |
349 Thread::kUnsetThreadLocalKey); | 345 Thread::kUnsetThreadLocalKey); |
350 | 346 |
351 // Get the MonitorWaitData object containing the event for this | 347 // Get the MonitorWaitData object containing the event for this |
352 // thread from thread local storage. Create it if it does not exist. | 348 // thread from thread local storage. Create it if it does not exist. |
353 uword raw_wait_data = | 349 uword raw_wait_data = |
354 Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); | 350 Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); |
355 MonitorWaitData* wait_data = NULL; | 351 MonitorWaitData* wait_data = NULL; |
356 if (raw_wait_data == 0) { | 352 if (raw_wait_data == 0) { |
357 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); | 353 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); |
358 wait_data = new MonitorWaitData(event); | 354 wait_data = new MonitorWaitData(event); |
359 Thread::SetThreadLocal(MonitorWaitData::monitor_wait_data_key_, | 355 Thread::SetThreadLocal(MonitorWaitData::monitor_wait_data_key_, |
360 reinterpret_cast<uword>(wait_data)); | 356 reinterpret_cast<uword>(wait_data)); |
361 } else { | 357 } else { |
362 wait_data = reinterpret_cast<MonitorWaitData*>(raw_wait_data); | 358 wait_data = reinterpret_cast<MonitorWaitData*>(raw_wait_data); |
363 wait_data->next_ = NULL; | 359 wait_data->next_ = NULL; |
364 } | 360 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // signal. This will be treated as a spurious wake-up and is OK | 428 // signal. This will be treated as a spurious wake-up and is OK |
433 // since all uses of monitors should recheck the condition after a | 429 // since all uses of monitors should recheck the condition after a |
434 // Wait. | 430 // Wait. |
435 data_.SignalAndRemoveAllWaiters(); | 431 data_.SignalAndRemoveAllWaiters(); |
436 } | 432 } |
437 | 433 |
438 } // namespace bin | 434 } // namespace bin |
439 } // namespace dart | 435 } // namespace dart |
440 | 436 |
441 #endif // defined(TARGET_OS_WINDOWS) | 437 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |