bug 1196632 pass ownership of runnables to NS_DispatchToMainThread r=jesup
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 20 Aug 2015 09:52:56 +1200
changeset 258793 b3ef0a1e1f6c0edf397d66afedc5f94203f7f68d
parent 258792 e0ea78681089f3a763a7b0dd8bfb7eb8ac643488
child 258794 621d3dc058a371fac9bdd4a8744ef424e8358fea
push id29263
push userryanvm@gmail.com
push dateSun, 23 Aug 2015 21:18:49 +0000
treeherdermozilla-central@4ccdd06e51d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1196632
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 1196632 pass ownership of runnables to NS_DispatchToMainThread r=jesup The already_AddRefed<nsIRunnable>&& overload saves some ref-counting and provides an assertion if called too late in shutdown.
dom/media/MediaStreamGraph.cpp
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1711,17 +1711,17 @@ MediaStreamGraphImpl::RunInStableState(b
         // Complete shutdown. First, ensure that this graph is no longer used.
         // A new graph graph will be created if one is needed.
         // Asynchronously clean up old graph. We don't want to do this
         // synchronously because it spins the event loop waiting for threads
         // to shut down, and we don't want to do that in a stable state handler.
         mLifecycleState = LIFECYCLE_WAITING_FOR_THREAD_SHUTDOWN;
         LIFECYCLE_LOG("Sending MediaStreamGraphShutDownRunnable %p", this);
         nsCOMPtr<nsIRunnable> event = new MediaStreamGraphShutDownRunnable(this );
-        NS_DispatchToMainThread(event);
+        NS_DispatchToMainThread(event.forget());
 
         LIFECYCLE_LOG("Disconnecting MediaStreamGraph %p", this);
         MediaStreamGraphImpl* graph;
         if (gGraphs.Get(mAudioChannel, &graph) && graph == this) {
           // null out gGraph if that's the graph being shut down
           gGraphs.Remove(mAudioChannel);
         }
       }
@@ -1782,17 +1782,17 @@ MediaStreamGraphImpl::RunInStableState(b
         controlMessagesToRunDuringShutdown.AppendElements(Move(mb.mMessages));
       }
       mBackMessageQueue.Clear();
       MOZ_ASSERT(mCurrentTaskMessageQueue.IsEmpty());
       // Stop MediaStreamGraph threads. Do not clear gGraph since
       // we have outstanding DOM objects that may need it.
       mLifecycleState = LIFECYCLE_WAITING_FOR_THREAD_SHUTDOWN;
       nsCOMPtr<nsIRunnable> event = new MediaStreamGraphShutDownRunnable(this);
-      NS_DispatchToMainThread(event);
+      NS_DispatchToMainThread(event.forget());
     }
 
     mDetectedNotRunning = mLifecycleState > LIFECYCLE_RUNNING;
   }
 
   // Make sure we get a new current time in the next event loop task
   if (!aSourceIsMSG) {
     MOZ_ASSERT(mPostedRunInStableState);
@@ -1841,17 +1841,17 @@ void
 MediaStreamGraphImpl::EnsureStableStateEventPosted()
 {
   mMonitor.AssertCurrentThreadOwns();
 
   if (mPostedRunInStableStateEvent)
     return;
   mPostedRunInStableStateEvent = true;
   nsCOMPtr<nsIRunnable> event = new MediaStreamGraphStableStateRunnable(this, true);
-  NS_DispatchToMainThread(event);
+  NS_DispatchToMainThread(event.forget());
 }
 
 void
 MediaStreamGraphImpl::AppendMessage(ControlMessage* aMessage)
 {
   MOZ_ASSERT(NS_IsMainThread(), "main thread only");
   MOZ_ASSERT(!aMessage->GetStream() ||
              !aMessage->GetStream()->IsDestroyed(),
@@ -2406,17 +2406,17 @@ MediaStream::AddMainThreadListener(MainT
 
   private:
     ~NotifyRunnable() {}
 
     nsRefPtr<MediaStream> mStream;
   };
 
   nsRefPtr<nsRunnable> runnable = new NotifyRunnable(this);
-  if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(runnable)))) {
+  if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(runnable.forget())))) {
     return;
   }
 
   mNotificationMainThreadRunnable = runnable;
 }
 
 void
 SourceMediaStream::DestroyImpl()
@@ -3213,21 +3213,21 @@ MediaStreamGraph::NotifyWhenGraphStarted
       // This runs on the graph thread, so when this runs, and the current
       // driver is an AudioCallbackDriver, we know the audio hardware is
       // started. If not, we are going to switch soon, keep reposting this
       // ControlMessage.
       MediaStreamGraphImpl* graphImpl = mStream->GraphImpl();
       if (graphImpl->CurrentDriver()->AsAudioCallbackDriver()) {
         nsCOMPtr<nsIRunnable> event = new dom::StateChangeTask(
             mStream->AsAudioNodeStream(), nullptr, AudioContextState::Running);
-        NS_DispatchToMainThread(event);
+        NS_DispatchToMainThread(event.forget());
       } else {
         nsCOMPtr<nsIRunnable> event = new GraphStartedRunnable(
             mStream->AsAudioNodeStream(), mStream->Graph());
-        NS_DispatchToMainThread(event);
+        NS_DispatchToMainThread(event.forget());
       }
     }
     virtual void RunDuringShutdown()
     {
     }
   };
 
   if (!aStream->IsDestroyed()) {
@@ -3337,17 +3337,17 @@ MediaStreamGraphImpl::AudioContextOperat
     case Suspend: state = AudioContextState::Suspended; break;
     case Resume: state = AudioContextState::Running; break;
     case Close: state = AudioContextState::Closed; break;
     default: MOZ_CRASH("Not handled.");
   }
 
   nsCOMPtr<nsIRunnable> event = new dom::StateChangeTask(
       aStream->AsAudioNodeStream(), aPromise, state);
-  NS_DispatchToMainThread(event);
+  NS_DispatchToMainThread(event.forget());
 }
 
 void
 MediaStreamGraphImpl::ApplyAudioContextOperationImpl(AudioNodeStream* aStream,
                                                AudioContextOperation aOperation,
                                                void* aPromise)
 {
   MOZ_ASSERT(CurrentDriver()->OnThread());