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

Unified Diff: runtime/vm/os_thread_win.cc

Issue 1275353005: VM thread shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os_thread_win.h ('k') | runtime/vm/service_isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_thread_win.cc
diff --git a/runtime/vm/os_thread_win.cc b/runtime/vm/os_thread_win.cc
index 126594910b55bc0cae7d1169ee3b59f25039a100..7af1ce41d96914a5ef52aff1cecf60ca71efc552 100644
--- a/runtime/vm/os_thread_win.cc
+++ b/runtime/vm/os_thread_win.cc
@@ -71,6 +71,7 @@ int OSThread::Start(ThreadStartFunction function, uword parameter) {
ThreadLocalKey OSThread::kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES;
ThreadId OSThread::kInvalidThreadId = 0;
+ThreadJoinId OSThread::kInvalidThreadJoinId = 0;
ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor unused) {
ThreadLocalKey key = TlsAlloc();
@@ -101,14 +102,29 @@ ThreadId OSThread::GetCurrentThreadId() {
}
-bool OSThread::Join(ThreadId id) {
+ThreadJoinId OSThread::GetCurrentThreadJoinId() {
+ return ::GetCurrentThreadId();
+}
+
+
+void OSThread::Join(ThreadJoinId id) {
HANDLE handle = OpenThread(SYNCHRONIZE, false, id);
- if (handle == INVALID_HANDLE_VALUE) {
- return false;
+
+ // TODO(zra): OSThread::Start() closes the handle to the thread. Thus, by the
+ // time we try to join the thread, its resources may have already been
+ // reclaimed, and joining will fail. This can be avoided in a couple of ways.
+ // First, GetCurrentThreadJoinId could call OpenThread and return a handle.
+ // This is bad, because each of those handles would have to be closed.
+ // Second OSThread could be refactored to no longer be AllStatic. Then the
+ // handle could be cached in the object by the Start method.
+ if (handle == NULL) {
+ ASSERT(GetLastError() == ERROR_INVALID_PARAMETER);
+ return;
}
+
DWORD res = WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
- return res == WAIT_OBJECT_0;
+ ASSERT(res == WAIT_OBJECT_0);
}
« no previous file with comments | « runtime/vm/os_thread_win.h ('k') | runtime/vm/service_isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698