Bug 1027789 - CacheEntry::RememberCallback should unlock before call to InvokeAvailableCallback, r=michal

This commit is contained in:
Honza Bambas 2014-07-02 18:16:21 +02:00
parent c4a894b69d
commit ab4c8d5ea9
2 changed files with 26 additions and 12 deletions

View File

@ -274,17 +274,35 @@ void CacheEntry::AsyncOpen(nsICacheEntryOpenCallback* aCallback, uint32_t aFlags
Callback callback(this, aCallback, readonly, multithread);
if (!Open(callback, truncate, priority, bypassIfBusy)) {
// We get here when the callback wants to bypass cache when it's busy.
LOG((" writing or revalidating, callback wants to bypass cache"));
callback.mNotWanted = true;
InvokeAvailableCallback(callback);
}
}
bool CacheEntry::Open(Callback & aCallback, bool aTruncate,
bool aPriority, bool aBypassIfBusy)
{
mozilla::MutexAutoLock lock(mLock);
RememberCallback(callback, bypassIfBusy);
// Check state under the lock
if (aBypassIfBusy && (mState == WRITING || mState == REVALIDATING)) {
return false;
}
RememberCallback(aCallback);
// Load() opens the lock
if (Load(truncate, priority)) {
if (Load(aTruncate, aPriority)) {
// Loading is in progress...
return;
return true;
}
InvokeCallbacks();
return true;
}
bool CacheEntry::Load(bool aTruncate, bool aPriority)
@ -508,20 +526,13 @@ void CacheEntry::TransferCallbacks(CacheEntry & aFromEntry)
}
}
void CacheEntry::RememberCallback(Callback & aCallback, bool aBypassIfBusy)
void CacheEntry::RememberCallback(Callback & aCallback)
{
mLock.AssertCurrentThreadOwns();
LOG(("CacheEntry::RememberCallback [this=%p, cb=%p, state=%s]",
this, aCallback.mCallback.get(), StateString(mState)));
if (aBypassIfBusy && (mState == WRITING || mState == REVALIDATING)) {
LOG((" writing or revalidating, callback wants to bypass cache"));
aCallback.mNotWanted = true;
InvokeAvailableCallback(aCallback);
return;
}
mCallbacks.AppendElement(aCallback);
}

View File

@ -204,11 +204,14 @@ private:
nsresult mRv;
};
// Starts the load or just invokes the callback, bypasses (when required)
// if busy. Returns true on job done, false on bypass.
bool Open(Callback & aCallback, bool aTruncate, bool aPriority, bool aBypassIfBusy);
// Loads from disk asynchronously
bool Load(bool aTruncate, bool aPriority);
void OnLoaded();
void RememberCallback(Callback & aCallback, bool aBypassIfBusy);
void RememberCallback(Callback & aCallback);
void InvokeCallbacksLock();
void InvokeCallbacks();
bool InvokeCallbacks(bool aReadOnly);