Bug 1225731 - Early bailout from TaskQueue::DispatchLocked(). draft
authorJW Wang <jwwang@mozilla.com>
Mon, 07 Dec 2015 15:58:40 +0800
changeset 314581 9bbb66e75886cdff82c6a35a444e46f63752b54e
parent 314447 cc9c6cd756cb744596ba039dcc5ad3065a7cc3ea
child 314582 8293e53443b55a418c300a1bc063ba83e4d6acba
push id8235
push userjwwang@mozilla.com
push dateMon, 07 Dec 2015 23:45:10 +0000
bugs1225731
milestone45.0a1
Bug 1225731 - Early bailout from TaskQueue::DispatchLocked().
xpcom/threads/TaskQueue.cpp
--- a/xpcom/threads/TaskQueue.cpp
+++ b/xpcom/threads/TaskQueue.cpp
@@ -40,29 +40,30 @@ TaskQueue::TailDispatcher()
 }
 
 nsresult
 TaskQueue::DispatchLocked(already_AddRefed<nsIRunnable> aRunnable,
                                DispatchMode aMode, DispatchFailureHandling aFailureHandling,
                                DispatchReason aReason)
 {
   nsCOMPtr<nsIRunnable> r = aRunnable;
-  AbstractThread* currentThread;
-  if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) {
-    currentThread->TailDispatcher().AddTask(this, r.forget(), aFailureHandling);
-    return NS_OK;
-  }
-
   mQueueMonitor.AssertCurrentThreadOwns();
   if (mIsFlushing && aMode == AbortIfFlushing) {
     return NS_ERROR_ABORT;
   }
   if (mIsShutdown) {
     return NS_ERROR_FAILURE;
   }
+
+  AbstractThread* currentThread;
+  if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) {
+    currentThread->TailDispatcher().AddTask(this, r.forget(), aFailureHandling);
+    return NS_OK;
+  }
+
   mTasks.push(r.forget());
   if (mIsRunning) {
     return NS_OK;
   }
   RefPtr<nsIRunnable> runner(new Runner(this));
   nsresult rv = mPool->Dispatch(runner.forget(), NS_DISPATCH_NORMAL);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to dispatch runnable to run TaskQueue");