Add ScopedThreadSuspension

Fixes the TransitionFromRunnableToSuspended and
TransitionFromSuspendedToRunnable pattern that was prone to errors.

Change-Id: Ie6ae9c0357c83b4fc4899d05dfa0975553170267
diff --git a/runtime/jdwp/jdwp_event.cc b/runtime/jdwp/jdwp_event.cc
index 5d21f17..06b67b3 100644
--- a/runtime/jdwp/jdwp_event.cc
+++ b/runtime/jdwp/jdwp_event.cc
@@ -623,7 +623,7 @@
   CHECK(pReq != nullptr);
   /* send request and possibly suspend ourselves */
   JDWP::ObjectId thread_self_id = Dbg::GetThreadSelfId();
-  self->TransitionFromRunnableToSuspended(kWaitingForDebuggerSend);
+  ScopedThreadSuspension sts(self, kWaitingForDebuggerSend);
   if (suspend_policy != SP_NONE) {
     AcquireJdwpTokenForEvent(threadId);
   }
@@ -633,7 +633,6 @@
     ScopedThreadStateChange stsc(self, kSuspended);
     SuspendByPolicy(suspend_policy, thread_self_id);
   }
-  self->TransitionFromSuspendedToRunnable();
 }
 
 /*
@@ -1323,9 +1322,8 @@
   }
   if (safe_to_release_mutator_lock_over_send) {
     // Change state to waiting to allow GC, ... while we're sending.
-    self->TransitionFromRunnableToSuspended(kWaitingForDebuggerSend);
+    ScopedThreadSuspension sts(self, kWaitingForDebuggerSend);
     SendBufferedRequest(type, wrapiov);
-    self->TransitionFromSuspendedToRunnable();
   } else {
     // Send and possibly block GC...
     SendBufferedRequest(type, wrapiov);