Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: runtime/vm/os_thread_win.cc

Issue 1978153002: Uses an open thread handle as the ThreadJoinId on Windows. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 19 matching lines...) Expand all
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() {
134 // TODO(zra): Use the thread handle as the join id in order to have a more 134 HANDLE handle = OpenThread(SYNCHRONIZE, false, ::GetCurrentThreadId());
135 // reliable join on windows. 135 ASSERT(handle != NULL);
136 return ::GetCurrentThreadId(); 136 return handle;
137 } 137 }
138 138
139 139
140 void OSThread::Join(ThreadJoinId id) { 140 void OSThread::Join(ThreadJoinId id) {
141 HANDLE handle = OpenThread(SYNCHRONIZE, false, id); 141 HANDLE handle = static_cast<HANDLE>(id);
142 142 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); 143 DWORD res = WaitForSingleObject(handle, INFINITE);
155 CloseHandle(handle); 144 CloseHandle(handle);
156 ASSERT(res == WAIT_OBJECT_0); 145 ASSERT(res == WAIT_OBJECT_0);
siva 2016/05/16 17:59:27 Are all thread guaranteed to call OSThread::Join()
zra 2016/05/16 20:32:54 Changed to call GetCurrentThreadJoinId only for th
157 } 146 }
158 147
159 148
160 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { 149 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) {
161 ASSERT(sizeof(id) <= sizeof(intptr_t)); 150 ASSERT(sizeof(id) <= sizeof(intptr_t));
162 return static_cast<intptr_t>(id); 151 return static_cast<intptr_t>(id);
163 } 152 }
164 153
165 154
166 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { 155 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 #pragma data_seg(".CRT$XLB") 668 #pragma data_seg(".CRT$XLB")
680 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; 669 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit;
681 670
682 // Reset the default section. 671 // Reset the default section.
683 #pragma data_seg() 672 #pragma data_seg()
684 673
685 #endif // _WIN64 674 #endif // _WIN64
686 } // extern "C" 675 } // extern "C"
687 676
688 #endif // defined(TARGET_OS_WINDOWS) 677 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698