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

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

Issue 1275353005: VM thread shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/thread_interrupter.h" 5 #include "vm/thread_interrupter.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 #include "vm/simulator.h" 10 #include "vm/simulator.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return; 94 return;
95 } 95 }
96 shutdown_ = true; 96 shutdown_ = true;
97 // Notify. 97 // Notify.
98 monitor_->Notify(); 98 monitor_->Notify();
99 ASSERT(initialized_); 99 ASSERT(initialized_);
100 if (FLAG_trace_thread_interrupter) { 100 if (FLAG_trace_thread_interrupter) {
101 OS::Print("ThreadInterrupter shutting down.\n"); 101 OS::Print("ThreadInterrupter shutting down.\n");
102 } 102 }
103 } 103 }
104 #if defined(TARGET_OS_WINDOWS) 104
105 // On Windows, a thread's exit-code can leak into the process's exit-code, 105 // Join the thread.
106 // if exiting 'at same time' as the process ends. By joining with the thread
107 // here, we avoid this race condition.
108 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadId); 106 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadId);
109 OSThread::Join(interrupter_thread_id_); 107 OSThread::Join(interrupter_thread_id_);
110 interrupter_thread_id_ = OSThread::kInvalidThreadId; 108 interrupter_thread_id_ = OSThread::kInvalidThreadId;
111 #else 109
112 // On non-Windows platforms, just wait for the thread interrupter to signal
113 // that it has exited the loop.
114 {
115 MonitorLocker shutdown_ml(monitor_);
116 while (thread_running_) {
117 // Wait for thread to exit.
118 shutdown_ml.Wait();
119 }
120 }
121 #endif
122 if (FLAG_trace_thread_interrupter) { 110 if (FLAG_trace_thread_interrupter) {
123 OS::Print("ThreadInterrupter shut down.\n"); 111 OS::Print("ThreadInterrupter shut down.\n");
124 } 112 }
125 } 113 }
126 114
127 // Delay between interrupts. 115 // Delay between interrupts.
128 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { 116 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) {
129 if (shutdown_) { 117 if (shutdown_) {
130 return; 118 return;
131 } 119 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 301 }
314 { 302 {
315 // Signal to main thread we are exiting. 303 // Signal to main thread we are exiting.
316 MonitorLocker shutdown_ml(monitor_); 304 MonitorLocker shutdown_ml(monitor_);
317 thread_running_ = false; 305 thread_running_ = false;
318 shutdown_ml.Notify(); 306 shutdown_ml.Notify();
319 } 307 }
320 } 308 }
321 309
322 } // namespace dart 310 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698