Bug 976866 - HTTP cache v2: Specific dispatch method for eviction events, r=michal

This commit is contained in:
Honza Bambas 2014-04-04 14:42:05 +02:00
parent 4d80458f88
commit 62b82713ee
3 changed files with 29 additions and 2 deletions

View File

@ -2019,7 +2019,7 @@ CacheFileIOManager::DoomFileByKey(const nsACString &aKey,
}
nsRefPtr<DoomFileByKeyEvent> ev = new DoomFileByKeyEvent(aKey, aCallback);
rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::OPEN);
rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -2495,7 +2495,7 @@ CacheFileIOManager::EvictAll()
nsCOMPtr<nsIRunnable> ev;
ev = NS_NewRunnableMethod(ioMan, &CacheFileIOManager::EvictAllInternal);
rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::OPEN_PRIORITY);
rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

View File

@ -60,6 +60,28 @@ nsresult CacheIOThread::Dispatch(nsIRunnable* aRunnable, uint32_t aLevel)
if (mShutdown && (PR_GetCurrentThread() != mThread))
return NS_ERROR_UNEXPECTED;
return DispatchInternal(aRunnable, aLevel);
}
nsresult CacheIOThread::DispatchAfterPendingOpens(nsIRunnable* aRunnable)
{
MonitorAutoLock lock(mMonitor);
if (mShutdown && (PR_GetCurrentThread() != mThread))
return NS_ERROR_UNEXPECTED;
// Move everything from later executed OPEN level to the OPEN_PRIORITY level
// where we post the (eviction) runnable.
mEventQueue[OPEN_PRIORITY].AppendElements(mEventQueue[OPEN]);
mEventQueue[OPEN].Clear();
return DispatchInternal(aRunnable, OPEN_PRIORITY);
}
nsresult CacheIOThread::DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel)
{
mMonitor.AssertCurrentThreadOwns();
mEventQueue[aLevel].AppendElement(aRunnable);
if (mLowestLevelWaiting > aLevel)
mLowestLevelWaiting = aLevel;

View File

@ -46,6 +46,10 @@ public:
nsresult Init();
nsresult Dispatch(nsIRunnable* aRunnable, uint32_t aLevel);
// Makes sure that any previously posted event to OPEN or OPEN_PRIORITY
// levels (such as file opennings and dooms) are executed before aRunnable
// that is intended to evict stuff from the cache.
nsresult DispatchAfterPendingOpens(nsIRunnable* aRunnable);
bool IsCurrentThread();
/**
@ -74,6 +78,7 @@ private:
void ThreadFunc();
void LoopOneLevel(uint32_t aLevel);
bool EventsPending(uint32_t aLastLevel = LAST_LEVEL);
nsresult DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel);
bool YieldInternal();
static CacheIOThread* sSelf;