mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Bug 1114999 - Part 3: Use automatic memory management for mObjsToRelease; r=novotny
This commit is contained in:
parent
c416f00994
commit
9bab0efb09
@ -10,6 +10,7 @@
|
|||||||
#include "CacheFileOutputStream.h"
|
#include "CacheFileOutputStream.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
#include "mozilla/DebugOnly.h"
|
#include "mozilla/DebugOnly.h"
|
||||||
|
#include "mozilla/Move.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsProxyRelease.h"
|
#include "nsProxyRelease.h"
|
||||||
@ -999,13 +1000,13 @@ CacheFile::Lock()
|
|||||||
void
|
void
|
||||||
CacheFile::Unlock()
|
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);
|
objs.SwapElements(mObjsToRelease);
|
||||||
|
|
||||||
mLock.Unlock();
|
mLock.Unlock();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < objs.Length(); i++)
|
|
||||||
objs[i]->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1015,11 +1016,11 @@ CacheFile::AssertOwnsLock() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CacheFile::ReleaseOutsideLock(nsISupports *aObject)
|
CacheFile::ReleaseOutsideLock(nsRefPtr<nsISupports> aObject)
|
||||||
{
|
{
|
||||||
AssertOwnsLock();
|
AssertOwnsLock();
|
||||||
|
|
||||||
mObjsToRelease.AppendElement(aObject);
|
mObjsToRelease.AppendElement(Move(aObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
@ -1438,8 +1439,7 @@ CacheFile::RemoveChunkInternal(CacheFileChunk *aChunk, bool aCacheChunk)
|
|||||||
AssertOwnsLock();
|
AssertOwnsLock();
|
||||||
|
|
||||||
aChunk->mActiveChunk = false;
|
aChunk->mActiveChunk = false;
|
||||||
ReleaseOutsideLock(static_cast<CacheFileChunkListener *>(
|
ReleaseOutsideLock(nsRefPtr<CacheFileChunkListener>(aChunk->mFile.forget()).forget());
|
||||||
aChunk->mFile.forget().take()));
|
|
||||||
|
|
||||||
if (aCacheChunk) {
|
if (aCacheChunk) {
|
||||||
mCachedChunks.Put(aChunk->Index(), aChunk);
|
mCachedChunks.Put(aChunk->Index(), aChunk);
|
||||||
@ -1542,7 +1542,7 @@ CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus)
|
|||||||
found = mInputs.RemoveElement(aInput);
|
found = mInputs.RemoveElement(aInput);
|
||||||
MOZ_ASSERT(found);
|
MOZ_ASSERT(found);
|
||||||
|
|
||||||
ReleaseOutsideLock(static_cast<nsIInputStream*>(aInput));
|
ReleaseOutsideLock(already_AddRefed<nsIInputStream>(static_cast<nsIInputStream*>(aInput)));
|
||||||
|
|
||||||
if (!mMemoryOnly)
|
if (!mMemoryOnly)
|
||||||
WriteMetadataIfNeededLocked();
|
WriteMetadataIfNeededLocked();
|
||||||
@ -1835,8 +1835,9 @@ CacheFile::WriteAllCachedChunks(const uint32_t& aIdx,
|
|||||||
|
|
||||||
MOZ_ASSERT(aChunk->IsReady());
|
MOZ_ASSERT(aChunk->IsReady());
|
||||||
|
|
||||||
NS_ADDREF(aChunk);
|
// this would be cleaner if we had an nsRefPtr constructor
|
||||||
file->ReleaseOutsideLock(aChunk);
|
// that took a nsRefPtr<Derived>
|
||||||
|
file->ReleaseOutsideLock(nsRefPtr<nsISupports>(aChunk));
|
||||||
|
|
||||||
return PL_DHASH_REMOVE;
|
return PL_DHASH_REMOVE;
|
||||||
}
|
}
|
||||||
@ -1936,7 +1937,7 @@ CacheFile::PadChunkWithZeroes(uint32_t aChunkIdx)
|
|||||||
chunk->UpdateDataSize(chunk->DataSize(), kChunkSize - chunk->DataSize(),
|
chunk->UpdateDataSize(chunk->DataSize(), kChunkSize - chunk->DataSize(),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
ReleaseOutsideLock(chunk.forget().take());
|
ReleaseOutsideLock(chunk.forget());
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ private:
|
|||||||
void Lock();
|
void Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
void AssertOwnsLock() const;
|
void AssertOwnsLock() const;
|
||||||
void ReleaseOutsideLock(nsISupports *aObject);
|
void ReleaseOutsideLock(nsRefPtr<nsISupports> aObject);
|
||||||
|
|
||||||
enum ECallerType {
|
enum ECallerType {
|
||||||
READER = 0,
|
READER = 0,
|
||||||
@ -216,7 +216,7 @@ private:
|
|||||||
nsTArray<CacheFileInputStream*> mInputs;
|
nsTArray<CacheFileInputStream*> mInputs;
|
||||||
CacheFileOutputStream *mOutput;
|
CacheFileOutputStream *mOutput;
|
||||||
|
|
||||||
nsTArray<nsISupports*> mObjsToRelease;
|
nsTArray<nsRefPtr<nsISupports>> mObjsToRelease;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CacheFileAutoLock {
|
class CacheFileAutoLock {
|
||||||
|
Loading…
Reference in New Issue
Block a user