Bug 1186745 part 3 - Make nsThreadSyncDispatch leak the sync task by default when Run() is not called. r=froydnj
☠☠ backed out by 00a507c0f662 ☠ ☠
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 29 Sep 2015 09:28:22 +1000
changeset 264804 383f8ac033ea6a9951779b06ee463c95d230a4ab
parent 264803 ce960a661987dacec560459797e720d442ccb912
child 264805 edc0b56d81faf04f67462221aaaa566319df8c39
push id65754
push userxquan@mozilla.com
push dateMon, 28 Sep 2015 23:28:58 +0000
treeherdermozilla-inbound@c6142b815de0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1186745
milestone44.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 1186745 part 3 - Make nsThreadSyncDispatch leak the sync task by default when Run() is not called. r=froydnj
xpcom/threads/nsThreadSyncDispatch.h
--- a/xpcom/threads/nsThreadSyncDispatch.h
+++ b/xpcom/threads/nsThreadSyncDispatch.h
@@ -3,47 +3,49 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsThreadSyncDispatch_h_
 #define nsThreadSyncDispatch_h_
 
 #include "nsThreadUtils.h"
+#include "LeakRefPtr.h"
 
 class nsThreadSyncDispatch : public nsRunnable
 {
 public:
   nsThreadSyncDispatch(nsIThread* aOrigin, already_AddRefed<nsIRunnable>&& aTask)
     : mOrigin(aOrigin)
-    , mSyncTask(aTask)
+    , mSyncTask(mozilla::Move(aTask))
     , mResult(NS_ERROR_NOT_INITIALIZED)
   {
   }
 
   bool IsPending()
   {
-    return mSyncTask != nullptr;
+    return !!mSyncTask;
   }
 
   nsresult Result()
   {
     return mResult;
   }
 
 private:
   NS_IMETHOD Run() override
   {
-    if (mSyncTask) {
-      mResult = mSyncTask->Run();
-      mSyncTask = nullptr;
+    if (nsCOMPtr<nsIRunnable> task = mSyncTask.take()) {
+      mResult = task->Run();
       // unblock the origin thread
       mOrigin->Dispatch(this, NS_DISPATCH_NORMAL);
     }
     return NS_OK;
   }
 
   nsCOMPtr<nsIThread> mOrigin;
-  nsCOMPtr<nsIRunnable> mSyncTask;
+  // The task is leaked by default when Run() is not called, because
+  // otherwise we may release it in an incorrect thread.
+  mozilla::LeakRefPtr<nsIRunnable> mSyncTask;
   nsresult mResult;
 };
 
 #endif // nsThreadSyncDispatch_h_