| 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/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 | 69 |
| 70 void ThreadInterrupter::Startup() { | 70 void ThreadInterrupter::Startup() { |
| 71 ASSERT(initialized_); | 71 ASSERT(initialized_); |
| 72 if (FLAG_trace_thread_interrupter) { | 72 if (FLAG_trace_thread_interrupter) { |
| 73 OS::Print("ThreadInterrupter starting up.\n"); | 73 OS::Print("ThreadInterrupter starting up.\n"); |
| 74 } | 74 } |
| 75 ASSERT(interrupter_thread_id_ == OSThread::kInvalidThreadJoinId); | 75 ASSERT(interrupter_thread_id_ == OSThread::kInvalidThreadJoinId); |
| 76 { | 76 { |
| 77 MonitorLocker startup_ml(monitor_); | 77 MonitorLocker startup_ml(monitor_); |
| 78 OSThread::Start(ThreadMain, 0); | 78 OSThread::Start("ThreadInterrupter", ThreadMain, 0); |
| 79 while (!thread_running_) { | 79 while (!thread_running_) { |
| 80 startup_ml.Wait(); | 80 startup_ml.Wait(); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); | 83 ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadJoinId); |
| 84 if (FLAG_trace_thread_interrupter) { | 84 if (FLAG_trace_thread_interrupter) { |
| 85 OS::Print("ThreadInterrupter running.\n"); | 85 OS::Print("ThreadInterrupter running.\n"); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 void ThreadInterrupter::ThreadMain(uword parameters) { | 147 void ThreadInterrupter::ThreadMain(uword parameters) { |
| 148 ASSERT(initialized_); | 148 ASSERT(initialized_); |
| 149 InstallSignalHandler(); | 149 InstallSignalHandler(); |
| 150 if (FLAG_trace_thread_interrupter) { | 150 if (FLAG_trace_thread_interrupter) { |
| 151 OS::Print("ThreadInterrupter thread running.\n"); | 151 OS::Print("ThreadInterrupter thread running.\n"); |
| 152 } | 152 } |
| 153 { | 153 { |
| 154 // Signal to main thread we are ready. | 154 // Signal to main thread we are ready. |
| 155 MonitorLocker startup_ml(monitor_); | 155 MonitorLocker startup_ml(monitor_); |
| 156 interrupter_thread_id_ = OSThread::GetCurrentThreadJoinId(); | 156 OSThread* os_thread = OSThread::Current(); |
| 157 ASSERT(os_thread != NULL); |
| 158 interrupter_thread_id_ = os_thread->join_id(); |
| 157 thread_running_ = true; | 159 thread_running_ = true; |
| 158 startup_ml.Notify(); | 160 startup_ml.Notify(); |
| 159 } | 161 } |
| 160 { | 162 { |
| 161 intptr_t interrupted_thread_count = 0; | 163 intptr_t interrupted_thread_count = 0; |
| 162 current_wait_time_ = interrupt_period_; | 164 current_wait_time_ = interrupt_period_; |
| 163 MonitorLocker wait_ml(monitor_); | 165 MonitorLocker wait_ml(monitor_); |
| 164 while (!shutdown_) { | 166 while (!shutdown_) { |
| 165 intptr_t r = wait_ml.WaitMicros(current_wait_time_); | 167 intptr_t r = wait_ml.WaitMicros(current_wait_time_); |
| 166 | 168 |
| 167 if (shutdown_) { | 169 if (shutdown_) { |
| 168 break; | 170 break; |
| 169 } | 171 } |
| 170 | 172 |
| 171 if ((r == Monitor::kNotified) && InDeepSleep()) { | 173 if ((r == Monitor::kNotified) && InDeepSleep()) { |
| 172 // Woken up from deep sleep. | 174 // Woken up from deep sleep. |
| 173 ASSERT(interrupted_thread_count == 0); | 175 ASSERT(interrupted_thread_count == 0); |
| 174 // Return to regular interrupts. | 176 // Return to regular interrupts. |
| 175 current_wait_time_ = interrupt_period_; | 177 current_wait_time_ = interrupt_period_; |
| 176 } | 178 } |
| 177 | 179 |
| 178 // Reset count before interrupting any threads. | 180 // Reset count before interrupting any threads. |
| 179 interrupted_thread_count = 0; | 181 interrupted_thread_count = 0; |
| 180 | 182 |
| 181 // Temporarily drop the monitor while we interrupt threads. | 183 // Temporarily drop the monitor while we interrupt threads. |
| 182 monitor_->Exit(); | 184 monitor_->Exit(); |
| 183 | 185 |
| 184 { | 186 { |
| 185 ThreadIterator it; | 187 OSThreadIterator it; |
| 186 while (it.HasNext()) { | 188 while (it.HasNext()) { |
| 187 Thread* thread = it.Next(); | 189 OSThread* thread = it.Next(); |
| 188 if (thread->ThreadInterruptsEnabled()) { | 190 if (thread->ThreadInterruptsEnabled()) { |
| 189 interrupted_thread_count++; | 191 interrupted_thread_count++; |
| 190 InterruptThread(thread); | 192 InterruptThread(thread); |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
| 195 // Take the monitor lock again. | 197 // Take the monitor lock again. |
| 196 monitor_->Enter(); | 198 monitor_->Enter(); |
| 197 | 199 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 216 } | 218 } |
| 217 { | 219 { |
| 218 // Signal to main thread we are exiting. | 220 // Signal to main thread we are exiting. |
| 219 MonitorLocker shutdown_ml(monitor_); | 221 MonitorLocker shutdown_ml(monitor_); |
| 220 thread_running_ = false; | 222 thread_running_ = false; |
| 221 shutdown_ml.Notify(); | 223 shutdown_ml.Notify(); |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 } // namespace dart | 227 } // namespace dart |
| OLD | NEW |