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