diff options
author | 2017-06-29 11:59:50 -0700 | |
---|---|---|
committer | 2017-06-30 14:24:56 +0000 | |
commit | 46f9340f2a055a8fdfebbfbb739c697c20d83e7c (patch) | |
tree | acb172f74723e4ea9ac7ded73b94c661217ec90d /runtime/thread.cc | |
parent | fe9a4f061841a3c597aac6817a47c799c54fcad7 (diff) |
Add SuspendReason enum and change Suspension functions.
More self-documenting and more type safe.
Bug: 62821960
Test: ./test.py
Change-Id: Ic7a1ae6a25e687d65f5aa10c1aad54a7b80dd086
Diffstat (limited to 'runtime/thread.cc')
-rw-r--r-- | runtime/thread.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/thread.cc b/runtime/thread.cc index be1614b3cc..a81166640a 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -1178,10 +1178,10 @@ static void UnsafeLogFatalForSuspendCount(Thread* self, Thread* thread) NO_THREA bool Thread::ModifySuspendCountInternal(Thread* self, int delta, AtomicInteger* suspend_barrier, - bool for_debugger) { + SuspendReason reason) { if (kIsDebugBuild) { DCHECK(delta == -1 || delta == +1 || delta == -tls32_.debug_suspend_count) - << delta << " " << tls32_.debug_suspend_count << " " << this; + << reason << " " << 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()) { @@ -1217,8 +1217,12 @@ bool Thread::ModifySuspendCountInternal(Thread* self, } tls32_.suspend_count += delta; - if (for_debugger) { - tls32_.debug_suspend_count += delta; + switch (reason) { + case SuspendReason::kForDebugger: + tls32_.debug_suspend_count += delta; + break; + case SuspendReason::kInternal: + break; } if (tls32_.suspend_count == 0) { @@ -1458,7 +1462,7 @@ bool Thread::RequestSynchronousCheckpoint(Closure* function) { { MutexLock mu2(self, *Locks::thread_suspend_count_lock_); - if (!ModifySuspendCount(self, +1, nullptr, false)) { + if (!ModifySuspendCount(self, +1, nullptr, SuspendReason::kInternal)) { // Just retry the loop. sched_yield(); continue; @@ -1483,7 +1487,7 @@ bool Thread::RequestSynchronousCheckpoint(Closure* function) { MutexLock mu2(self, *Locks::thread_suspend_count_lock_); DCHECK_NE(GetState(), ThreadState::kRunnable); - bool updated = ModifySuspendCount(self, -1, nullptr, false); + bool updated = ModifySuspendCount(self, -1, nullptr, SuspendReason::kInternal); DCHECK(updated); } |