Bug 1142852 P2 Make Cache Action use non-threadsafe ref-counting. r=ehsan
authorBen Kelly <ben@wanderview.com>
Mon, 23 Mar 2015 22:28:09 -0400
changeset 265527 2e9b6048bd0f5f95389eb2c64e88fda7704721e5
parent 265526 07234a94ed48b08fbcfa4fefe0d2dedb01c27c40
child 265528 fde190586b1b6b3c6d7cc16c3eb4371728eafef8
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1142852
milestone39.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 1142852 P2 Make Cache Action use non-threadsafe ref-counting. r=ehsan
dom/cache/Action.h
dom/cache/Manager.cpp
--- a/dom/cache/Action.h
+++ b/dom/cache/Action.h
@@ -59,18 +59,17 @@ public:
   // Executed on the initiating thread and is passed the nsresult given to
   // Resolver::Resolve().
   virtual void CompleteOnInitiatingThread(nsresult aRv) { }
 
   // Executed on the initiating thread.  If this Action will operate on the
   // given cache ID then override this to return true.
   virtual bool MatchesCacheId(CacheId aCacheId) const { return false; }
 
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(cache::Action)
-  NS_DECL_OWNINGTHREAD
+  NS_INLINE_DECL_REFCOUNTING(cache::Action)
 
 protected:
   Action();
 
   // virtual because deleted through base class pointer
   virtual ~Action();
 
   // Check if this Action has been canceled.  May be called from any thread,
--- a/dom/cache/Manager.cpp
+++ b/dom/cache/Manager.cpp
@@ -909,25 +909,29 @@ private:
     mCopyContextList.Clear();
   }
 
   static void
   AsyncCopyCompleteFunc(void* aClosure, nsresult aRv)
   {
     // May be on any thread, including STS event target.
     MOZ_ASSERT(aClosure);
-    nsRefPtr<CachePutAllAction> action = static_cast<CachePutAllAction*>(aClosure);
+    // Weak ref as we are guaranteed to the action is alive until
+    // CompleteOnInitiatingThread is called.
+    CachePutAllAction* action = static_cast<CachePutAllAction*>(aClosure);
     action->CallOnAsyncCopyCompleteOnTargetThread(aRv);
   }
 
   void
   CallOnAsyncCopyCompleteOnTargetThread(nsresult aRv)
   {
-    // May be on any thread, including STS event target.
-    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableMethodWithArg<nsresult>(
+    // May be on any thread, including STS event target.  Non-owning runnable
+    // here since we are guaranteed the Action will survive until
+    // CompleteOnInitiatingThread is called.
+    nsCOMPtr<nsIRunnable> runnable = NS_NewNonOwningRunnableMethodWithArgs<nsresult>(
       this, &CachePutAllAction::OnAsyncCopyComplete, aRv);
     MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
       mTargetThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL)));
   }
 
   void
   DoResolve(nsresult aRv)
   {