Bug 1202424 - Free shared memory when IPC system shuts down, not after. r=mrbkap
authorGian-Carlo Pascutto <gcp@mozilla.com>
Fri, 11 Sep 2015 09:33:36 +0200
changeset 295837 1ef643c92a6be6a06ff23cf2c62b01b7cf8e7503
parent 295836 4f79f9bd1754849a235097d26a6bce60deccb27b
child 295838 b6db43f49b67b732235d58977fe4b836e47e20a0
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1202424
milestone43.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 1202424 - Free shared memory when IPC system shuts down, not after. r=mrbkap
dom/media/systemservices/CamerasParent.cpp
dom/media/systemservices/CamerasParent.h
--- a/dom/media/systemservices/CamerasParent.cpp
+++ b/dom/media/systemservices/CamerasParent.cpp
@@ -761,16 +761,28 @@ CamerasParent::RecvStopCapture(const int
       }
       return NS_OK;
     });
 
   mVideoCaptureThread->message_loop()->PostTask(FROM_HERE, new RunnableTask(webrtc_runnable));
   return SendReplySuccess();
 }
 
+void
+CamerasParent::StopIPC()
+{
+  MOZ_ASSERT(!mDestroyed);
+  // Release shared memory now, it's our last chance
+  mShmemPool.Cleanup(this);
+  // We don't want to receive callbacks or anything if we can't
+  // forward them anymore anyway.
+  mChildIsAlive = false;
+  mDestroyed = true;
+}
+
 bool
 CamerasParent::RecvAllDone()
 {
   LOG((__PRETTY_FUNCTION__));
   // Don't try to send anything to the child now
   mChildIsAlive = false;
   return Send__delete__(this);
 }
@@ -786,38 +798,33 @@ void CamerasParent::DoShutdown()
       if (mEngines[i].mEngine) {
         mEngines[i].mEngine->SetTraceCallback(nullptr);
         webrtc::VideoEngine::Delete(mEngines[i].mEngine);
         mEngines[i].mEngine = nullptr;
       }
     }
   }
 
-  mShmemPool.Cleanup(this);
-
   mPBackgroundThread = nullptr;
 
   if (mVideoCaptureThread) {
     if (mVideoCaptureThread->IsRunning()) {
       mVideoCaptureThread->Stop();
     }
     delete mVideoCaptureThread;
     mVideoCaptureThread = nullptr;
   }
 }
 
 void
 CamerasParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   // No more IPC from here
   LOG((__PRETTY_FUNCTION__));
-  // We don't want to receive callbacks or anything if we can't
-  // forward them anymore anyway.
-  mChildIsAlive = false;
-  mDestroyed = true;
+  StopIPC();
   CloseEngines();
 }
 
 CamerasParent::CamerasParent()
   : mCallbackMutex("CamerasParent.mCallbackMutex"),
     mEngineMutex("CamerasParent.mEngineMutex"),
     mShmemPool(CaptureEngine::MaxEngine),
     mVideoCaptureThread(nullptr),
--- a/dom/media/systemservices/CamerasParent.h
+++ b/dom/media/systemservices/CamerasParent.h
@@ -112,16 +112,17 @@ public:
 
 protected:
   virtual ~CamerasParent();
 
   bool SetupEngine(CaptureEngine aCapEngine);
   void CloseEngines();
   bool EnsureInitialized(int aEngine);
   void DoShutdown();
+  void StopIPC();
 
   EngineHelper mEngines[CaptureEngine::MaxEngine];
   nsTArray<CallbackHelper*> mCallbacks;
   // Protects the callback arrays
   Mutex mCallbackMutex;
   // Protects the engines array
   Mutex mEngineMutex;