Bug 1213050 - Clean up TaskQueue before dropping references to it. r=cpearce, a=sledru
authorRandell Jesup <rjesup@jesup.org>
Thu, 12 May 2016 00:53:19 -0400
changeset 318954 b8dac4b0e8e0b87e1a72f6e5efc4f9acf73421fa
parent 318953 03754c55722d6a5edf08b715ef2489da9944d463
child 318955 b345678b3ef0837146b97351af63b07fb3ada692
push id9610
push userryanvm@gmail.com
push dateFri, 27 May 2016 14:45:39 +0000
treeherdermozilla-aurora@acc1985e7895 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sledru
bugs1213050
milestone48.0a2
Bug 1213050 - Clean up TaskQueue before dropping references to it. r=cpearce, a=sledru Also adds assertion TaskQueue isn't trying to kill itself MozReview-Commit-ID: 1AVuYcfnBBA
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
xpcom/threads/TaskQueue.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -208,23 +208,26 @@ public:
 
   bool RemoveListener(VideoConverterListener* aListener)
   {
     MutexAutoLock lock(mMutex);
 
     return mListeners.RemoveElement(aListener);
   }
 
+  void Shutdown()
+  {
+    mTaskQueue->BeginShutdown();
+    mTaskQueue->AwaitShutdownAndIdle();
+  }
+
 protected:
   virtual ~VideoFrameConverter()
   {
     MOZ_COUNT_DTOR(VideoFrameConverter);
-
-    mTaskQueue->BeginShutdown();
-    mTaskQueue->AwaitShutdownAndIdle();
   }
 
   void VideoFrameConverted(unsigned char* aVideoFrame,
                            unsigned int aVideoFrameLength,
                            unsigned short aWidth,
                            unsigned short aHeight,
                            VideoType aVideoType,
                            uint64_t aCaptureTime)
@@ -1112,16 +1115,21 @@ public:
                                             ConduitDeleteEvent(conduit_.forget()));
       MOZ_ASSERT(!NS_FAILED(rv),"Could not dispatch conduit shutdown to main");
       if (NS_FAILED(rv)) {
         MOZ_CRASH();
       }
     } else {
       conduit_ = nullptr;
     }
+#if !defined(MOZILLA_EXTERNAL_LINKAGE)
+    if (converter_) {
+      converter_->Shutdown();
+    }
+#endif
   }
 
   // Dispatches setting the internal TrackID to TRACK_INVALID to the media
   // graph thread to keep it in sync with other MediaStreamGraph operations
   // like RemoveListener() and AddListener(). The TrackID will be updated on
   // the next NewData() callback.
   void UnsetTrackId(MediaStreamGraphImpl* graph);
 
--- a/xpcom/threads/TaskQueue.cpp
+++ b/xpcom/threads/TaskQueue.cpp
@@ -94,16 +94,17 @@ TaskQueue::AwaitIdleLocked()
   while (mIsRunning) {
     mQueueMonitor.Wait();
   }
 }
 
 void
 TaskQueue::AwaitShutdownAndIdle()
 {
+  MOZ_ASSERT(!IsCurrentThreadIn());
   // Make sure there are no tasks for this queue waiting in the caller's tail
   // dispatcher.
   MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
                 !AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
 
   MonitorAutoLock mon(mQueueMonitor);
   while (!mIsShutdown) {
     mQueueMonitor.Wait();