Add ScopedThreadSuspension
Fixes the TransitionFromRunnableToSuspended and
TransitionFromSuspendedToRunnable pattern that was prone to errors.
Change-Id: Ie6ae9c0357c83b4fc4899d05dfa0975553170267
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index c553a18..b59edc9 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1604,14 +1604,11 @@
// Since FlushAllocStack() above resets the (active) allocation
// stack. Need to revoke the thread-local allocation stacks that
// point into it.
- {
- self->TransitionFromRunnableToSuspended(kNative);
- ThreadList* thread_list = Runtime::Current()->GetThreadList();
- thread_list->SuspendAll(__FUNCTION__);
- heap->RevokeAllThreadLocalAllocationStacks(self);
- thread_list->ResumeAll();
- self->TransitionFromSuspendedToRunnable();
- }
+ ScopedThreadSuspension sts(self, kNative);
+ ThreadList* thread_list = Runtime::Current()->GetThreadList();
+ thread_list->SuspendAll(__FUNCTION__);
+ heap->RevokeAllThreadLocalAllocationStacks(self);
+ thread_list->ResumeAll();
}
{
// Mark dex caches.