mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1190951 - TSan: data race netwerk/cache2/CacheIndex.cpp:1397 CacheIndex::IsUpToDate, r=valentin.gosu
This commit is contained in:
parent
8021ea75bb
commit
ce912d02cd
@ -72,7 +72,7 @@ public:
|
||||
, mDoNotSearchInIndex(false)
|
||||
, mDoNotSearchInUpdates(false)
|
||||
{
|
||||
mIndex->AssertOwnsLock();
|
||||
CacheIndex::sLock.AssertCurrentThreadOwns();
|
||||
|
||||
mHash = aHash;
|
||||
const CacheIndexEntry *entry = FindEntry();
|
||||
@ -84,7 +84,7 @@ public:
|
||||
|
||||
~CacheIndexEntryAutoManage()
|
||||
{
|
||||
mIndex->AssertOwnsLock();
|
||||
CacheIndex::sLock.AssertCurrentThreadOwns();
|
||||
|
||||
const CacheIndexEntry *entry = FindEntry();
|
||||
mIndex->mIndexStats.AfterChange(entry);
|
||||
@ -163,7 +163,7 @@ public:
|
||||
{}
|
||||
|
||||
void Cancel() {
|
||||
mIndex->AssertOwnsLock();
|
||||
CacheIndex::sLock.AssertCurrentThreadOwns();
|
||||
mCanceled = true;
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ private:
|
||||
NS_IMETHODIMP FileOpenHelper::OnFileOpened(CacheFileHandle *aHandle,
|
||||
nsresult aResult)
|
||||
{
|
||||
CacheIndexAutoLock lock(mIndex);
|
||||
StaticMutexAutoLock lock(CacheIndex::sLock);
|
||||
|
||||
if (mCanceled) {
|
||||
if (aHandle) {
|
||||
@ -220,6 +220,7 @@ NS_IMPL_ISUPPORTS(FileOpenHelper, CacheFileIOListener);
|
||||
|
||||
|
||||
CacheIndex * CacheIndex::gInstance = nullptr;
|
||||
StaticMutex CacheIndex::sLock;
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(CacheIndex)
|
||||
@ -232,8 +233,7 @@ NS_INTERFACE_MAP_END_THREADSAFE
|
||||
|
||||
|
||||
CacheIndex::CacheIndex()
|
||||
: mLock("CacheIndex.mLock")
|
||||
, mState(INITIAL)
|
||||
: mState(INITIAL)
|
||||
, mShuttingDown(false)
|
||||
, mIndexNeedsUpdate(false)
|
||||
, mRemovingAll(false)
|
||||
@ -248,6 +248,7 @@ CacheIndex::CacheIndex()
|
||||
, mRWBufPos(0)
|
||||
, mJournalReadSuccessfully(false)
|
||||
{
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
LOG(("CacheIndex::CacheIndex [this=%p]", this));
|
||||
MOZ_COUNT_CTOR(CacheIndex);
|
||||
MOZ_ASSERT(!gInstance, "multiple CacheIndex instances!");
|
||||
@ -261,28 +262,6 @@ CacheIndex::~CacheIndex()
|
||||
ReleaseBuffer();
|
||||
}
|
||||
|
||||
void
|
||||
CacheIndex::Lock()
|
||||
{
|
||||
mLock.Lock();
|
||||
|
||||
MOZ_ASSERT(!mIndexStats.StateLogged());
|
||||
}
|
||||
|
||||
void
|
||||
CacheIndex::Unlock()
|
||||
{
|
||||
MOZ_ASSERT(!mIndexStats.StateLogged());
|
||||
|
||||
mLock.Unlock();
|
||||
}
|
||||
|
||||
inline void
|
||||
CacheIndex::AssertOwnsLock()
|
||||
{
|
||||
mLock.AssertCurrentThreadOwns();
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
CacheIndex::Init(nsIFile *aCacheDirectory)
|
||||
@ -291,14 +270,14 @@ CacheIndex::Init(nsIFile *aCacheDirectory)
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
if (gInstance) {
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
|
||||
RefPtr<CacheIndex> idx = new CacheIndex();
|
||||
|
||||
CacheIndexAutoLock lock(idx);
|
||||
|
||||
nsresult rv = idx->InitInternal(aCacheDirectory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -325,10 +304,12 @@ CacheIndex::InitInternal(nsIFile *aCacheDirectory)
|
||||
nsresult
|
||||
CacheIndex::PreShutdown()
|
||||
{
|
||||
LOG(("CacheIndex::PreShutdown() [gInstance=%p]", gInstance));
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
LOG(("CacheIndex::PreShutdown() [gInstance=%p]", gInstance));
|
||||
|
||||
nsresult rv;
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
@ -336,8 +317,6 @@ CacheIndex::PreShutdown()
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
LOG(("CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, "
|
||||
"dontMarkIndexClean=%d]", index->mState, index->mIndexOnDiskIsValid,
|
||||
index->mDontMarkIndexClean));
|
||||
@ -382,7 +361,7 @@ CacheIndex::PreShutdown()
|
||||
void
|
||||
CacheIndex::PreShutdownInternal()
|
||||
{
|
||||
CacheIndexAutoLock lock(this);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
LOG(("CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, "
|
||||
"dontMarkIndexClean=%d]", mState, mIndexOnDiskIsValid,
|
||||
@ -420,10 +399,12 @@ CacheIndex::PreShutdownInternal()
|
||||
nsresult
|
||||
CacheIndex::Shutdown()
|
||||
{
|
||||
LOG(("CacheIndex::Shutdown() [gInstance=%p]", gInstance));
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
LOG(("CacheIndex::Shutdown() [gInstance=%p]", gInstance));
|
||||
|
||||
RefPtr<CacheIndex> index;
|
||||
index.swap(gInstance);
|
||||
|
||||
@ -431,8 +412,6 @@ CacheIndex::Shutdown()
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
bool sanitize = CacheObserver::ClearCacheOnShutdown();
|
||||
|
||||
LOG(("CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, "
|
||||
@ -486,16 +465,16 @@ CacheIndex::AddEntry(const SHA1Sum::Hash *aHash)
|
||||
{
|
||||
LOG(("CacheIndex::AddEntry() [hash=%08x%08x%08x%08x%08x]", LOGSHA1(aHash)));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -601,16 +580,16 @@ CacheIndex::EnsureEntryExists(const SHA1Sum::Hash *aHash)
|
||||
LOG(("CacheIndex::EnsureEntryExists() [hash=%08x%08x%08x%08x%08x]",
|
||||
LOGSHA1(aHash)));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -712,16 +691,16 @@ CacheIndex::InitEntry(const SHA1Sum::Hash *aHash,
|
||||
"anonymous=%d, inBrowser=%d, pinned=%d]", LOGSHA1(aHash), aAppId,
|
||||
aAnonymous, aInBrowser, aPinned));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -821,16 +800,16 @@ CacheIndex::RemoveEntry(const SHA1Sum::Hash *aHash)
|
||||
LOG(("CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x]",
|
||||
LOGSHA1(aHash)));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -922,16 +901,16 @@ CacheIndex::UpdateEntry(const SHA1Sum::Hash *aHash,
|
||||
aExpirationTime ? nsPrintfCString("%u", *aExpirationTime).get() : "",
|
||||
aSize ? nsPrintfCString("%u", *aSize).get() : ""));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1019,18 +998,18 @@ CacheIndex::RemoveAll()
|
||||
{
|
||||
LOG(("CacheIndex::RemoveAll()"));
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
|
||||
{
|
||||
CacheIndexAutoLock lock(index);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!index->mRemovingAll);
|
||||
|
||||
@ -1125,14 +1104,14 @@ CacheIndex::HasEntry(const nsACString &aKey, EntryStatus *_retval, bool *_pinned
|
||||
nsresult
|
||||
CacheIndex::HasEntry(const SHA1Sum::Hash &hash, EntryStatus *_retval, bool *_pinned)
|
||||
{
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1191,15 +1170,15 @@ CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash,
|
||||
{
|
||||
LOG(("CacheIndex::GetEntryForEviction()"));
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1267,13 +1246,13 @@ CacheIndex::GetCacheSize(uint32_t *_retval)
|
||||
{
|
||||
LOG(("CacheIndex::GetCacheSize()"));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1289,14 +1268,14 @@ CacheIndex::GetEntryFileCount(uint32_t *_retval)
|
||||
{
|
||||
LOG(("CacheIndex::GetEntryFileCount()"));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1312,14 +1291,14 @@ CacheIndex::GetCacheStats(nsILoadContextInfo *aInfo, uint32_t *aSize, uint32_t *
|
||||
{
|
||||
LOG(("CacheIndex::GetCacheStats() [info=%p]", aInfo));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1349,14 +1328,14 @@ CacheIndex::AsyncGetDiskConsumption(nsICacheStorageConsumptionObserver* aObserve
|
||||
{
|
||||
LOG(("CacheIndex::AsyncGetDiskConsumption()"));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1388,14 +1367,14 @@ CacheIndex::GetIterator(nsILoadContextInfo *aInfo, bool aAddNew,
|
||||
{
|
||||
LOG(("CacheIndex::GetIterator() [info=%p, addNew=%d]", aInfo, aAddNew));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1421,14 +1400,14 @@ CacheIndex::IsUpToDate(bool *_retval)
|
||||
{
|
||||
LOG(("CacheIndex::IsUpToDate()"));
|
||||
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
@ -1513,7 +1492,7 @@ CacheIndex::ProcessPendingOperations()
|
||||
{
|
||||
LOG(("CacheIndex::ProcessPendingOperations()"));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
for (auto iter = mPendingUpdates.Iter(); !iter.Done(); iter.Next()) {
|
||||
CacheIndexEntryUpdate* update = iter.Get();
|
||||
@ -1596,7 +1575,7 @@ CacheIndex::WriteIndexToDisk()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
MOZ_ASSERT(mState == READY);
|
||||
MOZ_ASSERT(!mRWBuf);
|
||||
MOZ_ASSERT(!mRWHash);
|
||||
@ -1638,7 +1617,7 @@ CacheIndex::WriteRecords()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
MOZ_ASSERT(mState == WRITING);
|
||||
|
||||
int64_t fileOffset;
|
||||
@ -1728,7 +1707,7 @@ CacheIndex::FinishWrite(bool aSucceeded)
|
||||
|
||||
MOZ_ASSERT((!aSucceeded && mState == SHUTDOWN) || mState == WRITING);
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
mIndexHandle = nullptr;
|
||||
mRWHash = nullptr;
|
||||
@ -2007,7 +1986,7 @@ CacheIndex::ReadIndexFromDisk()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
MOZ_ASSERT(mState == INITIAL);
|
||||
|
||||
ChangeState(READING);
|
||||
@ -2054,7 +2033,7 @@ CacheIndex::StartReadingIndex()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
MOZ_ASSERT(mIndexHandle);
|
||||
MOZ_ASSERT(mState == READING);
|
||||
@ -2094,7 +2073,7 @@ CacheIndex::ParseRecords()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
uint32_t entryCnt = (mIndexHandle->FileSize() - sizeof(CacheIndexHeader) -
|
||||
sizeof(CacheHash::Hash32_t)) / sizeof(CacheIndexRecord);
|
||||
@ -2222,7 +2201,7 @@ CacheIndex::StartReadingJournal()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
MOZ_ASSERT(mJournalHandle);
|
||||
MOZ_ASSERT(mIndexOnDiskIsValid);
|
||||
@ -2259,7 +2238,7 @@ CacheIndex::ParseJournal()
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
uint32_t entryCnt = (mJournalHandle->FileSize() -
|
||||
sizeof(CacheHash::Hash32_t)) / sizeof(CacheIndexRecord);
|
||||
@ -2334,7 +2313,7 @@ CacheIndex::MergeJournal()
|
||||
{
|
||||
LOG(("CacheIndex::MergeJournal()"));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
for (auto iter = mTmpJournal.Iter(); !iter.Done(); iter.Next()) {
|
||||
CacheIndexEntry* entry = iter.Get();
|
||||
@ -2398,7 +2377,7 @@ void
|
||||
CacheIndex::FinishRead(bool aSucceeded)
|
||||
{
|
||||
LOG(("CacheIndex::FinishRead() [succeeded=%d]", aSucceeded));
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
MOZ_ASSERT((!aSucceeded && mState == SHUTDOWN) || mState == READING);
|
||||
|
||||
@ -2479,14 +2458,14 @@ CacheIndex::DelayedUpdate(nsITimer *aTimer, void *aClosure)
|
||||
LOG(("CacheIndex::DelayedUpdate()"));
|
||||
|
||||
nsresult rv;
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
RefPtr<CacheIndex> index = gInstance;
|
||||
|
||||
if (!index) {
|
||||
return;
|
||||
}
|
||||
|
||||
CacheIndexAutoLock lock(index);
|
||||
|
||||
index->mUpdateTimer = nullptr;
|
||||
|
||||
if (!index->IsIndexUsable()) {
|
||||
@ -2613,7 +2592,7 @@ CacheIndex::InitEntryFromDiskData(CacheIndexEntry *aEntry,
|
||||
bool
|
||||
CacheIndex::IsUpdatePending()
|
||||
{
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
if (mUpdateTimer || mUpdateEventPending) {
|
||||
return true;
|
||||
@ -2627,7 +2606,7 @@ CacheIndex::BuildIndex()
|
||||
{
|
||||
LOG(("CacheIndex::BuildIndex()"));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
MOZ_ASSERT(mPendingUpdates.Count() == 0);
|
||||
|
||||
@ -2636,7 +2615,7 @@ CacheIndex::BuildIndex()
|
||||
if (!mDirEnumerator) {
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = SetupDirectoryEnumerator();
|
||||
}
|
||||
if (mState == SHUTDOWN) {
|
||||
@ -2661,7 +2640,7 @@ CacheIndex::BuildIndex()
|
||||
nsCOMPtr<nsIFile> file;
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = mDirEnumerator->GetNextFile(getter_AddRefs(file));
|
||||
}
|
||||
if (mState == SHUTDOWN) {
|
||||
@ -2723,7 +2702,7 @@ CacheIndex::BuildIndex()
|
||||
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = meta->SyncReadMetadata(file);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
@ -2782,7 +2761,7 @@ CacheIndex::StartUpdatingIndex(bool aRebuild)
|
||||
{
|
||||
LOG(("CacheIndex::StartUpdatingIndex() [rebuild=%d]", aRebuild));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
nsresult rv;
|
||||
|
||||
@ -2838,7 +2817,7 @@ CacheIndex::UpdateIndex()
|
||||
{
|
||||
LOG(("CacheIndex::UpdateIndex()"));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
MOZ_ASSERT(mPendingUpdates.Count() == 0);
|
||||
|
||||
@ -2847,7 +2826,7 @@ CacheIndex::UpdateIndex()
|
||||
if (!mDirEnumerator) {
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = SetupDirectoryEnumerator();
|
||||
}
|
||||
if (mState == SHUTDOWN) {
|
||||
@ -2873,7 +2852,7 @@ CacheIndex::UpdateIndex()
|
||||
nsCOMPtr<nsIFile> file;
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = mDirEnumerator->GetNextFile(getter_AddRefs(file));
|
||||
}
|
||||
if (mState == SHUTDOWN) {
|
||||
@ -2934,7 +2913,7 @@ CacheIndex::UpdateIndex()
|
||||
PRTime lastModifiedTime;
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = file->GetLastModifiedTime(&lastModifiedTime);
|
||||
}
|
||||
if (mState == SHUTDOWN) {
|
||||
@ -2963,7 +2942,7 @@ CacheIndex::UpdateIndex()
|
||||
|
||||
{
|
||||
// Do not do IO under the lock.
|
||||
CacheIndexAutoUnlock unlock(this);
|
||||
StaticMutexAutoUnlock unlock(sLock);
|
||||
rv = meta->SyncReadMetadata(file);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
@ -3014,7 +2993,7 @@ CacheIndex::FinishUpdate(bool aSucceeded)
|
||||
MOZ_ASSERT(mState == UPDATING || mState == BUILDING ||
|
||||
(!aSucceeded && mState == SHUTDOWN));
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
if (mDirEnumerator) {
|
||||
if (NS_IsMainThread()) {
|
||||
@ -3198,7 +3177,7 @@ CacheIndex::RemoveRecordFromFrecencyArray(CacheIndexRecord *aRecord)
|
||||
void
|
||||
CacheIndex::AddRecordToIterators(CacheIndexRecord *aRecord)
|
||||
{
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
for (uint32_t i = 0; i < mIterators.Length(); ++i) {
|
||||
// Add a new record only when iterator is supposed to be updated.
|
||||
@ -3211,7 +3190,7 @@ CacheIndex::AddRecordToIterators(CacheIndexRecord *aRecord)
|
||||
void
|
||||
CacheIndex::RemoveRecordFromIterators(CacheIndexRecord *aRecord)
|
||||
{
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
for (uint32_t i = 0; i < mIterators.Length(); ++i) {
|
||||
// Remove the record from iterator always, it makes no sence to return
|
||||
@ -3225,7 +3204,7 @@ void
|
||||
CacheIndex::ReplaceRecordInIterators(CacheIndexRecord *aOldRecord,
|
||||
CacheIndexRecord *aNewRecord)
|
||||
{
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
for (uint32_t i = 0; i < mIterators.Length(); ++i) {
|
||||
// We have to replace the record always since the pointer is no longer
|
||||
@ -3242,7 +3221,7 @@ CacheIndex::Run()
|
||||
{
|
||||
LOG(("CacheIndex::Run()"));
|
||||
|
||||
CacheIndexAutoLock lock(this);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
if (!IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3277,7 +3256,7 @@ CacheIndex::OnFileOpenedInternal(FileOpenHelper *aOpener,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
AssertOwnsLock();
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
if (!IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3387,7 +3366,7 @@ CacheIndex::OnDataWritten(CacheFileHandle *aHandle, const char *aBuf,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
CacheIndexAutoLock lock(this);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
if (!IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3437,7 +3416,7 @@ CacheIndex::OnDataRead(CacheFileHandle *aHandle, char *aBuf, nsresult aResult)
|
||||
LOG(("CacheIndex::OnDataRead() [handle=%p, result=0x%08x]", aHandle,
|
||||
aResult));
|
||||
|
||||
CacheIndexAutoLock lock(this);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
if (!IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3486,7 +3465,7 @@ CacheIndex::OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult)
|
||||
LOG(("CacheIndex::OnFileRenamed() [handle=%p, result=0x%08x]", aHandle,
|
||||
aResult));
|
||||
|
||||
CacheIndexAutoLock lock(this);
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
if (!IsIndexUsable()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3541,7 +3520,7 @@ CacheIndex::OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult)
|
||||
size_t
|
||||
CacheIndex::SizeOfExcludingThisInternal(mozilla::MallocSizeOf mallocSizeOf) const
|
||||
{
|
||||
CacheIndexAutoLock lock(const_cast<CacheIndex*>(this));
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
size_t n = 0;
|
||||
nsCOMPtr<nsISizeOf> sizeOf;
|
||||
@ -3578,6 +3557,8 @@ CacheIndex::SizeOfExcludingThisInternal(mozilla::MallocSizeOf mallocSizeOf) cons
|
||||
size_t
|
||||
CacheIndex::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
|
||||
{
|
||||
sLock.AssertCurrentThreadOwns();
|
||||
|
||||
if (!gInstance)
|
||||
return 0;
|
||||
|
||||
@ -3588,6 +3569,8 @@ CacheIndex::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
|
||||
size_t
|
||||
CacheIndex::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
|
||||
{
|
||||
StaticMutexAutoLock lock(sLock);
|
||||
|
||||
return mallocSizeOf(gInstance) + SizeOfExcludingThis(mallocSizeOf);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "mozilla/SHA1.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/Endian.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
@ -696,8 +696,6 @@ public:
|
||||
|
||||
private:
|
||||
friend class CacheIndexEntryAutoManage;
|
||||
friend class CacheIndexAutoLock;
|
||||
friend class CacheIndexAutoUnlock;
|
||||
friend class FileOpenHelper;
|
||||
friend class CacheIndexIterator;
|
||||
|
||||
@ -713,10 +711,6 @@ private:
|
||||
NS_IMETHOD OnEOFSet(CacheFileHandle *aHandle, nsresult aResult) override;
|
||||
NS_IMETHOD OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult) override;
|
||||
|
||||
void Lock();
|
||||
void Unlock();
|
||||
void AssertOwnsLock();
|
||||
|
||||
nsresult InitInternal(nsIFile *aCacheDirectory);
|
||||
void PreShutdownInternal();
|
||||
|
||||
@ -931,10 +925,10 @@ private:
|
||||
void ReportHashStats();
|
||||
|
||||
static CacheIndex *gInstance;
|
||||
static StaticMutex sLock;
|
||||
|
||||
nsCOMPtr<nsIFile> mCacheDirectory;
|
||||
|
||||
mozilla::Mutex mLock;
|
||||
EState mState;
|
||||
// Timestamp of time when the index was initialized. We use it to delay
|
||||
// initial update or build of index.
|
||||
@ -1089,70 +1083,6 @@ private:
|
||||
nsTArray<RefPtr<DiskConsumptionObserver> > mDiskConsumptionObservers;
|
||||
};
|
||||
|
||||
class CacheIndexAutoLock {
|
||||
public:
|
||||
explicit CacheIndexAutoLock(CacheIndex *aIndex)
|
||||
: mIndex(aIndex)
|
||||
, mLocked(true)
|
||||
{
|
||||
mIndex->Lock();
|
||||
}
|
||||
~CacheIndexAutoLock()
|
||||
{
|
||||
if (mLocked) {
|
||||
mIndex->Unlock();
|
||||
}
|
||||
}
|
||||
void Lock()
|
||||
{
|
||||
MOZ_ASSERT(!mLocked);
|
||||
mIndex->Lock();
|
||||
mLocked = true;
|
||||
}
|
||||
void Unlock()
|
||||
{
|
||||
MOZ_ASSERT(mLocked);
|
||||
mIndex->Unlock();
|
||||
mLocked = false;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<CacheIndex> mIndex;
|
||||
bool mLocked;
|
||||
};
|
||||
|
||||
class CacheIndexAutoUnlock {
|
||||
public:
|
||||
explicit CacheIndexAutoUnlock(CacheIndex *aIndex)
|
||||
: mIndex(aIndex)
|
||||
, mLocked(false)
|
||||
{
|
||||
mIndex->Unlock();
|
||||
}
|
||||
~CacheIndexAutoUnlock()
|
||||
{
|
||||
if (!mLocked) {
|
||||
mIndex->Lock();
|
||||
}
|
||||
}
|
||||
void Lock()
|
||||
{
|
||||
MOZ_ASSERT(!mLocked);
|
||||
mIndex->Lock();
|
||||
mLocked = true;
|
||||
}
|
||||
void Unlock()
|
||||
{
|
||||
MOZ_ASSERT(mLocked);
|
||||
mIndex->Unlock();
|
||||
mLocked = false;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<CacheIndex> mIndex;
|
||||
bool mLocked;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -32,7 +32,7 @@ CacheIndexIterator::GetNextHash(SHA1Sum::Hash *aHash)
|
||||
{
|
||||
LOG(("CacheIndexIterator::GetNextHash() [this=%p]", this));
|
||||
|
||||
CacheIndexAutoLock lock(mIndex);
|
||||
StaticMutexAutoLock lock(CacheIndex::sLock);
|
||||
|
||||
if (NS_FAILED(mStatus)) {
|
||||
return mStatus;
|
||||
@ -54,7 +54,7 @@ CacheIndexIterator::Close()
|
||||
{
|
||||
LOG(("CacheIndexIterator::Close() [this=%p]", this));
|
||||
|
||||
CacheIndexAutoLock lock(mIndex);
|
||||
StaticMutexAutoLock lock(CacheIndex::sLock);
|
||||
|
||||
return CloseInternal(NS_ERROR_NOT_AVAILABLE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user