Bug 673543 - ensure that no entry is activated while the main thread is blocked by SyncWithCacheIOThread()
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 12 Apr 2012 18:24:57 +0200
changeset 91542 38fcd9047d3905997d2aad6763c53b7a2a332ac1
parent 91541 e4c82a6b298c57415fc574fc79151a31acafc4a1
child 91543 fba161c486a087da876813d99f86bb9c33adc5e8
push id22455
push usermak77@bonardo.net
push dateFri, 13 Apr 2012 10:41:14 +0000
treeherdermozilla-central@9c81a70ddb1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs673543
milestone14.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 673543 - ensure that no entry is activated while the main thread is blocked by SyncWithCacheIOThread()
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsCacheService.h
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -1133,16 +1133,17 @@ NS_THREADSAFE_MEMORY_REPORTER_IMPLEMENT(
     "Memory used by the network memory cache.")
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService)
 
 nsCacheService::nsCacheService()
     : mLock("nsCacheService.mLock"),
       mCondVar(mLock, "nsCacheService.mCondVar"),
       mInitialized(false),
+      mClearingEntries(false),
       mEnableMemoryDevice(true),
       mEnableDiskDevice(true),
       mMemoryDevice(nsnull),
       mDiskDevice(nsnull),
       mOfflineDevice(nsnull),
       mTotalEntries(0),
       mCacheHits(0),
       mCacheMisses(0),
@@ -1887,17 +1888,19 @@ nsCacheService::OpenCacheEntry(nsCacheSe
 
 
 nsresult
 nsCacheService::ActivateEntry(nsCacheRequest * request, 
                               nsCacheEntry ** result,
                               nsCacheEntry ** doomedEntry)
 {
     CACHE_LOG_DEBUG(("Activate entry for request %p\n", request));
-    
+    if (!mInitialized || mClearingEntries)
+        return NS_ERROR_NOT_AVAILABLE;
+
     nsresult        rv = NS_OK;
 
     NS_ASSERTION(request != nsnull, "ActivateEntry called with no request");
     if (result) *result = nsnull;
     if (doomedEntry) *doomedEntry = nsnull;
     if ((!request) || (!result) || (!doomedEntry))
         return NS_ERROR_NULL_POINTER;
 
@@ -2169,16 +2172,17 @@ nsCacheService::OnProfileShutdown(bool c
 {
     if (!gService)  return;
     if (!gService->mInitialized) {
         // The cache service has been shut down, but someone is still holding
         // a reference to it. Ignore this call.
         return;
     }
     nsCacheServiceAutoLock lock;
+    gService->mClearingEntries = true;
 
     gService->DoomActiveEntries();
     gService->ClearDoomList();
 
     // Make sure to wait for any pending cache-operations before
     // proceeding with destructive actions (bug #620660)
     (void) SyncWithCacheIOThread();
 
@@ -2198,16 +2202,17 @@ nsCacheService::OnProfileShutdown(bool c
     }
     gService->mEnableOfflineDevice = false;
 
     if (gService->mMemoryDevice) {
         // clear memory cache
         gService->mMemoryDevice->EvictEntries(nsnull);
     }
 
+    gService->mClearingEntries = false;
 }
 
 
 void
 nsCacheService::OnProfileChanged()
 {
     if (!gService)  return;
 
--- a/netwerk/cache/nsCacheService.h
+++ b/netwerk/cache/nsCacheService.h
@@ -285,16 +285,17 @@ private:
     mozilla::CondVar                mCondVar;
 
     nsCOMPtr<nsIThread>             mCacheIOThread;
 
     nsTArray<nsISupports*>          mDoomedObjects;
     nsCOMPtr<nsITimer>              mSmartSizeTimer;
     
     bool                            mInitialized;
+    bool                            mClearingEntries;
     
     bool                            mEnableMemoryDevice;
     bool                            mEnableDiskDevice;
     bool                            mEnableOfflineDevice;
 
     nsMemoryCacheDevice *           mMemoryDevice;
     nsDiskCacheDevice *             mDiskDevice;
     nsOfflineCacheDevice *          mOfflineDevice;