Bug 1491868 - Avoid shutdown hang by checking if VRListenerThread is null. r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 01 Oct 2018 21:36:23 +0000
changeset 494801 a2e5b2b30bfa6f6912f4af2df950284950e3fb16
parent 494800 825f10de78392d7f9578b7950b498cfc280ddcf5
child 494802 d3aa8681ce9dfedda6db70666ac8e59d09a5e4b1
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1491868
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1491868 - Avoid shutdown hang by checking if VRListenerThread is null. r=kip MozReview-Commit-ID: HbWlMUQGXD8 Differential Revision: https://phabricator.services.mozilla.com/D7220
gfx/vr/VRThread.cpp
--- a/gfx/vr/VRThread.cpp
+++ b/gfx/vr/VRThread.cpp
@@ -48,17 +48,20 @@ VRListenerThreadHolder::VRListenerThread
  : mThread(CreateThread())
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 VRListenerThreadHolder::~VRListenerThreadHolder()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  DestroyThread(mThread);
+
+  if (mThread) {
+    DestroyThread(mThread);
+  }
 }
 
 /* static */ void
 VRListenerThreadHolder::DestroyThread(base::Thread* aThread)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!sVRListenerThreadHolder,
              "We shouldn't be destroying the VR listener thread yet.");
@@ -93,24 +96,34 @@ VRListenerThreadHolder::CreateThread()
 
 void
 VRListenerThreadHolder::Start()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread!");
   MOZ_ASSERT(!sVRListenerThreadHolder, "The VR listener thread has already been started!");
   sFinishedVRListenerShutDown = false;
   sVRListenerThreadHolder = new VRListenerThreadHolder();
+
+  if (!sVRListenerThreadHolder->GetThread()) {
+    MOZ_ASSERT(false, "VR listener thread not started.");
+    sVRListenerThreadHolder = nullptr;
+  }
 }
 
 void
 VRListenerThreadHolder::Shutdown()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread!");
-  MOZ_ASSERT(sVRListenerThreadHolder, "The VR listener thread has already been shut down!");
   VRManager::StopVRListenerThreadTasks();
+
+  if (!sVRListenerThreadHolder) {
+    // We've already shutdown or never started.
+    return;
+  }
+
   sVRListenerThreadHolder = nullptr;
 
   SpinEventLoopUntil([&]() { return sFinishedVRListenerShutDown; });
 }
 
 /* static */ bool
 VRListenerThreadHolder::IsInVRListenerThread()
 {