[kernel] Update Fuchsia suspend to use new API.

The old zx_task_suspend is being replaced with zx_task_suspend_token
which eliminates the possibility that suspends can get leaked due to
crashes.

Change-Id: Ib7df2494a013b899c98d03d9ceeb0cc9de2ea6b4
Reviewed-on: https://dart-review.googlesource.com/60204
Reviewed-by: Zach Anderson <zra@google.com>
diff --git a/runtime/vm/thread_interrupter_fuchsia.cc b/runtime/vm/thread_interrupter_fuchsia.cc
index 375f98d..d2f19c6 100644
--- a/runtime/vm/thread_interrupter_fuchsia.cc
+++ b/runtime/vm/thread_interrupter_fuchsia.cc
@@ -37,8 +37,8 @@
 class ThreadSuspendScope {
  public:
   explicit ThreadSuspendScope(zx_handle_t thread_handle)
-      : thread_handle_(thread_handle), suspended_(true) {
-    zx_status_t status = zx_task_suspend(thread_handle);
+      : thread_handle_(thread_handle), suspend_token_(ZX_HANDLE_INVALID) {
+    zx_status_t status = zx_task_suspend_token(thread_handle, &suspend_token_);
     // If a thread is somewhere where suspend is impossible, zx_task_suspend()
     // can return ZX_ERR_NOT_SUPPORTED.
     if (status != ZX_OK) {
@@ -46,27 +46,21 @@
         OS::PrintErr("ThreadInterrupter: zx_task_suspend failed: %s\n",
                      zx_status_get_string(status));
       }
-      suspended_ = false;
     }
   }
 
   ~ThreadSuspendScope() {
-    if (suspended_) {
-      zx_status_t status = zx_task_resume(thread_handle_, 0);
-      if (status != ZX_OK) {
-        // If we fail to resume a thread, then it's likely the program will
-        // hang. Crash instead.
-        FATAL1("zx_task_resume failed: %s", zx_status_get_string(status));
-      }
+    if (suspend_token_ != ZX_HANDLE_INVALID) {
+      zx_handle_close(suspend_token_);
     }
     zx_handle_close(thread_handle_);
   }
 
-  bool suspended() const { return suspended_; }
+  bool suspended() const { return suspend_token_ != ZX_HANDLE_INVALID; }
 
  private:
   zx_handle_t thread_handle_;
-  bool suspended_;
+  zx_handle_t suspend_token_;  // ZX_HANDLE_INVALID when not suspended.
 
   DISALLOW_ALLOCATION();
   DISALLOW_COPY_AND_ASSIGN(ThreadSuspendScope);