Bug 1494513: Work around VRThread shutdown bug causing frequent intermittent failures. r=erahm
authorKris Maglione <maglione.k@gmail.com>
Thu, 27 Sep 2018 20:28:31 +0000
changeset 486954 b3657ab8de7bef220b9e5714fb52d0673eac3ac1
parent 486953 c64fc93a1be87e2131e7fa7f946f55a99cb63de7
child 486955 ba1fef7b14eb4fd87ae72231196ddf29cd5fc5a6
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewerserahm
bugs1494513
milestone64.0a1
Bug 1494513: Work around VRThread shutdown bug causing frequent intermittent failures. r=erahm Differential Revision: https://phabricator.services.mozilla.com/D7134
gfx/vr/VRThread.cpp
--- a/gfx/vr/VRThread.cpp
+++ b/gfx/vr/VRThread.cpp
@@ -1,15 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "VRThread.h"
+#include "nsDebug.h"
+#include "nsThreadManager.h"
 #include "nsThreadUtils.h"
 #include "VRManager.h"
 
 namespace mozilla {
 
 namespace gfx {
 
 static StaticRefPtr<VRListenerThreadHolder> sVRListenerThreadHolder;
@@ -156,17 +158,26 @@ VRThread::Start()
   mStarted = true;
   mLastActiveTime = TimeStamp::Now();
 }
 
 void
 VRThread::Shutdown()
 {
   if (mThread) {
-    mThread->Shutdown();
+    if (nsThreadManager::get().IsNSThread()) {
+      mThread->Shutdown();
+    } else {
+      NS_WARNING("VRThread::Shutdown() may only be called from an XPCOM thread");
+      NS_DispatchToMainThread(NS_NewRunnableFunction(
+        "VRThread::Shutdown",
+        [thread = mThread]() {
+          thread->Shutdown();
+        }));
+    }
     mThread = nullptr;
   }
   mStarted = false;
 }
 
 const nsCOMPtr<nsIThread>
 VRThread::GetThread() const
 {