Bug 1132172 - Don't access CacheEntry::mFrecency on non-cache threads. r=michal
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 25 Mar 2015 14:55:00 -0400
changeset 266298 9369346e7e4acc32e36f0b1457e15ac6d79c8f04
parent 266297 d7bfe22ed06657672c9f1baac0d6ee6a60426184
child 266299 8be35539cc88d9b77a3d7018fb1b5ffd980f057d
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)
reviewersmichal
bugs1132172
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 1132172 - Don't access CacheEntry::mFrecency on non-cache threads. r=michal
netwerk/cache2/CacheEntry.cpp
netwerk/cache2/CacheEntry.h
--- a/netwerk/cache2/CacheEntry.cpp
+++ b/netwerk/cache2/CacheEntry.cpp
@@ -1589,17 +1589,17 @@ void CacheEntry::BackgroundOp(uint32_t a
         // more precise.
         mFrecency = log(exp(mFrecency - now_decay) + 1) + now_decay;
       }
       LOG(("CacheEntry FRECENCYUPDATE [this=%p, frecency=%1.10f]", this, mFrecency));
 
       // Because CacheFile::Set*() are not thread-safe to use (uses WeakReference that
       // is not thread-safe) we must post to the main thread...
       nsRefPtr<nsRunnableMethod<CacheEntry> > event =
-        NS_NewRunnableMethod(this, &CacheEntry::StoreFrecency);
+        NS_NewRunnableMethodWithArg<double>(this, &CacheEntry::StoreFrecency, mFrecency);
       NS_DispatchToMainThread(event);
     }
 
     if (aOperations & Ops::REGISTER) {
       LOG(("CacheEntry REGISTER [this=%p]", this));
 
       CacheStorageService::Self()->RegisterEntry(this);
     }
@@ -1613,24 +1613,22 @@ void CacheEntry::BackgroundOp(uint32_t a
 
   if (aOperations & Ops::CALLBACKS) {
     LOG(("CacheEntry CALLBACKS (invoke) [this=%p]", this));
 
     InvokeCallbacks();
   }
 }
 
-void CacheEntry::StoreFrecency()
+void CacheEntry::StoreFrecency(double aFrecency)
 {
-  // No need for thread safety over mFrecency, it will be rewriten
-  // correctly on following invocation if broken by concurrency.
   MOZ_ASSERT(NS_IsMainThread());
 
   if (NS_SUCCEEDED(mFileStatus)) {
-    mFile->SetFrecency(FRECENCY2INT(mFrecency));
+    mFile->SetFrecency(FRECENCY2INT(aFrecency));
   }
 }
 
 // CacheOutputCloseListener
 
 CacheOutputCloseListener::CacheOutputCloseListener(CacheEntry* aEntry)
 : mEntry(aEntry)
 {
--- a/netwerk/cache2/CacheEntry.h
+++ b/netwerk/cache2/CacheEntry.h
@@ -243,17 +243,17 @@ private:
   friend class CacheOutputCloseListener;
   void OnOutputClosed();
 
 private:
   // Schedules a background operation on the management thread.
   // When executed on the management thread directly, the operation(s)
   // is (are) executed immediately.
   void BackgroundOp(uint32_t aOperation, bool aForceAsync = false);
-  void StoreFrecency();
+  void StoreFrecency(double aFrecency);
 
   // Called only from DoomAlreadyRemoved()
   void DoomFile();
 
   already_AddRefed<CacheEntryHandle> ReopenTruncated(bool aMemoryOnly,
                                                      nsICacheEntryOpenCallback* aCallback);
   void TransferCallbacks(CacheEntry & aFromEntry);