Bug 1640009 - Hold a reference to VRManager singleton for the duration of the parent shutdown. r=sotaro
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 28 May 2020 07:32:57 +0000
changeset 596503 f9f4bdf52d9b437a8a95484dd2563c4b45baabfd
parent 596502 867528d1d35bdec48758f8aa899b0491d7ef10e5
child 596504 d62da1a75701f8b1880bf11c37ac6673eef2fb7b
push id13186
push userffxbld-merge
push dateMon, 01 Jun 2020 09:52:46 +0000
treeherdermozilla-beta@3e7c70a1e4a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1640009
milestone78.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 1640009 - Hold a reference to VRManager singleton for the duration of the parent shutdown. r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D77205
gfx/vr/ipc/VRManagerParent.cpp
gfx/vr/ipc/VRManagerParent.h
--- a/gfx/vr/ipc/VRManagerParent.cpp
+++ b/gfx/vr/ipc/VRManagerParent.cpp
@@ -120,29 +120,29 @@ bool VRManagerParent::CreateForGPUProces
   CompositorThread()->Dispatch(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
       "gfx::VRManagerParent::Bind", vmp, &VRManagerParent::Bind,
       std::move(aEndpoint)));
   return true;
 }
 
 /*static*/
 void VRManagerParent::Shutdown() {
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(
+      CompositorThread(),
+      "Shutdown() must gets called before the compositor thread is shutdown");
   ReleaseVRManagerParentSingleton();
   CompositorThread()->Dispatch(NS_NewRunnableFunction(
       "VRManagerParent::Shutdown",
-      []() -> void { VRManagerParent::ShutdownInternal(); }));
-}
-
-/*static*/
-void VRManagerParent::ShutdownInternal() {
-  VRManager* vm = VRManager::MaybeGet();
-  if (!vm) {
-    return;
-  }
-  vm->ShutdownVRManagerParents();
+      [vm = RefPtr<VRManager>(VRManager::MaybeGet())]() -> void {
+        if (!vm) {
+          return;
+        }
+        vm->ShutdownVRManagerParents();
+      }));
 }
 
 void VRManagerParent::ActorDestroy(ActorDestroyReason why) {}
 
 void VRManagerParent::ActorDealloc() {
   UnregisterFromManager();
   mCompositorThreadHolder = nullptr;
   mSelfRef = nullptr;
--- a/gfx/vr/ipc/VRManagerParent.h
+++ b/gfx/vr/ipc/VRManagerParent.h
@@ -77,18 +77,16 @@ class VRManagerParent final : public PVR
   void ActorDealloc() override;
   void RegisterWithManager();
   void UnregisterFromManager();
 
   void Bind(Endpoint<PVRManagerParent>&& aEndpoint);
 
   static void RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager);
 
-  static void ShutdownInternal();
-
   // This keeps us alive until ActorDestroy(), at which point we do a
   // deferred destruction of ourselves.
   RefPtr<VRManagerParent> mSelfRef;
   // Keep the compositor thread alive, until we have destroyed ourselves.
   RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
 
   // Keep the VRManager alive, until we have destroyed ourselves.
   RefPtr<VRManager> mVRManagerHolder;