Bug 981911 - Always call profiler_unregister_thread() when returning from MediaStreamGraphImpl::RunThread(). r=roc
authorAndrew McCreight <continuation@gmail.com>
Tue, 11 Mar 2014 16:06:57 -0700
changeset 191311 47b3d99c58a523e10bc1dc6d8ba7d733dce850e4
parent 191310 499a25915134ae487e195b572a444dd5d389aaa3
child 191312 716ba77a9d0a8d72fe8c4e3273bdcf0d5b57fe47
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs981911
milestone30.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 981911 - Always call profiler_unregister_thread() when returning from MediaStreamGraphImpl::RunThread(). r=roc
content/media/MediaStreamGraph.cpp
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -1139,28 +1139,42 @@ MediaStreamGraphImpl::ResumeAllAudioOutp
   for (uint32_t i = 0; i < mStreams.Length(); ++i) {
     MediaStream* s = mStreams[i];
     for (uint32_t j = 0; j < s->mAudioOutputStreams.Length(); ++j) {
       s->mAudioOutputStreams[j].mStream->Resume();
     }
   }
 }
 
+struct AutoProfilerUnregisterThread
+{
+  // The empty ctor is used to silence a pre-4.8.0 GCC unused variable warning.
+  AutoProfilerUnregisterThread()
+  {
+  }
+
+  ~AutoProfilerUnregisterThread()
+  {
+    profiler_unregister_thread();
+  }
+};
+
 void
 MediaStreamGraphImpl::RunThread()
 {
   nsTArray<MessageBlock> messageQueue;
   {
     MonitorAutoLock lock(mMonitor);
     messageQueue.SwapElements(mMessageQueue);
   }
   NS_ASSERTION(!messageQueue.IsEmpty(),
                "Shouldn't have started a graph with empty message queue!");
 
   uint32_t ticksProcessed = 0;
+  AutoProfilerUnregisterThread autoUnregister;
 
   for (;;) {
     // Update mCurrentTime to the min of the playing audio times, or using the
     // wall-clock time change if no audio is playing.
     UpdateCurrentTime();
 
     // Calculate independent action times for each batch of messages (each
     // batch corresponding to an event loop task). This isolates the performance
@@ -1315,18 +1329,16 @@ MediaStreamGraphImpl::RunThread()
           ResumeAllAudioOutputs();
         }
       }
       mWaitState = WAITSTATE_RUNNING;
       mNeedAnotherIteration = false;
       messageQueue.SwapElements(mMessageQueue);
     }
   }
-
-  profiler_unregister_thread();
 }
 
 void
 MediaStreamGraphImpl::ApplyStreamUpdate(StreamUpdate* aUpdate)
 {
   mMonitor.AssertCurrentThreadOwns();
 
   MediaStream* stream = aUpdate->mStream;