Bug 1225731 - Early bailout from TaskQueue::DispatchLocked(). r=froydnj
authorJW Wang <jwwang@mozilla.com>
Thu, 10 Nov 2016 15:45:45 +0800
changeset 438329 bf09a2e3fb6b97636484eb81af709790b6a4d60e
parent 438328 a5c6e3c69ef2d105505c560105de5249e470a626
child 438330 9479284d16ea0dc73893ec55baac7a06c7c5bf8e
push id35679
push userbmo:timdream@gmail.com
push dateMon, 14 Nov 2016 09:29:38 +0000
reviewersfroydnj
bugs1225731
milestone52.0a1
Bug 1225731 - Early bailout from TaskQueue::DispatchLocked(). r=froydnj MozReview-Commit-ID: Xhj87WeRID
xpcom/threads/TaskQueue.cpp
--- a/xpcom/threads/TaskQueue.cpp
+++ b/xpcom/threads/TaskQueue.cpp
@@ -90,26 +90,27 @@ TaskQueue::TailDispatcher()
 
 // Note aRunnable is passed by ref to support conditional ownership transfer.
 // See Dispatch() in TaskQueue.h for more details.
 nsresult
 TaskQueue::DispatchLocked(nsCOMPtr<nsIRunnable>& aRunnable,
                           DispatchFailureHandling aFailureHandling,
                           DispatchReason aReason)
 {
+  mQueueMonitor.AssertCurrentThreadOwns();
+  if (mIsShutdown) {
+    return NS_ERROR_FAILURE;
+  }
+
   AbstractThread* currentThread;
   if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) {
     currentThread->TailDispatcher().AddTask(this, aRunnable.forget(), aFailureHandling);
     return NS_OK;
   }
 
-  mQueueMonitor.AssertCurrentThreadOwns();
-  if (mIsShutdown) {
-    return NS_ERROR_FAILURE;
-  }
   mTasks.push(aRunnable.forget());
   if (mIsRunning) {
     return NS_OK;
   }
   RefPtr<nsIRunnable> runner(new Runner(this));
   nsresult rv = mTarget->Dispatch(runner.forget(), NS_DISPATCH_NORMAL);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to dispatch runnable to run TaskQueue");