Chromium Code Reviews| Index: runtime/vm/thread_interrupter.cc |
| diff --git a/runtime/vm/thread_interrupter.cc b/runtime/vm/thread_interrupter.cc |
| index 58c94bec797cc04dadc697d31c33db8dd7d31f8e..26063d08a97046c76d0f72c1d596acb4f9f47b5c 100644 |
| --- a/runtime/vm/thread_interrupter.cc |
| +++ b/runtime/vm/thread_interrupter.cc |
| @@ -124,6 +124,10 @@ void ThreadInterrupter::SetInterruptPeriod(intptr_t period) { |
| void ThreadInterrupter::WakeUp() { |
| + if (!initialized_) { |
| + // Early call. |
| + return; |
| + } |
| ASSERT(initialized_); |
| { |
| MonitorLocker ml(monitor_); |
| @@ -142,30 +146,6 @@ void ThreadInterruptNoOp(const InterruptedThreadState& state, void* data) { |
| } |
| -class ThreadInterrupterVisitIsolates : public IsolateVisitor { |
| - public: |
| - ThreadInterrupterVisitIsolates() { |
| - profiled_thread_count_ = 0; |
| - } |
| - |
| - void VisitIsolate(Isolate* isolate) { |
| - ASSERT(isolate != NULL); |
| - profiled_thread_count_ += isolate->ProfileInterrupt(); |
| - } |
| - |
| - intptr_t profiled_thread_count() const { |
| - return profiled_thread_count_; |
| - } |
| - |
| - void set_profiled_thread_count(intptr_t profiled_thread_count) { |
| - profiled_thread_count_ = profiled_thread_count; |
| - } |
| - |
| - private: |
| - intptr_t profiled_thread_count_; |
| -}; |
| - |
| - |
| void ThreadInterrupter::ThreadMain(uword parameters) { |
| ASSERT(initialized_); |
| InstallSignalHandler(); |
| @@ -180,7 +160,7 @@ void ThreadInterrupter::ThreadMain(uword parameters) { |
| startup_ml.Notify(); |
| } |
| { |
| - ThreadInterrupterVisitIsolates visitor; |
| + intptr_t interrupted_thread_count = 0; |
| current_wait_time_ = interrupt_period_; |
| MonitorLocker wait_ml(monitor_); |
| while (!shutdown_) { |
| @@ -192,17 +172,27 @@ void ThreadInterrupter::ThreadMain(uword parameters) { |
| if ((r == Monitor::kNotified) && InDeepSleep()) { |
| // Woken up from deep sleep. |
| - ASSERT(visitor.profiled_thread_count() == 0); |
| + ASSERT(interrupted_thread_count == 0); |
| // Return to regular interrupts. |
| current_wait_time_ = interrupt_period_; |
| } |
| - // Reset count before visiting isolates. |
| - visitor.set_profiled_thread_count(0); |
| - Isolate::VisitIsolates(&visitor); |
| + // Reset count before interrupting any threads. |
| + interrupted_thread_count = 0; |
| + |
|
siva
2015/10/26 23:45:26
Do we need to be holding the monitor_ lock here, w
Cutch
2015/10/27 22:36:24
Done.
|
| + { |
| + ThreadIterator it; |
| + while (it.HasNext()) { |
| + Thread* thread = it.Next(); |
| + if (thread->ThreadInterruptsEnabled()) { |
| + interrupted_thread_count++; |
| + InterruptThread(thread); |
| + } |
| + } |
| + } |
| - if (visitor.profiled_thread_count() == 0) { |
| - // No isolates were profiled. In order to reduce unnecessary CPU |
| + if (interrupted_thread_count == 0) { |
| + // No threads were interrupted. In order to reduce unnecessary CPU |
| // load, we will wait until we are notified before attempting to |
| // interrupt again. |
| current_wait_time_ = Monitor::kNoTimeout; |