Bug 1074048 - Allow MainThread access if the graph is shut down (for RunDuringShutdown). r=roc, a=lmandel
authorRandell Jesup <rjesup@jesup.org>
Tue, 30 Sep 2014 08:59:05 -0400
changeset 225448 2843cd849c7cb2c96366476f06ce2117b66db9c4
parent 225447 94b5b0cd16f10fdacb4e7b40bab7b66a969e7b1f
child 225449 d157cbc0fe744603c381155ea8cac92de64baf5f
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lmandel
bugs1074048
milestone34.0a2
Bug 1074048 - Allow MainThread access if the graph is shut down (for RunDuringShutdown). r=roc, a=lmandel
content/media/MediaStreamGraphImpl.h
--- a/content/media/MediaStreamGraphImpl.h
+++ b/content/media/MediaStreamGraphImpl.h
@@ -148,18 +148,26 @@ public:
    * Called before the thread runs.
    */
   void Init();
   // The following methods run on the graph thread (or possibly the main thread if
   // mLifecycleState > LIFECYCLE_RUNNING)
   void AssertOnGraphThreadOrNotRunning() {
     // either we're on the right thread (and calling CurrentDriver() is safe),
     // or we're going to assert anyways, so don't cross-check CurrentDriver
-    MOZ_ASSERT(mDriver->OnThread() ||
-               (mLifecycleState > LIFECYCLE_RUNNING && NS_IsMainThread()));
+#ifdef DEBUG
+    // if all the safety checks fail, assert we own the monitor
+    if (!mDriver->OnThread()) {
+      if (!(mDetectedNotRunning &&
+            mLifecycleState > LIFECYCLE_RUNNING &&
+            NS_IsMainThread())) {
+        mMonitor.AssertCurrentThreadOwns();
+      }
+    }
+#endif
   }
   /*
    * This does the actual iteration: Message processing, MediaStream ordering,
    * blocking computation and processing.
    */
   void DoIteration();
 
   bool OneIteration(GraphTime aFrom, GraphTime aTo,
@@ -419,40 +427,30 @@ public:
    */
   void PausedIndefinitly();
   void ResumedFromPaused();
 
   /**
    * Not safe to call off the MediaStreamGraph thread unless monitor is held!
    */
   GraphDriver* CurrentDriver() {
-#ifdef DEBUG
-    // #ifdef since we're not wrapping it all in MOZ_ASSERT()
-    if (!mDriver->OnThread()) {
-      mMonitor.AssertCurrentThreadOwns();
-    }
-#endif
+    AssertOnGraphThreadOrNotRunning();
     return mDriver;
   }
 
   /**
    * Effectively set the new driver, while we are switching.
    * It is only safe to call this at the very end of an iteration, when there
    * has been a SwitchAtNextIteration call during the iteration. The driver
    * should return and pass the control to the new driver shortly after.
    * We can also switch from Revive() (on MainThread), in which case the
    * monitor is held
    */
   void SetCurrentDriver(GraphDriver* aDriver) {
-#ifdef DEBUG
-    // #ifdef since we're not wrapping it all in MOZ_ASSERT()
-    if (!mDriver->OnThread()) {
-      mMonitor.AssertCurrentThreadOwns();
-    }
-#endif
+    AssertOnGraphThreadOrNotRunning();
     mDriver = aDriver;
   }
 
   Monitor& GetMonitor() {
     return mMonitor;
   }
 
   void EnsureNextIteration() {