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" // NOLINT | 5 #include "platform/globals.h" // NOLINT |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "vm/growable_array.h" | 8 #include "vm/growable_array.h" |
9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 // Close the handle, so we don't leak the thread object. | 86 // Close the handle, so we don't leak the thread object. |
87 CloseHandle(reinterpret_cast<HANDLE>(thread)); | 87 CloseHandle(reinterpret_cast<HANDLE>(thread)); |
88 | 88 |
89 return 0; | 89 return 0; |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 const ThreadId OSThread::kInvalidThreadId = 0; | 93 const ThreadId OSThread::kInvalidThreadId = 0; |
94 const ThreadJoinId OSThread::kInvalidThreadJoinId = 0; | 94 const ThreadJoinId OSThread::kInvalidThreadJoinId = NULL; |
95 | 95 |
96 | 96 |
97 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { | 97 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { |
98 ThreadLocalKey key = TlsAlloc(); | 98 ThreadLocalKey key = TlsAlloc(); |
99 if (key == kUnsetThreadLocalKey) { | 99 if (key == kUnsetThreadLocalKey) { |
100 FATAL1("TlsAlloc failed %d", GetLastError()); | 100 FATAL1("TlsAlloc failed %d", GetLastError()); |
101 } | 101 } |
102 ThreadLocalData::AddThreadLocal(key, destructor); | 102 ThreadLocalData::AddThreadLocal(key, destructor); |
103 return key; | 103 return key; |
104 } | 104 } |
(...skipping 18 matching lines...) Expand all Loading... |
123 ThreadId OSThread::GetCurrentThreadId() { | 123 ThreadId OSThread::GetCurrentThreadId() { |
124 return ::GetCurrentThreadId(); | 124 return ::GetCurrentThreadId(); |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 ThreadId OSThread::GetCurrentThreadTraceId() { | 128 ThreadId OSThread::GetCurrentThreadTraceId() { |
129 return ::GetCurrentThreadId(); | 129 return ::GetCurrentThreadId(); |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 ThreadJoinId OSThread::GetCurrentThreadJoinId() { | 133 ThreadJoinId OSThread::GetCurrentThreadJoinId(OSThread* thread) { |
134 // TODO(zra): Use the thread handle as the join id in order to have a more | 134 ASSERT(thread != NULL); |
135 // reliable join on windows. | 135 // Make sure we're filling in the join id for the current thread. |
136 return ::GetCurrentThreadId(); | 136 ThreadId id = GetCurrentThreadId(); |
| 137 ASSERT(thread->id() == id); |
| 138 // Make sure the join_id_ hasn't been set, yet. |
| 139 DEBUG_ASSERT(thread->join_id_ == kInvalidThreadJoinId); |
| 140 HANDLE handle = OpenThread(SYNCHRONIZE, false, id); |
| 141 ASSERT(handle != NULL); |
| 142 #if defined(DEBUG) |
| 143 thread->join_id_ = handle; |
| 144 #endif |
| 145 return handle; |
137 } | 146 } |
138 | 147 |
139 | 148 |
140 void OSThread::Join(ThreadJoinId id) { | 149 void OSThread::Join(ThreadJoinId id) { |
141 HANDLE handle = OpenThread(SYNCHRONIZE, false, id); | 150 HANDLE handle = static_cast<HANDLE>(id); |
142 | 151 ASSERT(handle != NULL); |
143 // TODO(zra): OSThread::Start() closes the handle to the thread. Thus, by the | |
144 // time we try to join the thread, its resources may have already been | |
145 // reclaimed, and joining will fail. This can be avoided in a couple of ways. | |
146 // First, GetCurrentThreadJoinId could call OpenThread and return a handle. | |
147 // This is bad, because each of those handles would have to be closed. | |
148 // Second OSThread could be refactored to no longer be AllStatic. Then the | |
149 // handle could be cached in the object by the Start method. | |
150 if (handle == NULL) { | |
151 return; | |
152 } | |
153 | |
154 DWORD res = WaitForSingleObject(handle, INFINITE); | 152 DWORD res = WaitForSingleObject(handle, INFINITE); |
155 CloseHandle(handle); | 153 CloseHandle(handle); |
156 ASSERT(res == WAIT_OBJECT_0); | 154 ASSERT(res == WAIT_OBJECT_0); |
157 } | 155 } |
158 | 156 |
159 | 157 |
160 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { | 158 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { |
161 ASSERT(sizeof(id) <= sizeof(intptr_t)); | 159 ASSERT(sizeof(id) <= sizeof(intptr_t)); |
162 return static_cast<intptr_t>(id); | 160 return static_cast<intptr_t>(id); |
163 } | 161 } |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 #pragma data_seg(".CRT$XLB") | 677 #pragma data_seg(".CRT$XLB") |
680 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; | 678 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; |
681 | 679 |
682 // Reset the default section. | 680 // Reset the default section. |
683 #pragma data_seg() | 681 #pragma data_seg() |
684 | 682 |
685 #endif // _WIN64 | 683 #endif // _WIN64 |
686 } // extern "C" | 684 } // extern "C" |
687 | 685 |
688 #endif // defined(TARGET_OS_WINDOWS) | 686 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |