| OLD | NEW |
| 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/simulator.h" | 5 #include "vm/simulator.h" |
| 6 #include "vm/thread_interrupter.h" | 6 #include "vm/thread_interrupter.h" |
| 7 | 7 |
| 8 namespace dart { | 8 namespace dart { |
| 9 | 9 |
| 10 // Notes: | 10 // Notes: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 ASSERT(interrupter_thread_id_ != Thread::kInvalidThreadId); | 81 ASSERT(interrupter_thread_id_ != Thread::kInvalidThreadId); |
| 82 if (FLAG_trace_thread_interrupter) { | 82 if (FLAG_trace_thread_interrupter) { |
| 83 OS::Print("ThreadInterrupter running.\n"); | 83 OS::Print("ThreadInterrupter running.\n"); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 void ThreadInterrupter::Shutdown() { | 88 void ThreadInterrupter::Shutdown() { |
| 89 if (shutdown_) { | |
| 90 // Already shutdown. | |
| 91 return; | |
| 92 } | |
| 93 ASSERT(initialized_); | |
| 94 if (FLAG_trace_thread_interrupter) { | |
| 95 OS::Print("ThreadInterrupter shutting down.\n"); | |
| 96 } | |
| 97 { | |
| 98 MonitorLocker ml(monitor_); | |
| 99 shutdown_ = true; | |
| 100 } | |
| 101 { | 89 { |
| 102 MonitorLocker shutdown_ml(monitor_); | 90 MonitorLocker shutdown_ml(monitor_); |
| 91 if (shutdown_) { |
| 92 // Already shutdown. |
| 93 return; |
| 94 } |
| 95 shutdown_ = true; |
| 96 ASSERT(initialized_); |
| 97 if (FLAG_trace_thread_interrupter) { |
| 98 OS::Print("ThreadInterrupter shutting down.\n"); |
| 99 } |
| 103 while (thread_running_) { | 100 while (thread_running_) { |
| 104 shutdown_ml.Wait(); | 101 shutdown_ml.Wait(); |
| 105 } | 102 } |
| 103 // Join in the interrupter thread. On Windows, a thread's exit-code can |
| 104 // leak into the process's exit-code, if exiting 'at same time' as the |
| 105 // process ends. |
| 106 if (interrupter_thread_id_ != Thread::kInvalidThreadId) { |
| 107 Thread::Join(interrupter_thread_id_); |
| 108 interrupter_thread_id_ = Thread::kInvalidThreadId; |
| 109 } |
| 106 } | 110 } |
| 107 interrupter_thread_id_ = Thread::kInvalidThreadId; | |
| 108 if (FLAG_trace_thread_interrupter) { | 111 if (FLAG_trace_thread_interrupter) { |
| 109 OS::Print("ThreadInterrupter shut down.\n"); | 112 OS::Print("ThreadInterrupter shut down.\n"); |
| 110 } | 113 } |
| 111 } | 114 } |
| 112 | 115 |
| 113 // Delay between interrupts. | 116 // Delay between interrupts. |
| 114 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { | 117 void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { |
| 115 if (shutdown_) { | 118 if (shutdown_) { |
| 116 return; | 119 return; |
| 117 } | 120 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 230 |
| 228 void ThreadInterrupter::ThreadMain(uword parameters) { | 231 void ThreadInterrupter::ThreadMain(uword parameters) { |
| 229 ASSERT(initialized_); | 232 ASSERT(initialized_); |
| 230 InstallSignalHandler(); | 233 InstallSignalHandler(); |
| 231 if (FLAG_trace_thread_interrupter) { | 234 if (FLAG_trace_thread_interrupter) { |
| 232 OS::Print("ThreadInterrupter thread running.\n"); | 235 OS::Print("ThreadInterrupter thread running.\n"); |
| 233 } | 236 } |
| 234 { | 237 { |
| 235 // Signal to main thread we are ready. | 238 // Signal to main thread we are ready. |
| 236 MonitorLocker startup_ml(monitor_); | 239 MonitorLocker startup_ml(monitor_); |
| 240 interrupter_thread_id_ = Thread::GetCurrentThreadId(); |
| 237 thread_running_ = true; | 241 thread_running_ = true; |
| 238 interrupter_thread_id_ = Thread::GetCurrentThreadId(); | |
| 239 startup_ml.Notify(); | 242 startup_ml.Notify(); |
| 240 } | 243 } |
| 241 { | 244 { |
| 242 MonitorLocker wait_ml(monitor_); | 245 MonitorLocker wait_ml(monitor_); |
| 243 ThreadInterrupterVisitIsolates visitor; | 246 ThreadInterrupterVisitIsolates visitor; |
| 244 while (!shutdown_) { | 247 while (!shutdown_) { |
| 245 Isolate::VisitIsolates(&visitor); | 248 Isolate::VisitIsolates(&visitor); |
| 246 wait_ml.WaitMicros(interrupt_period_); | 249 wait_ml.WaitMicros(interrupt_period_); |
| 247 } | 250 } |
| 248 } | 251 } |
| 249 if (FLAG_trace_thread_interrupter) { | 252 if (FLAG_trace_thread_interrupter) { |
| 250 OS::Print("ThreadInterrupter thread exiting.\n"); | 253 OS::Print("ThreadInterrupter thread exiting.\n"); |
| 251 } | 254 } |
| 252 { | 255 { |
| 253 // Signal to main thread we are exiting. | 256 // Signal to main thread we are exiting. |
| 254 MonitorLocker shutdown_ml(monitor_); | 257 MonitorLocker shutdown_ml(monitor_); |
| 255 thread_running_ = false; | 258 thread_running_ = false; |
| 256 shutdown_ml.Notify(); | 259 shutdown_ml.Notify(); |
| 257 } | 260 } |
| 258 } | 261 } |
| 259 | 262 |
| 260 } // namespace dart | 263 } // namespace dart |
| OLD | NEW |