Fix a race condition between VideoBridge and Compositor thread shutdown. (bug 1356365, r=mattwoodrow)
authorDavid Anderson <dvander@alliedmods.net>
Thu, 20 Apr 2017 19:32:48 -0700
changeset 566360 9fd7a385411f928649da4e53446f0c2327d72d9c
parent 566359 d8fb7831a005fd6dea8d29bad50dfc3de3480993
child 566361 fcd98542af390cfb873aee712e43388c779b07e6
push id55180
push userjjong@mozilla.com
push dateFri, 21 Apr 2017 09:36:13 +0000
reviewersmattwoodrow
bugs1356365
milestone55.0a1
Fix a race condition between VideoBridge and Compositor thread shutdown. (bug 1356365, r=mattwoodrow)
gfx/ipc/VsyncBridgeParent.cpp
gfx/ipc/VsyncBridgeParent.h
gfx/layers/ipc/VideoBridgeParent.cpp
gfx/layers/ipc/VideoBridgeParent.h
--- a/gfx/ipc/VsyncBridgeParent.cpp
+++ b/gfx/ipc/VsyncBridgeParent.cpp
@@ -20,16 +20,17 @@ VsyncBridgeParent::Start(Endpoint<PVsync
 
   return parent;
 }
 
 VsyncBridgeParent::VsyncBridgeParent()
  : mOpen(false)
 {
   MOZ_COUNT_CTOR(VsyncBridgeParent);
+  mCompositorThreadRef = CompositorThreadHolder::GetSingleton();
 }
 
 VsyncBridgeParent::~VsyncBridgeParent()
 {
   MOZ_COUNT_DTOR(VsyncBridgeParent);
 }
 
 void
@@ -70,16 +71,17 @@ VsyncBridgeParent::ShutdownImpl()
     mOpen = false;
   }
 }
 
 void
 VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   mOpen = false;
+  mCompositorThreadRef = nullptr;
 }
 
 void
 VsyncBridgeParent::DeallocPVsyncBridgeParent()
 {
   Release();
 }
 
--- a/gfx/ipc/VsyncBridgeParent.h
+++ b/gfx/ipc/VsyncBridgeParent.h
@@ -5,16 +5,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef include_gfx_ipc_VsyncBridgeParent_h
 #define include_gfx_ipc_VsyncBridgeParent_h
 
 #include "mozilla/RefPtr.h"
 #include "mozilla/gfx/PVsyncBridgeParent.h"
 
 namespace mozilla {
+namespace layers {
+class CompositorThreadHolder;
+} // namespace layers
+
 namespace gfx {
 
 class VsyncBridgeParent final : public PVsyncBridgeParent
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncBridgeParent)
 
   static RefPtr<VsyncBridgeParent> Start(Endpoint<PVsyncBridgeParent>&& aEndpoint);
@@ -29,14 +33,15 @@ private:
   VsyncBridgeParent();
   ~VsyncBridgeParent();
 
   void Open(Endpoint<PVsyncBridgeParent>&& aEndpoint);
   void ShutdownImpl();
 
 private:
   bool mOpen;
+  RefPtr<layers::CompositorThreadHolder> mCompositorThreadRef;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif // include_gfx_ipc_VsyncBridgeParent_h
--- a/gfx/layers/ipc/VideoBridgeParent.cpp
+++ b/gfx/layers/ipc/VideoBridgeParent.cpp
@@ -1,31 +1,32 @@
 /* vim: set ts=2 sw=2 et tw=80: */
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 "VideoBridgeParent.h"
+#include "CompositorThread.h"
 #include "mozilla/layers/TextureHost.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::ipc;
 using namespace mozilla::gfx;
 
-
 static VideoBridgeParent* sVideoBridgeSingleton;
 
 VideoBridgeParent::VideoBridgeParent()
   : mClosed(false)
 {
   mSelfRef = this;
   sVideoBridgeSingleton = this;
+  mCompositorThreadRef = CompositorThreadHolder::GetSingleton();
 }
 
 VideoBridgeParent::~VideoBridgeParent()
 {
   sVideoBridgeSingleton = nullptr;
 }
 
 /* static */ VideoBridgeParent*
@@ -45,16 +46,17 @@ VideoBridgeParent::ActorDestroy(ActorDes
 {
   // Can't alloc/dealloc shmems from now on.
   mClosed = true;
 }
 
 void
 VideoBridgeParent::DeallocPVideoBridgeParent()
 {
+  mCompositorThreadRef = nullptr;
   mSelfRef = nullptr;
 }
 
 PTextureParent*
 VideoBridgeParent::AllocPTextureParent(const SurfaceDescriptor& aSharedData,
                                        const LayersBackend& aLayersBackend,
                                        const TextureFlags& aFlags,
                                        const uint64_t& aSerial)
--- a/gfx/layers/ipc/VideoBridgeParent.h
+++ b/gfx/layers/ipc/VideoBridgeParent.h
@@ -7,16 +7,18 @@
 #define gfx_layers_ipc_VideoBridgeParent_h_
 
 #include "mozilla/layers/PVideoBridgeParent.h"
 #include "mozilla/layers/ISurfaceAllocator.h"
 
 namespace mozilla {
 namespace layers {
 
+class CompositorThreadHolder;
+
 class VideoBridgeParent final : public PVideoBridgeParent,
                                 public HostIPCAllocator,
                                 public ShmemAllocator
 {
 public:
   VideoBridgeParent();
   ~VideoBridgeParent();
 
@@ -56,16 +58,17 @@ public:
   void DeallocShmem(ipc::Shmem& aShmem) override;
 
 private:
   void DeallocPVideoBridgeParent() override;
 
   // This keeps us alive until ActorDestroy(), at which point we do a
   // deferred destruction of ourselves.
   RefPtr<VideoBridgeParent> mSelfRef;
+  RefPtr<CompositorThreadHolder> mCompositorThreadRef;
 
   std::map<uint64_t, PTextureParent*> mTextureMap;
 
   bool mClosed;
 };
 
 } // namespace layers
 } // namespace mozilla