Bug 1114999 - Part 3: Use automatic memory management for mObjsToRelease; r=novotny

This commit is contained in:
Jeff Muizelaar 2015-01-15 18:19:26 -05:00 committed by Ehsan Akhgari
parent c416f00994
commit 9bab0efb09
2 changed files with 14 additions and 13 deletions

View File

@ -10,6 +10,7 @@
#include "CacheFileOutputStream.h"
#include "nsThreadUtils.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Move.h"
#include <algorithm>
#include "nsComponentManagerUtils.h"
#include "nsProxyRelease.h"
@ -999,13 +1000,13 @@ CacheFile::Lock()
void
CacheFile::Unlock()
{
nsTArray<nsISupports*> objs;
// move the elements out of mObjsToRelease
// so that they can be released after we unlock
nsTArray<nsRefPtr<nsISupports>> objs;
objs.SwapElements(mObjsToRelease);
mLock.Unlock();
for (uint32_t i = 0; i < objs.Length(); i++)
objs[i]->Release();
}
void
@ -1015,11 +1016,11 @@ CacheFile::AssertOwnsLock() const
}
void
CacheFile::ReleaseOutsideLock(nsISupports *aObject)
CacheFile::ReleaseOutsideLock(nsRefPtr<nsISupports> aObject)
{
AssertOwnsLock();
mObjsToRelease.AppendElement(aObject);
mObjsToRelease.AppendElement(Move(aObject));
}
nsresult
@ -1438,8 +1439,7 @@ CacheFile::RemoveChunkInternal(CacheFileChunk *aChunk, bool aCacheChunk)
AssertOwnsLock();
aChunk->mActiveChunk = false;
ReleaseOutsideLock(static_cast<CacheFileChunkListener *>(
aChunk->mFile.forget().take()));
ReleaseOutsideLock(nsRefPtr<CacheFileChunkListener>(aChunk->mFile.forget()).forget());
if (aCacheChunk) {
mCachedChunks.Put(aChunk->Index(), aChunk);
@ -1542,7 +1542,7 @@ CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus)
found = mInputs.RemoveElement(aInput);
MOZ_ASSERT(found);
ReleaseOutsideLock(static_cast<nsIInputStream*>(aInput));
ReleaseOutsideLock(already_AddRefed<nsIInputStream>(static_cast<nsIInputStream*>(aInput)));
if (!mMemoryOnly)
WriteMetadataIfNeededLocked();
@ -1835,8 +1835,9 @@ CacheFile::WriteAllCachedChunks(const uint32_t& aIdx,
MOZ_ASSERT(aChunk->IsReady());
NS_ADDREF(aChunk);
file->ReleaseOutsideLock(aChunk);
// this would be cleaner if we had an nsRefPtr constructor
// that took a nsRefPtr<Derived>
file->ReleaseOutsideLock(nsRefPtr<nsISupports>(aChunk));
return PL_DHASH_REMOVE;
}
@ -1936,7 +1937,7 @@ CacheFile::PadChunkWithZeroes(uint32_t aChunkIdx)
chunk->UpdateDataSize(chunk->DataSize(), kChunkSize - chunk->DataSize(),
false);
ReleaseOutsideLock(chunk.forget().take());
ReleaseOutsideLock(chunk.forget());
return NS_OK;
}

View File

@ -121,7 +121,7 @@ private:
void Lock();
void Unlock();
void AssertOwnsLock() const;
void ReleaseOutsideLock(nsISupports *aObject);
void ReleaseOutsideLock(nsRefPtr<nsISupports> aObject);
enum ECallerType {
READER = 0,
@ -216,7 +216,7 @@ private:
nsTArray<CacheFileInputStream*> mInputs;
CacheFileOutputStream *mOutput;
nsTArray<nsISupports*> mObjsToRelease;
nsTArray<nsRefPtr<nsISupports>> mObjsToRelease;
};
class CacheFileAutoLock {