| 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 | 9 |
| 10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 ThreadId Thread::GetCurrentThreadId() { | 100 ThreadId Thread::GetCurrentThreadId() { |
| 101 return ::GetCurrentThreadId(); | 101 return ::GetCurrentThreadId(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 bool Thread::Join(ThreadId id) { | 105 bool Thread::Join(ThreadId id) { |
| 106 HANDLE handle = OpenThread(SYNCHRONIZE, false, id); | 106 HANDLE handle = OpenThread(SYNCHRONIZE, false, id); |
| 107 if (handle == INVALID_HANDLE_VALUE) { | 107 |
| 108 // TODO(zra): OSThread::Start() closes the handle to the thread. Thus, by the |
| 109 // time we try to join the thread, its resources may have already been |
| 110 // reclaimed, and joining will fail. This can be avoided in a couple of ways. |
| 111 // First, GetCurrentThreadJoinId could call OpenThread and return a handle. |
| 112 // This is bad, because each of those handles would have to be closed. |
| 113 // Second OSThread could be refactored to no longer be AllStatic. Then the |
| 114 // handle could be cached in the object by the Start method. |
| 115 if (handle == NULL) { |
| 108 return false; | 116 return false; |
| 109 } | 117 } |
| 118 |
| 110 DWORD res = WaitForSingleObject(handle, INFINITE); | 119 DWORD res = WaitForSingleObject(handle, INFINITE); |
| 111 CloseHandle(handle); | 120 CloseHandle(handle); |
| 112 return res == WAIT_OBJECT_0; | 121 ASSERT(res == WAIT_OBJECT_0); |
| 122 return true; |
| 113 } | 123 } |
| 114 | 124 |
| 115 | 125 |
| 116 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { | 126 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { |
| 117 ASSERT(sizeof(id) <= sizeof(intptr_t)); | 127 ASSERT(sizeof(id) <= sizeof(intptr_t)); |
| 118 return static_cast<intptr_t>(id); | 128 return static_cast<intptr_t>(id); |
| 119 } | 129 } |
| 120 | 130 |
| 121 | 131 |
| 122 bool Thread::Compare(ThreadId a, ThreadId b) { | 132 bool Thread::Compare(ThreadId a, ThreadId b) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // signal. This will be treated as a spurious wake-up and is OK | 448 // signal. This will be treated as a spurious wake-up and is OK |
| 439 // since all uses of monitors should recheck the condition after a | 449 // since all uses of monitors should recheck the condition after a |
| 440 // Wait. | 450 // Wait. |
| 441 data_.SignalAndRemoveAllWaiters(); | 451 data_.SignalAndRemoveAllWaiters(); |
| 442 } | 452 } |
| 443 | 453 |
| 444 } // namespace bin | 454 } // namespace bin |
| 445 } // namespace dart | 455 } // namespace dart |
| 446 | 456 |
| 447 #endif // defined(TARGET_OS_WINDOWS) | 457 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |