diff options
-rw-r--r-- | runtime/thread.cc | 14 | ||||
-rw-r--r-- | runtime/thread_list.cc | 13 |
2 files changed, 14 insertions, 13 deletions
diff --git a/runtime/thread.cc b/runtime/thread.cc index b802882c13..29d011ca91 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -598,12 +598,14 @@ static void UnsafeLogFatalForSuspendCount(Thread* self, Thread* thread) NO_THREA } void Thread::ModifySuspendCount(Thread* self, int delta, bool for_debugger) { - DCHECK(delta == -1 || delta == +1 || delta == -tls32_.debug_suspend_count) - << delta << " " << tls32_.debug_suspend_count << " " << this; - DCHECK_GE(tls32_.suspend_count, tls32_.debug_suspend_count) << this; - Locks::thread_suspend_count_lock_->AssertHeld(self); - if (this != self && !IsSuspended()) { - Locks::thread_list_lock_->AssertHeld(self); + if (kIsDebugBuild) { + DCHECK(delta == -1 || delta == +1 || delta == -tls32_.debug_suspend_count) + << delta << " " << tls32_.debug_suspend_count << " " << this; + DCHECK_GE(tls32_.suspend_count, tls32_.debug_suspend_count) << this; + Locks::thread_suspend_count_lock_->AssertHeld(self); + if (this != self && !IsSuspended()) { + Locks::thread_list_lock_->AssertHeld(self); + } } if (UNLIKELY(delta < 0 && tls32_.suspend_count <= 0)) { UnsafeLogFatalForSuspendCount(self, this); diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index 09337802bf..7de9433b24 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -750,14 +750,13 @@ void ThreadList::Register(Thread* self) { MutexLock mu(self, *Locks::thread_list_lock_); MutexLock mu2(self, *Locks::thread_suspend_count_lock_); CHECK_GE(suspend_all_count_, debug_suspend_all_count_); - if (debug_suspend_all_count_ > 0) { - self->ModifySuspendCount(self, debug_suspend_all_count_, true); + // Modify suspend count in increments of 1 to maintain invariants in ModifySuspendCount. While + // this isn't particularly efficient the suspend counts are most commonly 0 or 1. + for (int delta = debug_suspend_all_count_; delta > 0; delta--) { + self->ModifySuspendCount(self, +1, true); } - if (suspend_all_count_ > 0) { - int delta = suspend_all_count_ - debug_suspend_all_count_; - if (delta > 0) { - self->ModifySuspendCount(self, delta, false); - } + for (int delta = suspend_all_count_ - debug_suspend_all_count_; delta > 0; delta--) { + self->ModifySuspendCount(self, +1, false); } CHECK(!Contains(self)); list_.push_back(self); |