Merge backout

This commit is contained in:
Chris Jones 2011-03-31 18:58:11 -05:00
commit 912845af59
165 changed files with 2718 additions and 1375 deletions

View File

@ -42,6 +42,7 @@
#include <nsDeque.h> #include <nsDeque.h>
#include "Layers.h" #include "Layers.h"
#include "ImageLayers.h" #include "ImageLayers.h"
#include "nsAutoLock.h"
#include "nsClassHashtable.h" #include "nsClassHashtable.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "nsSize.h" #include "nsSize.h"

View File

@ -36,10 +36,10 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "mozilla/Monitor.h"
#include "mozilla/XPCOM.h" #include "mozilla/XPCOM.h"
#include "nsMediaCache.h" #include "nsMediaCache.h"
#include "nsAutoLock.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDirectoryServiceUtils.h" #include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h" #include "nsDirectoryServiceDefs.h"
@ -51,8 +51,6 @@
#include "prlog.h" #include "prlog.h"
#include "nsIPrivateBrowsingService.h" #include "nsIPrivateBrowsingService.h"
using namespace mozilla;
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo* gMediaCacheLog; PRLogModuleInfo* gMediaCacheLog;
#define LOG(type, msg) PR_LOG(gMediaCacheLog, type, msg) #define LOG(type, msg) PR_LOG(gMediaCacheLog, type, msg)
@ -79,6 +77,9 @@ static const PRUint32 REPLAY_DELAY = 30;
// can. // can.
static const PRUint32 FREE_BLOCK_SCAN_LIMIT = 16; static const PRUint32 FREE_BLOCK_SCAN_LIMIT = 16;
using mozilla::TimeStamp;
using mozilla::TimeDuration;
#ifdef DEBUG #ifdef DEBUG
// Turn this on to do very expensive cache state validation // Turn this on to do very expensive cache state validation
// #define DEBUG_VERIFY_CACHE // #define DEBUG_VERIFY_CACHE
@ -134,7 +135,7 @@ public:
}; };
nsMediaCache() : mNextResourceID(1), nsMediaCache() : mNextResourceID(1),
mMonitor("nsMediaCache.mMonitor"), mMonitor(nsAutoMonitor::NewMonitor("media.cache")),
mFD(nsnull), mFDCurrentPos(0), mUpdateQueued(PR_FALSE) mFD(nsnull), mFDCurrentPos(0), mUpdateQueued(PR_FALSE)
#ifdef DEBUG #ifdef DEBUG
, mInUpdate(PR_FALSE) , mInUpdate(PR_FALSE)
@ -149,6 +150,9 @@ public:
if (mFD) { if (mFD) {
PR_Close(mFD); PR_Close(mFD);
} }
if (mMonitor) {
nsAutoMonitor::DestroyMonitor(mMonitor);
}
MOZ_COUNT_DTOR(nsMediaCache); MOZ_COUNT_DTOR(nsMediaCache);
} }
@ -227,7 +231,7 @@ public:
void Verify() {} void Verify() {}
#endif #endif
Monitor& GetMonitor() { return mMonitor; } PRMonitor* Monitor() { return mMonitor; }
/** /**
* An iterator that makes it easy to iterate through all streams that * An iterator that makes it easy to iterate through all streams that
@ -350,7 +354,7 @@ protected:
// The monitor protects all the data members here. Also, off-main-thread // The monitor protects all the data members here. Also, off-main-thread
// readers that need to block will Wait() on this monitor. When new // readers that need to block will Wait() on this monitor. When new
// data becomes available in the cache, we NotifyAll() on this monitor. // data becomes available in the cache, we NotifyAll() on this monitor.
Monitor mMonitor; PRMonitor* mMonitor;
// The Blocks describing the cache entries. // The Blocks describing the cache entries.
nsTArray<Block> mIndex; nsTArray<Block> mIndex;
// The file descriptor of the cache file. The file will be deleted // The file descriptor of the cache file. The file will be deleted
@ -545,6 +549,11 @@ nsMediaCache::Init()
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
NS_ASSERTION(!mFD, "Cache file already open?"); NS_ASSERTION(!mFD, "Cache file already open?");
if (!mMonitor) {
// the constructor failed
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIFile> tmp; nsCOMPtr<nsIFile> tmp;
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmp)); nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
@ -608,7 +617,7 @@ nsMediaCache::Flush()
void void
nsMediaCache::FlushInternal() nsMediaCache::FlushInternal()
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) { for (PRUint32 blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) {
FreeBlock(blockIndex); FreeBlock(blockIndex);
@ -663,7 +672,7 @@ nsresult
nsMediaCache::ReadCacheFile(PRInt64 aOffset, void* aData, PRInt32 aLength, nsMediaCache::ReadCacheFile(PRInt64 aOffset, void* aData, PRInt32 aLength,
PRInt32* aBytes) PRInt32* aBytes)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
if (!mFD) if (!mFD)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -685,7 +694,7 @@ nsMediaCache::ReadCacheFile(PRInt64 aOffset, void* aData, PRInt32 aLength,
nsresult nsresult
nsMediaCache::ReadCacheFileAllBytes(PRInt64 aOffset, void* aData, PRInt32 aLength) nsMediaCache::ReadCacheFileAllBytes(PRInt64 aOffset, void* aData, PRInt32 aLength)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRInt64 offset = aOffset; PRInt64 offset = aOffset;
PRInt32 count = aLength; PRInt32 count = aLength;
@ -708,7 +717,7 @@ nsMediaCache::ReadCacheFileAllBytes(PRInt64 aOffset, void* aData, PRInt32 aLengt
nsresult nsresult
nsMediaCache::WriteCacheFile(PRInt64 aOffset, const void* aData, PRInt32 aLength) nsMediaCache::WriteCacheFile(PRInt64 aOffset, const void* aData, PRInt32 aLength)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
if (!mFD) if (!mFD)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -749,7 +758,7 @@ PRInt32
nsMediaCache::FindBlockForIncomingData(TimeStamp aNow, nsMediaCache::FindBlockForIncomingData(TimeStamp aNow,
nsMediaCacheStream* aStream) nsMediaCacheStream* aStream)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRInt32 blockIndex = FindReusableBlock(aNow, aStream, PRInt32 blockIndex = FindReusableBlock(aNow, aStream,
aStream->mChannelOffset/BLOCK_SIZE, PR_INT32_MAX); aStream->mChannelOffset/BLOCK_SIZE, PR_INT32_MAX);
@ -792,7 +801,7 @@ nsMediaCache::AppendMostReusableBlock(BlockList* aBlockList,
nsTArray<PRUint32>* aResult, nsTArray<PRUint32>* aResult,
PRInt32 aBlockIndexLimit) PRInt32 aBlockIndexLimit)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRInt32 blockIndex = aBlockList->GetLastBlock(); PRInt32 blockIndex = aBlockList->GetLastBlock();
if (blockIndex < 0) if (blockIndex < 0)
@ -816,7 +825,7 @@ nsMediaCache::FindReusableBlock(TimeStamp aNow,
PRInt32 aForStreamBlock, PRInt32 aForStreamBlock,
PRInt32 aMaxSearchBlockIndex) PRInt32 aMaxSearchBlockIndex)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRUint32 length = PR_MIN(PRUint32(aMaxSearchBlockIndex), mIndex.Length()); PRUint32 length = PR_MIN(PRUint32(aMaxSearchBlockIndex), mIndex.Length());
@ -910,7 +919,7 @@ nsMediaCache::GetBlockOwner(PRInt32 aBlockIndex, nsMediaCacheStream* aStream)
void void
nsMediaCache::SwapBlocks(PRInt32 aBlockIndex1, PRInt32 aBlockIndex2) nsMediaCache::SwapBlocks(PRInt32 aBlockIndex1, PRInt32 aBlockIndex2)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
Block* block1 = &mIndex[aBlockIndex1]; Block* block1 = &mIndex[aBlockIndex1];
Block* block2 = &mIndex[aBlockIndex2]; Block* block2 = &mIndex[aBlockIndex2];
@ -990,7 +999,7 @@ nsMediaCache::AddBlockOwnerAsReadahead(PRInt32 aBlockIndex,
void void
nsMediaCache::FreeBlock(PRInt32 aBlock) nsMediaCache::FreeBlock(PRInt32 aBlock)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
Block* block = &mIndex[aBlock]; Block* block = &mIndex[aBlock];
if (block->mOwners.IsEmpty()) { if (block->mOwners.IsEmpty()) {
@ -1013,7 +1022,7 @@ nsMediaCache::FreeBlock(PRInt32 aBlock)
TimeDuration TimeDuration
nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock) nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
NS_ASSERTION(!IsBlockFree(aBlock), "aBlock is free"); NS_ASSERTION(!IsBlockFree(aBlock), "aBlock is free");
Block* block = &mIndex[aBlock]; Block* block = &mIndex[aBlock];
@ -1063,7 +1072,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock)
TimeDuration TimeDuration
nsMediaCache::PredictNextUseForIncomingData(nsMediaCacheStream* aStream) nsMediaCache::PredictNextUseForIncomingData(nsMediaCacheStream* aStream)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRInt64 bytesAhead = aStream->mChannelOffset - aStream->mStreamOffset; PRInt64 bytesAhead = aStream->mChannelOffset - aStream->mStreamOffset;
if (bytesAhead <= -BLOCK_SIZE) { if (bytesAhead <= -BLOCK_SIZE) {
@ -1091,7 +1100,7 @@ nsMediaCache::Update()
nsAutoTArray<StreamAction,10> actions; nsAutoTArray<StreamAction,10> actions;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mUpdateQueued = PR_FALSE; mUpdateQueued = PR_FALSE;
#ifdef DEBUG #ifdef DEBUG
mInUpdate = PR_TRUE; mInUpdate = PR_TRUE;
@ -1373,8 +1382,8 @@ nsMediaCache::Update()
// Close the streams that failed due to error. This will cause all // Close the streams that failed due to error. This will cause all
// client Read and Seek operations on those streams to fail. Blocked // client Read and Seek operations on those streams to fail. Blocked
// Reads will also be woken up. // Reads will also be woken up.
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
stream->CloseInternal(mon); stream->CloseInternal(&mon);
} }
} }
} }
@ -1394,7 +1403,7 @@ public:
void void
nsMediaCache::QueueUpdate() nsMediaCache::QueueUpdate()
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
// Queuing an update while we're in an update raises a high risk of // Queuing an update while we're in an update raises a high risk of
// triggering endless events // triggering endless events
@ -1411,7 +1420,7 @@ nsMediaCache::QueueUpdate()
void void
nsMediaCache::Verify() nsMediaCache::Verify()
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
mFreeBlocks.Verify(); mFreeBlocks.Verify();
for (PRUint32 i = 0; i < mStreams.Length(); ++i) { for (PRUint32 i = 0; i < mStreams.Length(); ++i) {
@ -1443,7 +1452,7 @@ void
nsMediaCache::InsertReadaheadBlock(BlockOwner* aBlockOwner, nsMediaCache::InsertReadaheadBlock(BlockOwner* aBlockOwner,
PRInt32 aBlockIndex) PRInt32 aBlockIndex)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
// Find the last block whose stream block is before aBlockIndex's // Find the last block whose stream block is before aBlockIndex's
// stream block, and insert after it // stream block, and insert after it
@ -1469,7 +1478,7 @@ void
nsMediaCache::AllocateAndWriteBlock(nsMediaCacheStream* aStream, const void* aData, nsMediaCache::AllocateAndWriteBlock(nsMediaCacheStream* aStream, const void* aData,
nsMediaCacheStream::ReadMode aMode) nsMediaCacheStream::ReadMode aMode)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRInt32 streamBlockIndex = aStream->mChannelOffset/BLOCK_SIZE; PRInt32 streamBlockIndex = aStream->mChannelOffset/BLOCK_SIZE;
@ -1547,7 +1556,7 @@ nsMediaCache::OpenStream(nsMediaCacheStream* aStream)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
LOG(PR_LOG_DEBUG, ("Stream %p opened", aStream)); LOG(PR_LOG_DEBUG, ("Stream %p opened", aStream));
mStreams.AppendElement(aStream); mStreams.AppendElement(aStream);
aStream->mResourceID = mNextResourceID++; aStream->mResourceID = mNextResourceID++;
@ -1561,7 +1570,7 @@ nsMediaCache::ReleaseStream(nsMediaCacheStream* aStream)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
LOG(PR_LOG_DEBUG, ("Stream %p closed", aStream)); LOG(PR_LOG_DEBUG, ("Stream %p closed", aStream));
mStreams.RemoveElement(aStream); mStreams.RemoveElement(aStream);
} }
@ -1569,7 +1578,7 @@ nsMediaCache::ReleaseStream(nsMediaCacheStream* aStream)
void void
nsMediaCache::ReleaseStreamBlocks(nsMediaCacheStream* aStream) nsMediaCache::ReleaseStreamBlocks(nsMediaCacheStream* aStream)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
// XXX scanning the entire stream doesn't seem great, if not much of it // XXX scanning the entire stream doesn't seem great, if not much of it
// is cached, but the only easy alternative is to scan the entire cache // is cached, but the only easy alternative is to scan the entire cache
@ -1609,7 +1618,7 @@ nsMediaCache::NoteBlockUsage(nsMediaCacheStream* aStream, PRInt32 aBlockIndex,
nsMediaCacheStream::ReadMode aMode, nsMediaCacheStream::ReadMode aMode,
TimeStamp aNow) TimeStamp aNow)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
if (aBlockIndex < 0) { if (aBlockIndex < 0) {
// this block is not in the cache yet // this block is not in the cache yet
@ -1641,7 +1650,7 @@ nsMediaCache::NoteBlockUsage(nsMediaCacheStream* aStream, PRInt32 aBlockIndex,
void void
nsMediaCache::NoteSeek(nsMediaCacheStream* aStream, PRInt64 aOldOffset) nsMediaCache::NoteSeek(nsMediaCacheStream* aStream, PRInt64 aOldOffset)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
if (aOldOffset < aStream->mStreamOffset) { if (aOldOffset < aStream->mStreamOffset) {
// We seeked forward. Convert blocks from readahead to played. // We seeked forward. Convert blocks from readahead to played.
@ -1697,7 +1706,7 @@ nsMediaCacheStream::NotifyDataLength(PRInt64 aLength)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
mStreamLength = aLength; mStreamLength = aLength;
} }
@ -1706,7 +1715,7 @@ nsMediaCacheStream::NotifyDataStarted(PRInt64 aOffset)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
NS_WARN_IF_FALSE(aOffset == mChannelOffset, NS_WARN_IF_FALSE(aOffset == mChannelOffset,
"Server is giving us unexpected offset"); "Server is giving us unexpected offset");
mChannelOffset = aOffset; mChannelOffset = aOffset;
@ -1757,7 +1766,7 @@ nsMediaCacheStream::NotifyDataReceived(PRInt64 aSize, const char* aData,
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
PRInt64 size = aSize; PRInt64 size = aSize;
const char* data = aData; const char* data = aData;
@ -1826,7 +1835,7 @@ nsMediaCacheStream::NotifyDataEnded(nsresult aStatus)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
PRInt32 blockOffset = PRInt32(mChannelOffset%BLOCK_SIZE); PRInt32 blockOffset = PRInt32(mChannelOffset%BLOCK_SIZE);
if (blockOffset > 0) { if (blockOffset > 0) {
@ -1864,7 +1873,7 @@ nsMediaCacheStream::~nsMediaCacheStream()
void void
nsMediaCacheStream::SetSeekable(PRBool aIsSeekable) nsMediaCacheStream::SetSeekable(PRBool aIsSeekable)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
NS_ASSERTION(mIsSeekable || aIsSeekable || NS_ASSERTION(mIsSeekable || aIsSeekable ||
mChannelOffset == 0, "channel offset must be zero when we become non-seekable"); mChannelOffset == 0, "channel offset must be zero when we become non-seekable");
mIsSeekable = aIsSeekable; mIsSeekable = aIsSeekable;
@ -1876,7 +1885,7 @@ nsMediaCacheStream::SetSeekable(PRBool aIsSeekable)
PRBool PRBool
nsMediaCacheStream::IsSeekable() nsMediaCacheStream::IsSeekable()
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
return mIsSeekable; return mIsSeekable;
} }
@ -1885,8 +1894,8 @@ nsMediaCacheStream::Close()
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
CloseInternal(mon); CloseInternal(&mon);
// Queue an Update since we may have created more free space. Don't do // Queue an Update since we may have created more free space. Don't do
// it from CloseInternal since that gets called by Update() itself // it from CloseInternal since that gets called by Update() itself
// sometimes, and we try to not to queue updates from Update(). // sometimes, and we try to not to queue updates from Update().
@ -1894,7 +1903,7 @@ nsMediaCacheStream::Close()
} }
void void
nsMediaCacheStream::CloseInternal(MonitorAutoEnter& aMonitor) nsMediaCacheStream::CloseInternal(nsAutoMonitor* aMonitor)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
@ -1903,13 +1912,13 @@ nsMediaCacheStream::CloseInternal(MonitorAutoEnter& aMonitor)
mClosed = PR_TRUE; mClosed = PR_TRUE;
gMediaCache->ReleaseStreamBlocks(this); gMediaCache->ReleaseStreamBlocks(this);
// Wake up any blocked readers // Wake up any blocked readers
aMonitor.NotifyAll(); aMonitor->NotifyAll();
} }
void void
nsMediaCacheStream::Pin() nsMediaCacheStream::Pin()
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
++mPinCount; ++mPinCount;
// Queue an Update since we may no longer want to read more into the // Queue an Update since we may no longer want to read more into the
// cache, if this stream's block have become non-evictable // cache, if this stream's block have become non-evictable
@ -1919,7 +1928,7 @@ nsMediaCacheStream::Pin()
void void
nsMediaCacheStream::Unpin() nsMediaCacheStream::Unpin()
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
NS_ASSERTION(mPinCount > 0, "Unbalanced Unpin"); NS_ASSERTION(mPinCount > 0, "Unbalanced Unpin");
--mPinCount; --mPinCount;
// Queue an Update since we may be able to read more into the // Queue an Update since we may be able to read more into the
@ -1930,28 +1939,28 @@ nsMediaCacheStream::Unpin()
PRInt64 PRInt64
nsMediaCacheStream::GetLength() nsMediaCacheStream::GetLength()
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
return mStreamLength; return mStreamLength;
} }
PRInt64 PRInt64
nsMediaCacheStream::GetNextCachedData(PRInt64 aOffset) nsMediaCacheStream::GetNextCachedData(PRInt64 aOffset)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
return GetNextCachedDataInternal(aOffset); return GetNextCachedDataInternal(aOffset);
} }
PRInt64 PRInt64
nsMediaCacheStream::GetCachedDataEnd(PRInt64 aOffset) nsMediaCacheStream::GetCachedDataEnd(PRInt64 aOffset)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
return GetCachedDataEndInternal(aOffset); return GetCachedDataEndInternal(aOffset);
} }
PRBool PRBool
nsMediaCacheStream::IsDataCachedToEndOfStream(PRInt64 aOffset) nsMediaCacheStream::IsDataCachedToEndOfStream(PRInt64 aOffset)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (mStreamLength < 0) if (mStreamLength < 0)
return PR_FALSE; return PR_FALSE;
return GetCachedDataEndInternal(aOffset) >= mStreamLength; return GetCachedDataEndInternal(aOffset) >= mStreamLength;
@ -1960,7 +1969,7 @@ nsMediaCacheStream::IsDataCachedToEndOfStream(PRInt64 aOffset)
PRInt64 PRInt64
nsMediaCacheStream::GetCachedDataEndInternal(PRInt64 aOffset) nsMediaCacheStream::GetCachedDataEndInternal(PRInt64 aOffset)
{ {
gMediaCache->GetMonitor().AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(gMediaCache->Monitor());
PRUint32 startBlockIndex = aOffset/BLOCK_SIZE; PRUint32 startBlockIndex = aOffset/BLOCK_SIZE;
PRUint32 blockIndex = startBlockIndex; PRUint32 blockIndex = startBlockIndex;
while (blockIndex < mBlocks.Length() && mBlocks[blockIndex] != -1) { while (blockIndex < mBlocks.Length() && mBlocks[blockIndex] != -1) {
@ -1983,7 +1992,7 @@ nsMediaCacheStream::GetCachedDataEndInternal(PRInt64 aOffset)
PRInt64 PRInt64
nsMediaCacheStream::GetNextCachedDataInternal(PRInt64 aOffset) nsMediaCacheStream::GetNextCachedDataInternal(PRInt64 aOffset)
{ {
gMediaCache->GetMonitor().AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(gMediaCache->Monitor());
if (aOffset == mStreamLength) if (aOffset == mStreamLength)
return -1; return -1;
@ -2030,7 +2039,7 @@ nsMediaCacheStream::GetNextCachedDataInternal(PRInt64 aOffset)
void void
nsMediaCacheStream::SetReadMode(ReadMode aMode) nsMediaCacheStream::SetReadMode(ReadMode aMode)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (aMode == mCurrentMode) if (aMode == mCurrentMode)
return; return;
mCurrentMode = aMode; mCurrentMode = aMode;
@ -2041,7 +2050,7 @@ void
nsMediaCacheStream::SetPlaybackRate(PRUint32 aBytesPerSecond) nsMediaCacheStream::SetPlaybackRate(PRUint32 aBytesPerSecond)
{ {
NS_ASSERTION(aBytesPerSecond > 0, "Zero playback rate not allowed"); NS_ASSERTION(aBytesPerSecond > 0, "Zero playback rate not allowed");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (aBytesPerSecond == mPlaybackBytesPerSecond) if (aBytesPerSecond == mPlaybackBytesPerSecond)
return; return;
mPlaybackBytesPerSecond = aBytesPerSecond; mPlaybackBytesPerSecond = aBytesPerSecond;
@ -2053,7 +2062,7 @@ nsMediaCacheStream::Seek(PRInt32 aWhence, PRInt64 aOffset)
{ {
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (mClosed) if (mClosed)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2087,7 +2096,7 @@ nsMediaCacheStream::Tell()
{ {
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
return mStreamOffset; return mStreamOffset;
} }
@ -2096,7 +2105,7 @@ nsMediaCacheStream::Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes)
{ {
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (mClosed) if (mClosed)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2181,7 +2190,7 @@ nsMediaCacheStream::ReadFromCache(char* aBuffer,
PRInt64 aOffset, PRInt64 aOffset,
PRInt64 aCount) PRInt64 aCount)
{ {
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
if (mClosed) if (mClosed)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2259,7 +2268,7 @@ nsMediaCacheStream::InitAsClone(nsMediaCacheStream* aOriginal)
mResourceID = aOriginal->mResourceID; mResourceID = aOriginal->mResourceID;
// Grab cache blocks from aOriginal as readahead blocks for our stream // Grab cache blocks from aOriginal as readahead blocks for our stream
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
mPrincipal = aOriginal->mPrincipal; mPrincipal = aOriginal->mPrincipal;
mStreamLength = aOriginal->mStreamLength; mStreamLength = aOriginal->mStreamLength;
@ -2289,7 +2298,7 @@ nsresult nsMediaCacheStream::GetCachedRanges(nsTArray<nsByteRange>& aRanges)
{ {
// Take the monitor, so that the cached data ranges can't grow while we're // Take the monitor, so that the cached data ranges can't grow while we're
// trying to loop over them. // trying to loop over them.
MonitorAutoEnter mon(gMediaCache->GetMonitor()); nsAutoMonitor mon(gMediaCache->Monitor());
// We must be pinned while running this, otherwise the cached data ranges may // We must be pinned while running this, otherwise the cached data ranges may
// shrink while we're trying to loop over them. // shrink while we're trying to loop over them.

View File

@ -40,13 +40,11 @@
#define nsMediaCache_h_ #define nsMediaCache_h_
#include "nsTArray.h" #include "nsTArray.h"
#include "nsAutoLock.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
class nsByteRange; class nsByteRange;
namespace mozilla {
class MonitorAutoEnter;
}
/** /**
* Media applications want fast, "on demand" random access to media data, * Media applications want fast, "on demand" random access to media data,
@ -211,8 +209,6 @@ class nsMediaChannelStream;
* This class can be directly embedded as a value. * This class can be directly embedded as a value.
*/ */
class nsMediaCacheStream { class nsMediaCacheStream {
typedef mozilla::MonitorAutoEnter MonitorAutoEnter;
public: public:
enum { enum {
// This needs to be a power of two // This needs to be a power of two
@ -433,7 +429,7 @@ private:
// aMonitor is the nsAutoMonitor wrapper holding the cache monitor. // aMonitor is the nsAutoMonitor wrapper holding the cache monitor.
// This is used to NotifyAll to wake up threads that might be // This is used to NotifyAll to wake up threads that might be
// blocked on reading from this stream. // blocked on reading from this stream.
void CloseInternal(MonitorAutoEnter& aMonitor); void CloseInternal(nsAutoMonitor* aMonitor);
// Update mPrincipal given that data has been received from aPrincipal // Update mPrincipal given that data has been received from aPrincipal
void UpdatePrincipal(nsIPrincipal* aPrincipal); void UpdatePrincipal(nsIPrincipal* aPrincipal);

View File

@ -47,6 +47,7 @@
#include "nsIDOMHTMLMediaElement.h" #include "nsIDOMHTMLMediaElement.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsHTMLMediaElement.h" #include "nsHTMLMediaElement.h"
#include "nsAutoLock.h"
#include "nsIRenderingContext.h" #include "nsIRenderingContext.h"
#include "gfxContext.h" #include "gfxContext.h"
#include "nsPresContext.h" #include "nsPresContext.h"
@ -56,8 +57,6 @@
#include "nsSVGEffects.h" #include "nsSVGEffects.h"
#endif #endif
using namespace mozilla;
// Number of milliseconds between progress events as defined by spec // Number of milliseconds between progress events as defined by spec
#define PROGRESS_MS 350 #define PROGRESS_MS 350
@ -76,7 +75,7 @@ nsMediaDecoder::nsMediaDecoder() :
mElement(0), mElement(0),
mRGBWidth(-1), mRGBWidth(-1),
mRGBHeight(-1), mRGBHeight(-1),
mVideoUpdateLock("nsMediaDecoder.mVideoUpdateLock"), mVideoUpdateLock(nsnull),
mPixelAspectRatio(1.0), mPixelAspectRatio(1.0),
mFrameBufferLength(0), mFrameBufferLength(0),
mPinnedForSeek(PR_FALSE), mPinnedForSeek(PR_FALSE),
@ -89,13 +88,19 @@ nsMediaDecoder::nsMediaDecoder() :
nsMediaDecoder::~nsMediaDecoder() nsMediaDecoder::~nsMediaDecoder()
{ {
if (mVideoUpdateLock) {
nsAutoLock::DestroyLock(mVideoUpdateLock);
mVideoUpdateLock = nsnull;
}
MOZ_COUNT_DTOR(nsMediaDecoder); MOZ_COUNT_DTOR(nsMediaDecoder);
} }
PRBool nsMediaDecoder::Init(nsHTMLMediaElement* aElement) PRBool nsMediaDecoder::Init(nsHTMLMediaElement* aElement)
{ {
mElement = aElement; mElement = aElement;
return PR_TRUE; mVideoUpdateLock = nsAutoLock::NewLock("nsMediaDecoder::mVideoUpdateLock");
return mVideoUpdateLock != nsnull;
} }
void nsMediaDecoder::Shutdown() void nsMediaDecoder::Shutdown()
@ -137,7 +142,7 @@ void nsMediaDecoder::Invalidate()
PRBool invalidateFrame = PR_FALSE; PRBool invalidateFrame = PR_FALSE;
{ {
MutexAutoLock lock(mVideoUpdateLock); nsAutoLock lock(mVideoUpdateLock);
// Get mImageContainerSizeChanged while holding the lock. // Get mImageContainerSizeChanged while holding the lock.
invalidateFrame = mImageContainerSizeChanged; invalidateFrame = mImageContainerSizeChanged;
@ -253,7 +258,7 @@ void nsMediaDecoder::SetVideoData(const gfxIntSize& aSize,
Image* aImage, Image* aImage,
TimeStamp aTarget) TimeStamp aTarget)
{ {
MutexAutoLock lock(mVideoUpdateLock); nsAutoLock lock(mVideoUpdateLock);
if (mRGBWidth != aSize.width || mRGBHeight != aSize.height || if (mRGBWidth != aSize.width || mRGBHeight != aSize.height ||
mPixelAspectRatio != aPixelAspectRatio) { mPixelAspectRatio != aPixelAspectRatio) {
@ -282,7 +287,7 @@ void nsMediaDecoder::SetVideoData(const gfxIntSize& aSize,
double nsMediaDecoder::GetFrameDelay() double nsMediaDecoder::GetFrameDelay()
{ {
MutexAutoLock lock(mVideoUpdateLock); nsAutoLock lock(mVideoUpdateLock);
return mPaintDelay.ToSeconds(); return mPaintDelay.ToSeconds();
} }

View File

@ -48,7 +48,6 @@
#include "nsITimer.h" #include "nsITimer.h"
#include "ImageLayers.h" #include "ImageLayers.h"
#include "mozilla/Monitor.h" #include "mozilla/Monitor.h"
#include "mozilla/Mutex.h"
class nsHTMLMediaElement; class nsHTMLMediaElement;
class nsMediaStream; class nsMediaStream;
@ -90,7 +89,6 @@ public:
typedef mozilla::layers::ImageContainer ImageContainer; typedef mozilla::layers::ImageContainer ImageContainer;
typedef mozilla::layers::Image Image; typedef mozilla::layers::Image Image;
typedef mozilla::Monitor Monitor; typedef mozilla::Monitor Monitor;
typedef mozilla::Mutex Mutex;
nsMediaDecoder(); nsMediaDecoder();
virtual ~nsMediaDecoder(); virtual ~nsMediaDecoder();
@ -443,7 +441,7 @@ protected:
// to the RGB buffer must obtain this lock first to ensure that // to the RGB buffer must obtain this lock first to ensure that
// the video element does not use video data or sizes that are // the video element does not use video data or sizes that are
// in the midst of being changed. // in the midst of being changed.
Mutex mVideoUpdateLock; PRLock* mVideoUpdateLock;
// Pixel aspect ratio (ratio of the pixel width to pixel height) // Pixel aspect ratio (ratio of the pixel width to pixel height)
float mPixelAspectRatio; float mPixelAspectRatio;

View File

@ -35,11 +35,11 @@
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "mozilla/Mutex.h"
#include "nsDebug.h" #include "nsDebug.h"
#include "nsMediaStream.h" #include "nsMediaStream.h"
#include "nsMediaDecoder.h" #include "nsMediaDecoder.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsAutoLock.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIFileChannel.h" #include "nsIFileChannel.h"
@ -61,7 +61,7 @@
#define HTTP_OK_CODE 200 #define HTTP_OK_CODE 200
#define HTTP_PARTIAL_RESPONSE_CODE 206 #define HTTP_PARTIAL_RESPONSE_CODE 206
using namespace mozilla; using mozilla::TimeStamp;
nsMediaChannelStream::nsMediaChannelStream(nsMediaDecoder* aDecoder, nsMediaChannelStream::nsMediaChannelStream(nsMediaDecoder* aDecoder,
nsIChannel* aChannel, nsIURI* aURI) nsIChannel* aChannel, nsIURI* aURI)
@ -69,7 +69,7 @@ nsMediaChannelStream::nsMediaChannelStream(nsMediaDecoder* aDecoder,
mOffset(0), mSuspendCount(0), mOffset(0), mSuspendCount(0),
mReopenOnError(PR_FALSE), mIgnoreClose(PR_FALSE), mReopenOnError(PR_FALSE), mIgnoreClose(PR_FALSE),
mCacheStream(this), mCacheStream(this),
mLock("nsMediaChannelStream.mLock"), mLock(nsAutoLock::NewLock("media.channel.stream")),
mCacheSuspendCount(0) mCacheSuspendCount(0)
{ {
} }
@ -80,6 +80,9 @@ nsMediaChannelStream::~nsMediaChannelStream()
// Kill its reference to us since we're going away // Kill its reference to us since we're going away
mListener->Revoke(); mListener->Revoke();
} }
if (mLock) {
nsAutoLock::DestroyLock(mLock);
}
} }
// nsMediaChannelStream::Listener just observes the channel and // nsMediaChannelStream::Listener just observes the channel and
@ -268,7 +271,7 @@ nsMediaChannelStream::OnStartRequest(nsIRequest* aRequest)
} }
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.Start(TimeStamp::Now()); mChannelStatistics.Start(TimeStamp::Now());
} }
@ -294,7 +297,7 @@ nsMediaChannelStream::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
"How can OnStopRequest fire while we're suspended?"); "How can OnStopRequest fire while we're suspended?");
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now()); mChannelStatistics.Stop(TimeStamp::Now());
} }
@ -380,7 +383,7 @@ nsMediaChannelStream::OnDataAvailable(nsIRequest* aRequest,
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!"); NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.AddBytes(aCount); mChannelStatistics.AddBytes(aCount);
} }
@ -409,6 +412,8 @@ nsresult nsMediaChannelStream::Open(nsIStreamListener **aStreamListener)
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = mCacheStream.Init(); nsresult rv = mCacheStream.Init();
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@ -544,7 +549,7 @@ void nsMediaChannelStream::CloseChannel()
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now()); mChannelStatistics.Stop(TimeStamp::Now());
} }
@ -623,7 +628,7 @@ void nsMediaChannelStream::Suspend(PRBool aCloseImmediately)
element->DownloadSuspended(); element->DownloadSuspended();
} else if (mSuspendCount == 0) { } else if (mSuspendCount == 0) {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now()); mChannelStatistics.Stop(TimeStamp::Now());
} }
mChannel->Suspend(); mChannel->Suspend();
@ -651,7 +656,7 @@ void nsMediaChannelStream::Resume()
if (mChannel) { if (mChannel) {
// Just wake up our existing channel // Just wake up our existing channel
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mChannelStatistics.Start(TimeStamp::Now()); mChannelStatistics.Start(TimeStamp::Now());
} }
// if an error occurs after Resume, assume it's because the server // if an error occurs after Resume, assume it's because the server
@ -757,7 +762,7 @@ nsMediaChannelStream::CacheClientSeek(PRInt64 aOffset, PRBool aResume)
// No need to mess with the channel, since we're making a new one // No need to mess with the channel, since we're making a new one
--mSuspendCount; --mSuspendCount;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientSeek(aResume=true) without previous CacheClientSuspend!"); NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientSeek(aResume=true) without previous CacheClientSuspend!");
--mCacheSuspendCount; --mCacheSuspendCount;
} }
@ -775,7 +780,7 @@ nsresult
nsMediaChannelStream::CacheClientSuspend() nsMediaChannelStream::CacheClientSuspend()
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
++mCacheSuspendCount; ++mCacheSuspendCount;
} }
Suspend(PR_FALSE); Suspend(PR_FALSE);
@ -789,7 +794,7 @@ nsMediaChannelStream::CacheClientResume()
{ {
Resume(); Resume();
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientResume without previous CacheClientSuspend!"); NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientResume without previous CacheClientSuspend!");
--mCacheSuspendCount; --mCacheSuspendCount;
} }
@ -819,14 +824,14 @@ nsMediaChannelStream::IsDataCachedToEndOfStream(PRInt64 aOffset)
PRBool PRBool
nsMediaChannelStream::IsSuspendedByCache() nsMediaChannelStream::IsSuspendedByCache()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mCacheSuspendCount > 0; return mCacheSuspendCount > 0;
} }
PRBool PRBool
nsMediaChannelStream::IsSuspended() nsMediaChannelStream::IsSuspended()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mSuspendCount > 0; return mSuspendCount > 0;
} }
@ -857,7 +862,7 @@ nsMediaChannelStream::Unpin()
double double
nsMediaChannelStream::GetDownloadRate(PRPackedBool* aIsReliable) nsMediaChannelStream::GetDownloadRate(PRPackedBool* aIsReliable)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mChannelStatistics.GetRate(TimeStamp::Now(), aIsReliable); return mChannelStatistics.GetRate(TimeStamp::Now(), aIsReliable);
} }
@ -872,11 +877,14 @@ class nsMediaFileStream : public nsMediaStream
public: public:
nsMediaFileStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) : nsMediaFileStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
nsMediaStream(aDecoder, aChannel, aURI), mSize(-1), nsMediaStream(aDecoder, aChannel, aURI), mSize(-1),
mLock("nsMediaFileStream.mLock") mLock(nsAutoLock::NewLock("media.file.stream"))
{ {
} }
~nsMediaFileStream() ~nsMediaFileStream()
{ {
if (mLock) {
nsAutoLock::DestroyLock(mLock);
}
} }
// Main thread // Main thread
@ -927,7 +935,7 @@ private:
// Read or Seek is in progress since it resets various internal // Read or Seek is in progress since it resets various internal
// values to null. // values to null.
// This lock protects mSeekable and mInput. // This lock protects mSeekable and mInput.
Mutex mLock; PRLock* mLock;
// Seekable stream interface to file. This can be used from any // Seekable stream interface to file. This can be used from any
// thread. // thread.
@ -1033,7 +1041,7 @@ nsresult nsMediaFileStream::Close()
{ {
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mChannel) { if (mChannel) {
mChannel->Cancel(NS_ERROR_PARSED_DATA_CACHED); mChannel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
mChannel = nsnull; mChannel = nsnull;
@ -1079,7 +1087,7 @@ nsMediaStream* nsMediaFileStream::CloneData(nsMediaDecoder* aDecoder)
nsresult nsMediaFileStream::ReadFromCache(char* aBuffer, PRInt64 aOffset, PRUint32 aCount) nsresult nsMediaFileStream::ReadFromCache(char* aBuffer, PRInt64 aOffset, PRUint32 aCount)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mInput || !mSeekable) if (!mInput || !mSeekable)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
PRInt64 offset = 0; PRInt64 offset = 0;
@ -1108,7 +1116,7 @@ nsresult nsMediaFileStream::ReadFromCache(char* aBuffer, PRInt64 aOffset, PRUint
nsresult nsMediaFileStream::Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes) nsresult nsMediaFileStream::Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mInput) if (!mInput)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mInput->Read(aBuffer, aCount, aBytes); return mInput->Read(aBuffer, aCount, aBytes);
@ -1118,7 +1126,7 @@ nsresult nsMediaFileStream::Seek(PRInt32 aWhence, PRInt64 aOffset)
{ {
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mSeekable) if (!mSeekable)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mSeekable->Seek(aWhence, aOffset); return mSeekable->Seek(aWhence, aOffset);
@ -1128,7 +1136,7 @@ PRInt64 nsMediaFileStream::Tell()
{ {
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mSeekable) if (!mSeekable)
return 0; return 0;

View File

@ -38,7 +38,6 @@
#if !defined(nsMediaStream_h_) #if !defined(nsMediaStream_h_)
#define nsMediaStream_h_ #define nsMediaStream_h_
#include "mozilla/Mutex.h"
#include "mozilla/XPCOM.h" #include "mozilla/XPCOM.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
@ -46,6 +45,7 @@
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIChannelEventSink.h" #include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "prlock.h"
#include "nsMediaCache.h" #include "nsMediaCache.h"
// For HTTP seeking, if number of bytes needing to be // For HTTP seeking, if number of bytes needing to be
@ -344,8 +344,6 @@ protected:
*/ */
class nsMediaChannelStream : public nsMediaStream class nsMediaChannelStream : public nsMediaStream
{ {
typedef mozilla::Mutex Mutex;
public: public:
nsMediaChannelStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI); nsMediaChannelStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI);
~nsMediaChannelStream(); ~nsMediaChannelStream();
@ -470,7 +468,7 @@ protected:
nsMediaCacheStream mCacheStream; nsMediaCacheStream mCacheStream;
// This lock protects mChannelStatistics and mCacheSuspendCount // This lock protects mChannelStatistics and mCacheSuspendCount
Mutex mLock; PRLock* mLock;
nsChannelStatistics mChannelStatistics; nsChannelStatistics mChannelStatistics;
PRUint32 mCacheSuspendCount; PRUint32 mCacheSuspendCount;
}; };

View File

@ -59,6 +59,7 @@
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
// Other includes // Other includes
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDeque.h" #include "nsDeque.h"
@ -81,8 +82,6 @@
#include "nsDOMWorkerSecurityManager.h" #include "nsDOMWorkerSecurityManager.h"
#include "nsDOMWorkerTimeout.h" #include "nsDOMWorkerTimeout.h"
using namespace mozilla;
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo *gDOMThreadsLog = nsnull; PRLogModuleInfo *gDOMThreadsLog = nsnull;
#endif #endif
@ -373,7 +372,7 @@ public:
PRBool aClearQueue) { PRBool aClearQueue) {
NS_ASSERTION(aRunnable, "Null pointer!"); NS_ASSERTION(aRunnable, "Null pointer!");
gDOMThreadService->mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(gDOMThreadService->mMonitor);
if (NS_LIKELY(!aTimeoutInterval)) { if (NS_LIKELY(!aTimeoutInterval)) {
NS_ADDREF(aRunnable); NS_ADDREF(aRunnable);
@ -466,7 +465,7 @@ public:
JS_SetContextPrivate(cx, NULL); JS_SetContextPrivate(cx, NULL);
} }
MonitorAutoEnter mon(gDOMThreadService->mMonitor); nsAutoMonitor mon(gDOMThreadService->mMonitor);
killWorkerWhenDone = mKillWorkerWhenDone; killWorkerWhenDone = mKillWorkerWhenDone;
gDOMThreadService->WorkerComplete(this); gDOMThreadService->WorkerComplete(this);
mon.NotifyAll(); mon.NotifyAll();
@ -496,7 +495,7 @@ protected:
while (1) { while (1) {
nsCOMPtr<nsIRunnable> runnable; nsCOMPtr<nsIRunnable> runnable;
{ {
MonitorAutoEnter mon(gDOMThreadService->mMonitor); nsAutoMonitor mon(gDOMThreadService->mMonitor);
runnable = dont_AddRef((nsIRunnable*)mRunnables.PopFront()); runnable = dont_AddRef((nsIRunnable*)mRunnables.PopFront());
@ -573,7 +572,7 @@ DOMWorkerOperationCallback(JSContext* aCx)
JS_FlushCaches(aCx); JS_FlushCaches(aCx);
for (;;) { for (;;) {
MonitorAutoEnter mon(worker->Pool()->GetMonitor()); nsAutoMonitor mon(worker->Pool()->Monitor());
// There's a small chance that the worker was canceled after our check // There's a small chance that the worker was canceled after our check
// above in which case we shouldn't wait here. We're guaranteed not to // above in which case we shouldn't wait here. We're guaranteed not to
@ -729,7 +728,7 @@ DOMWorkerErrorReporter(JSContext* aCx,
*/ */
nsDOMThreadService::nsDOMThreadService() nsDOMThreadService::nsDOMThreadService()
: mMonitor("nsDOMThreadServer.mMonitor"), : mMonitor(nsnull),
mNavigatorStringsLoaded(PR_FALSE) mNavigatorStringsLoaded(PR_FALSE)
{ {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@ -748,6 +747,10 @@ nsDOMThreadService::~nsDOMThreadService()
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
Cleanup(); Cleanup();
if (mMonitor) {
nsAutoMonitor::DestroyMonitor(mMonitor);
}
} }
NS_IMPL_THREADSAFE_ISUPPORTS3(nsDOMThreadService, nsIEventTarget, NS_IMPL_THREADSAFE_ISUPPORTS3(nsDOMThreadService, nsIEventTarget,
@ -784,6 +787,9 @@ nsDOMThreadService::Init()
rv = mThreadPool->SetIdleThreadLimit(THREADPOOL_IDLE_THREADS); rv = mThreadPool->SetIdleThreadLimit(THREADPOOL_IDLE_THREADS);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mMonitor = nsAutoMonitor::NewMonitor("nsDOMThreadService::mMonitor");
NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
PRBool success = mWorkersInProgress.Init(); PRBool success = mWorkersInProgress.Init();
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
@ -884,7 +890,7 @@ nsDOMThreadService::Cleanup()
CancelWorkersForGlobal(nsnull); CancelWorkersForGlobal(nsnull);
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
NS_ASSERTION(!mPools.Count(), "Live workers left!"); NS_ASSERTION(!mPools.Count(), "Live workers left!");
mPools.Clear(); mPools.Clear();
@ -949,7 +955,7 @@ nsDOMThreadService::Dispatch(nsDOMWorker* aWorker,
nsRefPtr<nsDOMWorkerRunnable> workerRunnable; nsRefPtr<nsDOMWorkerRunnable> workerRunnable;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
if (mWorkersInProgress.Get(aWorker, getter_AddRefs(workerRunnable))) { if (mWorkersInProgress.Get(aWorker, getter_AddRefs(workerRunnable))) {
workerRunnable->PutRunnable(aRunnable, aTimeoutInterval, aClearQueue); workerRunnable->PutRunnable(aRunnable, aTimeoutInterval, aClearQueue);
@ -972,7 +978,7 @@ nsDOMThreadService::Dispatch(nsDOMWorker* aWorker,
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("Failed to dispatch runnable to thread pool!"); NS_WARNING("Failed to dispatch runnable to thread pool!");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
// We exited the monitor after inserting the runnable into the table so make // We exited the monitor after inserting the runnable into the table so make
// sure we're removing the right one! // sure we're removing the right one!
@ -1000,7 +1006,7 @@ nsDOMThreadService::SetWorkerTimeout(nsDOMWorker* aWorker,
NS_ASSERTION(mThreadPool, "Dispatch called after 'xpcom-shutdown'!"); NS_ASSERTION(mThreadPool, "Dispatch called after 'xpcom-shutdown'!");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
nsRefPtr<nsDOMWorkerRunnable> workerRunnable; nsRefPtr<nsDOMWorkerRunnable> workerRunnable;
if (mWorkersInProgress.Get(aWorker, getter_AddRefs(workerRunnable))) { if (mWorkersInProgress.Get(aWorker, getter_AddRefs(workerRunnable))) {
@ -1011,7 +1017,7 @@ nsDOMThreadService::SetWorkerTimeout(nsDOMWorker* aWorker,
void void
nsDOMThreadService::WorkerComplete(nsDOMWorkerRunnable* aRunnable) nsDOMThreadService::WorkerComplete(nsDOMWorkerRunnable* aRunnable)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
#ifdef DEBUG #ifdef DEBUG
nsRefPtr<nsDOMWorker>& debugWorker = aRunnable->mWorker; nsRefPtr<nsDOMWorker>& debugWorker = aRunnable->mWorker;
@ -1028,7 +1034,7 @@ nsDOMThreadService::WorkerComplete(nsDOMWorkerRunnable* aRunnable)
PRBool PRBool
nsDOMThreadService::QueueSuspendedWorker(nsDOMWorkerRunnable* aRunnable) nsDOMThreadService::QueueSuspendedWorker(nsDOMWorkerRunnable* aRunnable)
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
#ifdef DEBUG #ifdef DEBUG
{ {
@ -1085,7 +1091,7 @@ already_AddRefed<nsDOMWorkerPool>
nsDOMThreadService::GetPoolForGlobal(nsIScriptGlobalObject* aGlobalObject, nsDOMThreadService::GetPoolForGlobal(nsIScriptGlobalObject* aGlobalObject,
PRBool aRemove) PRBool aRemove)
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
nsRefPtr<nsDOMWorkerPool> pool; nsRefPtr<nsDOMWorkerPool> pool;
mPools.Get(aGlobalObject, getter_AddRefs(pool)); mPools.Get(aGlobalObject, getter_AddRefs(pool));
@ -1100,7 +1106,7 @@ nsDOMThreadService::GetPoolForGlobal(nsIScriptGlobalObject* aGlobalObject,
void void
nsDOMThreadService::TriggerOperationCallbackForPool(nsDOMWorkerPool* aPool) nsDOMThreadService::TriggerOperationCallbackForPool(nsDOMWorkerPool* aPool)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
// See if we need to trigger the operation callback on any currently running // See if we need to trigger the operation callback on any currently running
// contexts. // contexts.
@ -1117,7 +1123,7 @@ nsDOMThreadService::TriggerOperationCallbackForPool(nsDOMWorkerPool* aPool)
void void
nsDOMThreadService::RescheduleSuspendedWorkerForPool(nsDOMWorkerPool* aPool) nsDOMThreadService::RescheduleSuspendedWorkerForPool(nsDOMWorkerPool* aPool)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
PRUint32 count = mSuspendedWorkers.Length(); PRUint32 count = mSuspendedWorkers.Length();
if (!count) { if (!count) {
@ -1161,7 +1167,7 @@ nsDOMThreadService::CancelWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject)
if (pool) { if (pool) {
pool->Cancel(); pool->Cancel();
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
TriggerOperationCallbackForPool(pool); TriggerOperationCallbackForPool(pool);
RescheduleSuspendedWorkerForPool(pool); RescheduleSuspendedWorkerForPool(pool);
@ -1177,7 +1183,7 @@ nsDOMThreadService::SuspendWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject
if (pool) { if (pool) {
pool->Suspend(); pool->Suspend();
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
TriggerOperationCallbackForPool(pool); TriggerOperationCallbackForPool(pool);
} }
} }
@ -1191,7 +1197,7 @@ nsDOMThreadService::ResumeWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject)
if (pool) { if (pool) {
pool->Resume(); pool->Resume();
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
TriggerOperationCallbackForPool(pool); TriggerOperationCallbackForPool(pool);
RescheduleSuspendedWorkerForPool(pool); RescheduleSuspendedWorkerForPool(pool);
@ -1203,7 +1209,7 @@ nsDOMThreadService::NoteEmptyPool(nsDOMWorkerPool* aPool)
{ {
NS_ASSERTION(aPool, "Null pointer!"); NS_ASSERTION(aPool, "Null pointer!");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mPools.Remove(aPool->ScriptGlobalObject()); mPools.Remove(aPool->ScriptGlobalObject());
} }
@ -1222,7 +1228,7 @@ nsDOMThreadService::ChangeThreadPoolMaxThreads(PRInt16 aDelta)
{ {
NS_ENSURE_ARG(aDelta == 1 || aDelta == -1); NS_ENSURE_ARG(aDelta == 1 || aDelta == -1);
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
PRUint32 currentThreadCount; PRUint32 currentThreadCount;
nsresult rv = mThreadPool->GetThreadLimit(&currentThreadCount); nsresult rv = mThreadPool->GetThreadLimit(&currentThreadCount);
@ -1260,7 +1266,7 @@ nsDOMThreadService::NoteThreadsafeContractId(const nsACString& aContractId,
{ {
NS_ASSERTION(!aContractId.IsEmpty(), "Empty contract id!"); NS_ASSERTION(!aContractId.IsEmpty(), "Empty contract id!");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
#ifdef DEBUG #ifdef DEBUG
{ {
@ -1281,7 +1287,7 @@ nsDOMThreadService::GetContractIdThreadsafeStatus(const nsACString& aContractId)
{ {
NS_ASSERTION(!aContractId.IsEmpty(), "Empty contract id!"); NS_ASSERTION(!aContractId.IsEmpty(), "Empty contract id!");
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
PRBool isThreadsafe; PRBool isThreadsafe;
if (mThreadsafeContractIDs.Get(aContractId, &isThreadsafe)) { if (mThreadsafeContractIDs.Get(aContractId, &isThreadsafe)) {
@ -1392,7 +1398,7 @@ nsDOMThreadService::OnThreadCreated()
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
#ifdef DEBUG #ifdef DEBUG
JSContext** newContext = JSContext** newContext =
@ -1421,7 +1427,7 @@ nsDOMThreadService::OnThreadShuttingDown()
NS_WARN_IF_FALSE(cx, "Thread died with no context?"); NS_WARN_IF_FALSE(cx, "Thread died with no context?");
if (cx) { if (cx) {
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mJSContexts.RemoveElement(cx); mJSContexts.RemoveElement(cx);
} }
@ -1467,7 +1473,7 @@ nsDOMThreadService::RegisterWorker(nsDOMWorker* aWorker,
nsRefPtr<nsDOMWorkerPool> pool; nsRefPtr<nsDOMWorkerPool> pool;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
if (!mThreadPool) { if (!mThreadPool) {
// Shutting down! // Shutting down!
@ -1516,7 +1522,7 @@ nsDOMThreadService::RegisterWorker(nsDOMWorker* aWorker,
rv = pool->Init(); rv = pool->Init();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
PRBool success = mPools.Put(aGlobalObject, pool); PRBool success = mPools.Put(aGlobalObject, pool);
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);

View File

@ -47,13 +47,13 @@
// Other includes // Other includes
#include "jsapi.h" #include "jsapi.h"
#include "mozilla/Monitor.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
#include "nsRefPtrHashtable.h" #include "nsRefPtrHashtable.h"
#include "nsStringGlue.h" #include "nsStringGlue.h"
#include "nsTPtrArray.h" #include "nsTPtrArray.h"
#include "prmon.h"
#include "prlog.h" #include "prlog.h"
#ifdef PR_LOGGING #ifdef PR_LOGGING
@ -185,7 +185,7 @@ private:
// mMonitor protects all access to mWorkersInProgress and // mMonitor protects all access to mWorkersInProgress and
// mCreationsInProgress. // mCreationsInProgress.
mozilla::Monitor mMonitor; PRMonitor* mMonitor;
// A map from nsDOMWorkerThread to nsDOMWorkerRunnable. // A map from nsDOMWorkerThread to nsDOMWorkerRunnable.
nsRefPtrHashtable<nsVoidPtrHashKey, nsDOMWorkerRunnable> mWorkersInProgress; nsRefPtrHashtable<nsVoidPtrHashKey, nsDOMWorkerRunnable> mWorkersInProgress;

View File

@ -48,6 +48,7 @@
#include "jsdbgapi.h" #include "jsdbgapi.h"
#endif #endif
#include "nsAtomicRefcnt.h" #include "nsAtomicRefcnt.h"
#include "nsAutoLock.h"
#include "nsAXPCNativeCallContext.h" #include "nsAXPCNativeCallContext.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDOMClassInfo.h" #include "nsDOMClassInfo.h"
@ -69,8 +70,6 @@
#include "nsDOMWorkerTimeout.h" #include "nsDOMWorkerTimeout.h"
#include "nsDOMWorkerXHR.h" #include "nsDOMWorkerXHR.h"
using namespace mozilla;
class TestComponentThreadsafetyRunnable : public nsIRunnable class TestComponentThreadsafetyRunnable : public nsIRunnable
{ {
public: public:
@ -1352,7 +1351,7 @@ nsDOMWorker::nsDOMWorker(nsDOMWorker* aParent,
: mParent(aParent), : mParent(aParent),
mParentWN(aParentWN), mParentWN(aParentWN),
mPrivilegeModel(aPrivilegeModel), mPrivilegeModel(aPrivilegeModel),
mLock("nsDOMWorker.mLock"), mLock(nsnull),
mInnerScope(nsnull), mInnerScope(nsnull),
mGlobal(NULL), mGlobal(NULL),
mNextTimeoutId(0), mNextTimeoutId(0),
@ -1376,6 +1375,10 @@ nsDOMWorker::~nsDOMWorker()
mPool->NoteDyingWorker(this); mPool->NoteDyingWorker(this);
} }
if (mLock) {
nsAutoLock::DestroyLock(mLock);
}
NS_ASSERTION(!mFeatures.Length(), "Live features!"); NS_ASSERTION(!mFeatures.Length(), "Live features!");
NS_ASSERTION(!mQueuedRunnables.Length(), "Events that never ran!"); NS_ASSERTION(!mQueuedRunnables.Length(), "Events that never ran!");
@ -1497,7 +1500,7 @@ nsDOMWorker::PostCreate(nsIXPConnectWrappedNative* aWrapper,
JSContext* /* aCx */, JSContext* /* aCx */,
JSObject* /* aObj */) JSObject* /* aObj */)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mWrappedNative = aWrapper; mWrappedNative = aWrapper;
return NS_OK; return NS_OK;
} }
@ -1511,7 +1514,7 @@ nsDOMWorker::Trace(nsIXPConnectWrappedNative* /* aWrapper */,
PRBool canceled = PR_FALSE; PRBool canceled = PR_FALSE;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
canceled = mStatus == eKilled; canceled = mStatus == eKilled;
} }
@ -1534,7 +1537,7 @@ nsDOMWorker::Finalize(nsIXPConnectWrappedNative* /* aWrapper */,
// Clear our wrapped native now that it has died. // Clear our wrapped native now that it has died.
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mWrappedNative = nsnull; mWrappedNative = nsnull;
} }
@ -1669,6 +1672,9 @@ nsDOMWorker::InitializeInternal(nsIScriptGlobalObject* aOwner,
NS_ASSERTION(mPrincipal, "Should have set the principal!"); NS_ASSERTION(mPrincipal, "Should have set the principal!");
} }
mLock = nsAutoLock::NewLock("nsDOMWorker::mLock");
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
NS_ASSERTION(!mGlobal, "Already got a global?!"); NS_ASSERTION(!mGlobal, "Already got a global?!");
nsCOMPtr<nsIXPConnectJSObjectHolder> thisWrapped; nsCOMPtr<nsIXPConnectJSObjectHolder> thisWrapped;
@ -1727,7 +1733,7 @@ nsDOMWorker::Cancel()
PRBool enforceTimeout = PR_FALSE; PRBool enforceTimeout = PR_FALSE;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mStatus != eCanceled, "Canceled more than once?!"); NS_ASSERTION(mStatus != eCanceled, "Canceled more than once?!");
@ -1789,7 +1795,7 @@ nsDOMWorker::Kill()
PRUint32 count, index; PRUint32 count, index;
nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features; nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mStatus == eKilled) { if (mStatus == eKilled) {
NS_ASSERTION(mFeatures.Length() == 0, "Features added after killed!"); NS_ASSERTION(mFeatures.Length() == 0, "Features added after killed!");
@ -1838,7 +1844,7 @@ nsDOMWorker::Suspend()
PRBool shouldSuspendFeatures; PRBool shouldSuspendFeatures;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(!mSuspended, "Suspended more than once!"); NS_ASSERTION(!mSuspended, "Suspended more than once!");
shouldSuspendFeatures = !mSuspended; shouldSuspendFeatures = !mSuspended;
mSuspended = PR_TRUE; mSuspended = PR_TRUE;
@ -1856,7 +1862,7 @@ nsDOMWorker::Resume()
PRBool shouldResumeFeatures; PRBool shouldResumeFeatures;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
#ifdef DEBUG #ifdef DEBUG
// Should only have a mismatch if GC or Cancel happened while suspended. // Should only have a mismatch if GC or Cancel happened while suspended.
if (!mSuspended) { if (!mSuspended) {
@ -1884,7 +1890,7 @@ nsDOMWorker::Resume()
PRBool PRBool
nsDOMWorker::IsCanceled() nsDOMWorker::IsCanceled()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return IsCanceledNoLock(); return IsCanceledNoLock();
} }
@ -1918,14 +1924,14 @@ nsDOMWorker::IsCanceledNoLock()
PRBool PRBool
nsDOMWorker::IsClosing() nsDOMWorker::IsClosing()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mStatus != eRunning; return mStatus != eRunning;
} }
PRBool PRBool
nsDOMWorker::IsSuspended() nsDOMWorker::IsSuspended()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mSuspended; return mSuspended;
} }
@ -2197,7 +2203,7 @@ nsDOMWorker::GetWrappedNative()
{ {
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative; nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
wrappedNative = mWrappedNative; wrappedNative = mWrappedNative;
} }
return wrappedNative.forget(); return wrappedNative.forget();
@ -2214,7 +2220,7 @@ nsDOMWorker::AddFeature(nsDOMWorkerFeature* aFeature,
// aCx may be null. // aCx may be null.
JSAutoSuspendRequest asr(aCx); JSAutoSuspendRequest asr(aCx);
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mStatus == eKilled) { if (mStatus == eKilled) {
// No features may be added after we've been canceled. Sorry. // No features may be added after we've been canceled. Sorry.
@ -2247,7 +2253,7 @@ nsDOMWorker::RemoveFeature(nsDOMWorkerFeature* aFeature,
// aCx may be null. // aCx may be null.
JSAutoSuspendRequest asr(aCx); JSAutoSuspendRequest asr(aCx);
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
#ifdef DEBUG #ifdef DEBUG
PRBool removed = PRBool removed =
@ -2264,7 +2270,7 @@ nsDOMWorker::CancelTimeoutWithId(PRUint32 aId)
{ {
nsRefPtr<nsDOMWorkerFeature> foundFeature; nsRefPtr<nsDOMWorkerFeature> foundFeature;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
PRUint32 count = mFeatures.Length(); PRUint32 count = mFeatures.Length();
for (PRUint32 index = 0; index < count; index++) { for (PRUint32 index = 0; index < count; index++) {
nsDOMWorkerFeature*& feature = mFeatures[index]; nsDOMWorkerFeature*& feature = mFeatures[index];
@ -2287,7 +2293,7 @@ nsDOMWorker::SuspendFeatures()
{ {
nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features; nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// We don't really have to worry about overflow here because the only way // We don't really have to worry about overflow here because the only way
// to do this is through recursive script loading, which uses the stack. We // to do this is through recursive script loading, which uses the stack. We
@ -2316,7 +2322,7 @@ nsDOMWorker::ResumeFeatures()
{ {
nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features; nsAutoTArray<nsRefPtr<nsDOMWorkerFeature>, 20> features;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mFeatureSuspendDepth > 0, "Shouldn't happen!"); NS_ASSERTION(mFeatureSuspendDepth > 0, "Shouldn't happen!");
if (--mFeatureSuspendDepth != 0) { if (--mFeatureSuspendDepth != 0) {
@ -2377,7 +2383,7 @@ nsDOMWorker::FireCloseRunnable(PRIntervalTime aTimeoutInterval,
// to do is unblock the waiting thread. // to do is unblock the waiting thread.
PRBool wakeUp; PRBool wakeUp;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mExpirationTime == 0, NS_ASSERTION(mExpirationTime == 0,
"Close runnable should not be scheduled already!"); "Close runnable should not be scheduled already!");
@ -2390,7 +2396,7 @@ nsDOMWorker::FireCloseRunnable(PRIntervalTime aTimeoutInterval,
} }
if (wakeUp) { if (wakeUp) {
MonitorAutoEnter mon(mPool->GetMonitor()); nsAutoMonitor mon(mPool->Monitor());
mon.NotifyAll(); mon.NotifyAll();
} }
@ -2424,7 +2430,7 @@ nsresult
nsDOMWorker::Close() nsDOMWorker::Close()
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mStatus != eKilled, "This should be impossible!"); NS_ASSERTION(mStatus != eKilled, "This should be impossible!");
if (mStatus != eRunning) { if (mStatus != eRunning) {
return NS_OK; return NS_OK;
@ -2442,7 +2448,7 @@ nsresult
nsDOMWorker::TerminateInternal(PRBool aFromFinalize) nsDOMWorker::TerminateInternal(PRBool aFromFinalize)
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
#ifdef DEBUG #ifdef DEBUG
if (!aFromFinalize) { if (!aFromFinalize) {
NS_ASSERTION(mStatus != eCanceled, "Shouldn't be able to get here!"); NS_ASSERTION(mStatus != eCanceled, "Shouldn't be able to get here!");
@ -2489,7 +2495,7 @@ void
nsDOMWorker::SetExpirationTime(PRIntervalTime aExpirationTime) nsDOMWorker::SetExpirationTime(PRIntervalTime aExpirationTime)
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mStatus != eRunning && mStatus != eKilled, "Bad status!"); NS_ASSERTION(mStatus != eRunning && mStatus != eKilled, "Bad status!");
NS_ASSERTION(!mExpirationTime || mExpirationTime == PR_INTERVAL_NO_TIMEOUT, NS_ASSERTION(!mExpirationTime || mExpirationTime == PR_INTERVAL_NO_TIMEOUT,
@ -2503,7 +2509,7 @@ nsDOMWorker::SetExpirationTime(PRIntervalTime aExpirationTime)
PRIntervalTime PRIntervalTime
nsDOMWorker::GetExpirationTime() nsDOMWorker::GetExpirationTime()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
return mExpirationTime; return mExpirationTime;
} }
#endif #endif
@ -2588,7 +2594,7 @@ nsDOMWorker::DispatchEvent(nsIDOMEvent* aEvent,
PRBool* _retval) PRBool* _retval)
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (IsCanceledNoLock()) { if (IsCanceledNoLock()) {
return NS_OK; return NS_OK;
} }
@ -2629,7 +2635,7 @@ NS_IMETHODIMP
nsDOMWorker::PostMessage(/* JSObject aMessage */) nsDOMWorker::PostMessage(/* JSObject aMessage */)
{ {
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// There's no reason to dispatch this message after the close handler has // There's no reason to dispatch this message after the close handler has
// been triggered since it will never be allowed to run. // been triggered since it will never be allowed to run.
if (mStatus != eRunning) { if (mStatus != eRunning) {

View File

@ -48,10 +48,10 @@
#include "nsIXPCScriptable.h" #include "nsIXPCScriptable.h"
#include "jsapi.h" #include "jsapi.h"
#include "mozilla/Mutex.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsTPtrArray.h" #include "nsTPtrArray.h"
#include "prlock.h"
#include "nsDOMWorkerMessageHandler.h" #include "nsDOMWorkerMessageHandler.h"
@ -143,8 +143,6 @@ class nsDOMWorker : public nsDOMWorkerMessageHandler,
public nsIJSNativeInitializer, public nsIJSNativeInitializer,
public nsIXPCScriptable public nsIXPCScriptable
{ {
typedef mozilla::Mutex Mutex;
friend class nsDOMWorkerFeature; friend class nsDOMWorkerFeature;
friend class nsDOMWorkerFunctions; friend class nsDOMWorkerFunctions;
friend class nsDOMWorkerScope; friend class nsDOMWorkerScope;
@ -216,7 +214,7 @@ public:
return mPool; return mPool;
} }
Mutex& GetLock() { PRLock* Lock() {
return mLock; return mLock;
} }
@ -354,7 +352,7 @@ private:
// worker is created. // worker is created.
WorkerPrivilegeModel mPrivilegeModel; WorkerPrivilegeModel mPrivilegeModel;
Mutex mLock; PRLock* mLock;
nsRefPtr<nsDOMWorkerPool> mPool; nsRefPtr<nsDOMWorkerPool> mPool;

View File

@ -50,6 +50,7 @@
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
// Other includes // Other includes
#include "nsAutoLock.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDOMJSUtils.h" #include "nsDOMJSUtils.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
@ -59,15 +60,13 @@
#include "nsDOMThreadService.h" #include "nsDOMThreadService.h"
#include "nsDOMWorker.h" #include "nsDOMWorker.h"
using namespace mozilla;
#define LOG(_args) PR_LOG(gDOMThreadsLog, PR_LOG_DEBUG, _args) #define LOG(_args) PR_LOG(gDOMThreadsLog, PR_LOG_DEBUG, _args)
nsDOMWorkerPool::nsDOMWorkerPool(nsIScriptGlobalObject* aGlobalObject, nsDOMWorkerPool::nsDOMWorkerPool(nsIScriptGlobalObject* aGlobalObject,
nsIDocument* aDocument) nsIDocument* aDocument)
: mParentGlobal(aGlobalObject), : mParentGlobal(aGlobalObject),
mParentDocument(aDocument), mParentDocument(aDocument),
mMonitor("nsDOMWorkerPool.mMonitor"), mMonitor(nsnull),
mCanceled(PR_FALSE), mCanceled(PR_FALSE),
mSuspended(PR_FALSE), mSuspended(PR_FALSE),
mWindowID(aDocument ? aDocument->OuterWindowID() : 0) mWindowID(aDocument ? aDocument->OuterWindowID() : 0)
@ -90,6 +89,10 @@ nsDOMWorkerPool::~nsDOMWorkerPool()
if (document) { if (document) {
NS_ProxyRelease(mainThread, document, PR_FALSE); NS_ProxyRelease(mainThread, document, PR_FALSE);
} }
if (mMonitor) {
nsAutoMonitor::DestroyMonitor(mMonitor);
}
} }
NS_IMPL_THREADSAFE_ADDREF(nsDOMWorkerPool) NS_IMPL_THREADSAFE_ADDREF(nsDOMWorkerPool)
@ -99,6 +102,10 @@ nsresult
nsDOMWorkerPool::Init() nsDOMWorkerPool::Init()
{ {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
mMonitor = nsAutoMonitor::NewMonitor("nsDOMWorkerPool::mMonitor");
NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
return NS_OK; return NS_OK;
} }
@ -110,7 +117,7 @@ nsDOMWorkerPool::NoteWorker(nsDOMWorker* aWorker)
PRBool suspendWorker; PRBool suspendWorker;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
if (mCanceled) { if (mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
@ -137,7 +144,7 @@ nsDOMWorkerPool::NoteDyingWorker(nsDOMWorker* aWorker)
PRBool removeFromThreadService = PR_FALSE; PRBool removeFromThreadService = PR_FALSE;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
NS_ASSERTION(mWorkers.Contains(aWorker), "Worker from a different pool?!"); NS_ASSERTION(mWorkers.Contains(aWorker), "Worker from a different pool?!");
mWorkers.RemoveElement(aWorker); mWorkers.RemoveElement(aWorker);
@ -156,7 +163,7 @@ nsDOMWorkerPool::NoteDyingWorker(nsDOMWorker* aWorker)
void void
nsDOMWorkerPool::GetWorkers(nsTArray<nsDOMWorker*>& aArray) nsDOMWorkerPool::GetWorkers(nsTArray<nsDOMWorker*>& aArray)
{ {
mMonitor.AssertCurrentThreadIn(); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
NS_ASSERTION(!aArray.Length(), "Should be empty!"); NS_ASSERTION(!aArray.Length(), "Should be empty!");
#ifdef DEBUG #ifdef DEBUG
@ -174,7 +181,7 @@ nsDOMWorkerPool::Cancel()
nsAutoTArray<nsDOMWorker*, 10> workers; nsAutoTArray<nsDOMWorker*, 10> workers;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mCanceled = PR_TRUE; mCanceled = PR_TRUE;
@ -186,7 +193,7 @@ nsDOMWorkerPool::Cancel()
for (PRUint32 index = 0; index < count; index++) { for (PRUint32 index = 0; index < count; index++) {
workers[index]->Cancel(); workers[index]->Cancel();
} }
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.NotifyAll(); mon.NotifyAll();
} }
} }
@ -198,7 +205,7 @@ nsDOMWorkerPool::Suspend()
nsAutoTArray<nsDOMWorker*, 10> workers; nsAutoTArray<nsDOMWorker*, 10> workers;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
NS_ASSERTION(!mSuspended, "Suspended more than once!"); NS_ASSERTION(!mSuspended, "Suspended more than once!");
mSuspended = PR_TRUE; mSuspended = PR_TRUE;
@ -219,7 +226,7 @@ nsDOMWorkerPool::Resume()
nsAutoTArray<nsDOMWorker*, 10> workers; nsAutoTArray<nsDOMWorker*, 10> workers;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
NS_ASSERTION(mSuspended, "Not suspended!"); NS_ASSERTION(mSuspended, "Not suspended!");
mSuspended = PR_FALSE; mSuspended = PR_FALSE;
@ -232,7 +239,7 @@ nsDOMWorkerPool::Resume()
for (PRUint32 index = 0; index < count; index++) { for (PRUint32 index = 0; index < count; index++) {
workers[index]->Resume(); workers[index]->Resume();
} }
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.NotifyAll(); mon.NotifyAll();
} }
} }

View File

@ -42,10 +42,10 @@
// Other includes // Other includes
#include "jsapi.h" #include "jsapi.h"
#include "mozilla/Monitor.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsStringGlue.h" #include "nsStringGlue.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "prmon.h"
class nsDOMWorker; class nsDOMWorker;
class nsIDocument; class nsIDocument;
@ -55,8 +55,6 @@ class nsIScriptGlobalObject;
class nsDOMWorkerPool class nsDOMWorkerPool
{ {
typedef mozilla::Monitor Monitor;
public: public:
nsDOMWorkerPool(nsIScriptGlobalObject* aGlobalObject, nsDOMWorkerPool(nsIScriptGlobalObject* aGlobalObject,
nsIDocument* aDocument); nsIDocument* aDocument);
@ -81,7 +79,7 @@ public:
nsresult NoteWorker(nsDOMWorker* aWorker); nsresult NoteWorker(nsDOMWorker* aWorker);
void NoteDyingWorker(nsDOMWorker* aWorker); void NoteDyingWorker(nsDOMWorker* aWorker);
Monitor& GetMonitor() { PRMonitor* Monitor() {
return mMonitor; return mMonitor;
} }
@ -107,7 +105,7 @@ private:
nsTArray<nsDOMWorker*> mWorkers; nsTArray<nsDOMWorker*> mWorkers;
// Monitor for suspending and resuming workers. // Monitor for suspending and resuming workers.
Monitor mMonitor; PRMonitor* mMonitor;
PRPackedBool mCanceled; PRPackedBool mCanceled;
PRPackedBool mSuspended; PRPackedBool mSuspended;

View File

@ -49,6 +49,7 @@
#include "nsIStreamLoader.h" #include "nsIStreamLoader.h"
// Other includes // Other includes
#include "nsAutoLock.h"
#include "nsContentErrors.h" #include "nsContentErrors.h"
#include "nsContentPolicyUtils.h" #include "nsContentPolicyUtils.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
@ -69,8 +70,6 @@
#include "nsDOMThreadService.h" #include "nsDOMThreadService.h"
#include "nsDOMWorkerTimeout.h" #include "nsDOMWorkerTimeout.h"
using namespace mozilla;
#define LOG(_args) PR_LOG(gDOMThreadsLog, PR_LOG_DEBUG, _args) #define LOG(_args) PR_LOG(gDOMThreadsLog, PR_LOG_DEBUG, _args)
nsDOMWorkerScriptLoader::nsDOMWorkerScriptLoader(nsDOMWorker* aWorker) nsDOMWorkerScriptLoader::nsDOMWorkerScriptLoader(nsDOMWorker* aWorker)
@ -304,7 +303,7 @@ nsDOMWorkerScriptLoader::Cancel()
nsAutoTArray<ScriptLoaderRunnable*, 10> runnables; nsAutoTArray<ScriptLoaderRunnable*, 10> runnables;
{ {
MutexAutoLock lock(mWorker->GetLock()); nsAutoLock lock(mWorker->Lock());
runnables.AppendElements(mPendingRunnables); runnables.AppendElements(mPendingRunnables);
mPendingRunnables.Clear(); mPendingRunnables.Clear();
} }
@ -754,7 +753,7 @@ ScriptLoaderRunnable::ScriptLoaderRunnable(nsDOMWorkerScriptLoader* aLoader)
: mRevoked(PR_FALSE), : mRevoked(PR_FALSE),
mLoader(aLoader) mLoader(aLoader)
{ {
MutexAutoLock lock(aLoader->GetLock()); nsAutoLock lock(aLoader->Lock());
#ifdef DEBUG #ifdef DEBUG
nsDOMWorkerScriptLoader::ScriptLoaderRunnable** added = nsDOMWorkerScriptLoader::ScriptLoaderRunnable** added =
#endif #endif
@ -766,7 +765,7 @@ nsDOMWorkerScriptLoader::
ScriptLoaderRunnable::~ScriptLoaderRunnable() ScriptLoaderRunnable::~ScriptLoaderRunnable()
{ {
if (!mRevoked) { if (!mRevoked) {
MutexAutoLock lock(mLoader->GetLock()); nsAutoLock lock(mLoader->Lock());
#ifdef DEBUG #ifdef DEBUG
PRBool removed = PRBool removed =
#endif #endif

View File

@ -54,6 +54,7 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsStringGlue.h" #include "nsStringGlue.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "prlock.h"
#include "nsDOMWorker.h" #include "nsDOMWorker.h"
@ -90,8 +91,6 @@ class nsDOMWorkerScriptLoader : public nsDOMWorkerFeature,
public nsIRunnable, public nsIRunnable,
public nsIStreamLoaderObserver public nsIStreamLoaderObserver
{ {
typedef mozilla::Mutex Mutex;
friend class AutoSuspendWorkerEvents; friend class AutoSuspendWorkerEvents;
friend class ScriptLoaderRunnable; friend class ScriptLoaderRunnable;
@ -133,8 +132,8 @@ private:
void SuspendWorkerEvents(); void SuspendWorkerEvents();
void ResumeWorkerEvents(); void ResumeWorkerEvents();
Mutex& GetLock() { PRLock* Lock() {
return mWorker->GetLock(); return mWorker->Lock();
} }
class ScriptLoaderRunnable : public nsIRunnable class ScriptLoaderRunnable : public nsIRunnable

View File

@ -45,6 +45,7 @@
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
// Other includes // Other includes
#include "nsAutoLock.h"
#include "nsAXPCNativeCallContext.h" #include "nsAXPCNativeCallContext.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
@ -58,8 +59,6 @@
#include "nsDOMWorkerPool.h" #include "nsDOMWorkerPool.h"
#include "nsDOMWorkerXHRProxy.h" #include "nsDOMWorkerXHRProxy.h"
using namespace mozilla;
// The list of event types that we support. This list and the defines based on // The list of event types that we support. This list and the defines based on
// it determine the sizes of the listener arrays in nsDOMWorkerXHRProxy. Make // it determine the sizes of the listener arrays in nsDOMWorkerXHRProxy. Make
// sure that any event types shared by both the XHR and Upload objects are // sure that any event types shared by both the XHR and Upload objects are
@ -494,7 +493,7 @@ nsDOMWorkerXHR::Cancel()
{ {
// This lock is here to prevent a race between Cancel and GetUpload, not to // This lock is here to prevent a race between Cancel and GetUpload, not to
// protect mCanceled. // protect mCanceled.
MutexAutoLock lock(mWorker->GetLock()); nsAutoLock lock(mWorker->Lock());
mCanceled = PR_TRUE; mCanceled = PR_TRUE;
mUpload = nsnull; mUpload = nsnull;
@ -830,7 +829,7 @@ nsDOMWorkerXHR::GetUpload(nsIXMLHttpRequestUpload** aUpload)
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
} }
MutexAutoLock lock(worker->GetLock()); nsAutoLock lock(worker->Lock());
if (mCanceled) { if (mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;

View File

@ -48,6 +48,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "prlock.h"
// DOMWorker includes // DOMWorker includes
#include "nsDOMWorker.h" #include "nsDOMWorker.h"
@ -91,8 +92,6 @@ class nsDOMWorkerXHR : public nsDOMWorkerFeature,
public nsIXMLHttpRequest, public nsIXMLHttpRequest,
public nsIXPCScriptable public nsIXPCScriptable
{ {
typedef mozilla::Mutex Mutex;
friend class nsDOMWorkerXHREvent; friend class nsDOMWorkerXHREvent;
friend class nsDOMWorkerXHRLastProgressOrLoadEvent; friend class nsDOMWorkerXHRLastProgressOrLoadEvent;
friend class nsDOMWorkerXHRProxy; friend class nsDOMWorkerXHRProxy;
@ -117,8 +116,8 @@ public:
private: private:
virtual ~nsDOMWorkerXHR(); virtual ~nsDOMWorkerXHR();
Mutex& GetLock() { PRLock* Lock() {
return mWorker->GetLock(); return mWorker->Lock();
} }
already_AddRefed<nsIXPConnectWrappedNative> GetWrappedNative() { already_AddRefed<nsIXPConnectWrappedNative> GetWrappedNative() {

View File

@ -49,6 +49,7 @@
#include "nsIXMLHttpRequest.h" #include "nsIXMLHttpRequest.h"
// Other includes // Other includes
#include "nsAutoLock.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsIClassInfoImpl.h" #include "nsIClassInfoImpl.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
@ -65,8 +66,6 @@
#include "nsDOMWorkerXHR.h" #include "nsDOMWorkerXHR.h"
#include "nsDOMWorkerXHRProxiedFunctions.h" #include "nsDOMWorkerXHRProxiedFunctions.h"
using namespace mozilla;
#define MAX_XHR_LISTENER_TYPE nsDOMWorkerXHREventTarget::sMaxXHREventTypes #define MAX_XHR_LISTENER_TYPE nsDOMWorkerXHREventTarget::sMaxXHREventTypes
#define MAX_UPLOAD_LISTENER_TYPE nsDOMWorkerXHREventTarget::sMaxUploadEventTypes #define MAX_UPLOAD_LISTENER_TYPE nsDOMWorkerXHREventTarget::sMaxUploadEventTypes
@ -182,7 +181,7 @@ public:
nsRefPtr<nsDOMWorkerXHREvent> lastProgressOrLoadEvent; nsRefPtr<nsDOMWorkerXHREvent> lastProgressOrLoadEvent;
if (!mProxy->mCanceled) { if (!mProxy->mCanceled) {
MutexAutoLock lock(mProxy->mWorkerXHR->GetLock()); nsAutoLock lock(mProxy->mWorkerXHR->Lock());
mProxy->mLastProgressOrLoadEvent.swap(lastProgressOrLoadEvent); mProxy->mLastProgressOrLoadEvent.swap(lastProgressOrLoadEvent);
if (mProxy->mCanceled) { if (mProxy->mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
@ -376,7 +375,7 @@ nsDOMWorkerXHRProxy::Destroy()
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
{ {
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
mCanceled = PR_TRUE; mCanceled = PR_TRUE;
@ -466,7 +465,7 @@ nsDOMWorkerXHRProxy::DestroyInternal()
// necko has fired its OnStartRequest notification. Guard against that here. // necko has fired its OnStartRequest notification. Guard against that here.
nsRefPtr<nsDOMWorkerXHRFinishSyncXHRRunnable> syncFinishedRunnable; nsRefPtr<nsDOMWorkerXHRFinishSyncXHRRunnable> syncFinishedRunnable;
{ {
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
mSyncFinishedRunnable.swap(syncFinishedRunnable); mSyncFinishedRunnable.swap(syncFinishedRunnable);
} }
@ -581,7 +580,7 @@ nsDOMWorkerXHRProxy::HandleWorkerEvent(nsDOMWorkerXHREvent* aEvent,
NS_ASSERTION(aEvent, "Should not be null!"); NS_ASSERTION(aEvent, "Should not be null!");
{ {
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
if (mCanceled || if (mCanceled ||
(aEvent->mChannelID != -1 && aEvent->mChannelID != mChannelID)) { (aEvent->mChannelID != -1 && aEvent->mChannelID != mChannelID)) {
@ -606,7 +605,7 @@ nsDOMWorkerXHRProxy::HandleWorkerEvent(nsDOMWorkerXHREvent* aEvent,
progressInfo = nsnull; progressInfo = nsnull;
// Dummy memory barrier. // Dummy memory barrier.
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
} }
nsIDOMEventTarget* target = aUploadEvent ? nsIDOMEventTarget* target = aUploadEvent ?
@ -770,7 +769,7 @@ nsDOMWorkerXHRProxy::HandleEvent(nsIDOMEvent* aEvent)
NS_ASSERTION(!syncFinishedRunnable, "This shouldn't be set!"); NS_ASSERTION(!syncFinishedRunnable, "This shouldn't be set!");
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
mSyncFinishedRunnable.swap(syncFinishedRunnable); mSyncFinishedRunnable.swap(syncFinishedRunnable);
} }
else { else {
@ -812,7 +811,7 @@ nsDOMWorkerXHRProxy::HandleEvent(nsIDOMEvent* aEvent)
NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY);
{ {
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
if (mCanceled) { if (mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
@ -958,7 +957,7 @@ nsDOMWorkerXHRProxy::Send(nsIVariant* aBody)
mSyncXHRThread = NS_GetCurrentThread(); mSyncXHRThread = NS_GetCurrentThread();
NS_ENSURE_TRUE(mSyncXHRThread, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mSyncXHRThread, NS_ERROR_FAILURE);
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
if (mCanceled) { if (mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
@ -983,7 +982,7 @@ nsDOMWorkerXHRProxy::SendAsBinary(const nsAString& aBody)
mSyncXHRThread = NS_GetCurrentThread(); mSyncXHRThread = NS_GetCurrentThread();
NS_ENSURE_TRUE(mSyncXHRThread, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mSyncXHRThread, NS_ERROR_FAILURE);
MutexAutoLock lock(mWorkerXHR->GetLock()); nsAutoLock lock(mWorkerXHR->Lock());
if (mCanceled) { if (mCanceled) {
return NS_ERROR_ABORT; return NS_ERROR_ABORT;

View File

@ -4623,17 +4623,10 @@ simple_stress_test()
SimpleTransactionFactory factory; SimpleTransactionFactory factory;
PRInt32 iterations =
#ifdef DEBUG
10
#else
// //
// 1500 iterations sends 1,125,750 transactions through the system!! // 1500 iterations sends 1,125,750 transactions through the system!!
// //
1500 return stress_test(&factory, 1500);
#endif
;
return stress_test(&factory, iterations);
} }
nsresult nsresult
@ -4659,17 +4652,10 @@ aggregation_stress_test()
AggregateTransactionFactory factory(3, 4); AggregateTransactionFactory factory(3, 4);
PRInt32 iterations =
#ifdef DEBUG
10
#else
// //
// 500 iterations sends 2,630,250 transactions through the system!! // 500 iterations sends 2,630,250 transactions through the system!!
// //
500 return stress_test(&factory, 500);
#endif
;
return stress_test(&factory, iterations);
} }
nsresult nsresult
@ -4695,17 +4681,10 @@ aggregation_batch_stress_test()
AggregateTransactionFactory factory(3, 4, BATCH_FLAG); AggregateTransactionFactory factory(3, 4, BATCH_FLAG);
PRInt32 iterations =
#ifdef DEBUG
10
#else
// //
// 500 iterations sends 2,630,250 transactions through the system!! // 500 iterations sends 2,630,250 transactions through the system!!
// //
iterations = 500 return stress_test(&factory, 500);
#endif
;
return stress_test(&factory, iterations);
} }
int int

View File

@ -42,6 +42,7 @@
#include "nsWindowWatcher.h" #include "nsWindowWatcher.h"
#include "nsAutoWindowStateHelper.h" #include "nsAutoWindowStateHelper.h"
#include "nsAutoLock.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsWWJSUtils.h" #include "nsWWJSUtils.h"
@ -100,8 +101,6 @@
#include "nsIWeakReference.h" #include "nsIWeakReference.h"
#endif #endif
using namespace mozilla;
static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1"; static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
/**************************************************************** /****************************************************************
@ -339,7 +338,7 @@ NS_IMPL_QUERY_INTERFACE3(nsWindowWatcher,
nsWindowWatcher::nsWindowWatcher() : nsWindowWatcher::nsWindowWatcher() :
mEnumeratorList(), mEnumeratorList(),
mOldestWindow(0), mOldestWindow(0),
mListLock("nsWindowWatcher.mListLock") mListLock(0)
{ {
} }
@ -348,11 +347,17 @@ nsWindowWatcher::~nsWindowWatcher()
// delete data // delete data
while (mOldestWindow) while (mOldestWindow)
RemoveWindow(mOldestWindow); RemoveWindow(mOldestWindow);
if (mListLock)
nsAutoLock::DestroyLock(mListLock);
} }
nsresult nsresult
nsWindowWatcher::Init() nsWindowWatcher::Init()
{ {
mListLock = nsAutoLock::NewLock("nsWindowWatcher::mListLock");
if (!mListLock)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
} }
@ -1068,7 +1073,7 @@ nsWindowWatcher::GetWindowEnumerator(nsISimpleEnumerator** _retval)
if (!_retval) if (!_retval)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
MutexAutoLock lock(mListLock); nsAutoLock lock(mListLock);
nsWatcherWindowEnumerator *enumerator = new nsWatcherWindowEnumerator(this); nsWatcherWindowEnumerator *enumerator = new nsWatcherWindowEnumerator(this);
if (enumerator) if (enumerator)
return CallQueryInterface(enumerator, _retval); return CallQueryInterface(enumerator, _retval);
@ -1164,7 +1169,7 @@ nsWindowWatcher::AddWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome *aChrome)
{ {
nsWatcherWindowEntry *info; nsWatcherWindowEntry *info;
MutexAutoLock lock(mListLock); nsAutoLock lock(mListLock);
// if we already have an entry for this window, adjust // if we already have an entry for this window, adjust
// its chrome mapping and return // its chrome mapping and return
@ -1264,7 +1269,7 @@ nsresult nsWindowWatcher::RemoveWindow(nsWatcherWindowEntry *inInfo)
{ {
// notify the enumerators // notify the enumerators
MutexAutoLock lock(mListLock); nsAutoLock lock(mListLock);
for (ctr = 0; ctr < count; ++ctr) for (ctr = 0; ctr < count; ++ctr)
mEnumeratorList[ctr]->WindowRemoved(inInfo); mEnumeratorList[ctr]->WindowRemoved(inInfo);
@ -1300,7 +1305,7 @@ nsWindowWatcher::GetChromeForWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome *
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
*_retval = 0; *_retval = 0;
MutexAutoLock lock(mListLock); nsAutoLock lock(mListLock);
nsWatcherWindowEntry *info = FindWindowEntry(aWindow); nsWatcherWindowEntry *info = FindWindowEntry(aWindow);
if (info) { if (info) {
if (info->mChromeWeak != nsnull) { if (info->mChromeWeak != nsnull) {

View File

@ -44,7 +44,6 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "jspubtd.h" #include "jspubtd.h"
#include "mozilla/Mutex.h"
#include "nsIWindowCreator.h" // for stupid compilers #include "nsIWindowCreator.h" // for stupid compilers
#include "nsIWindowWatcher.h" #include "nsIWindowWatcher.h"
#include "nsIPromptFactory.h" #include "nsIPromptFactory.h"
@ -62,6 +61,7 @@ class nsPromptService;
struct JSContext; struct JSContext;
struct JSObject; struct JSObject;
struct nsWatcherWindowEntry; struct nsWatcherWindowEntry;
struct PRLock;
struct SizeSpec; struct SizeSpec;
class nsWindowWatcher : class nsWindowWatcher :
@ -145,7 +145,7 @@ protected:
nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList; nsTArray<nsWatcherWindowEnumerator*> mEnumeratorList;
nsWatcherWindowEntry *mOldestWindow; nsWatcherWindowEntry *mOldestWindow;
mozilla::Mutex mListLock; PRLock *mListLock;
nsCOMPtr<nsIWindowCreator> mWindowCreator; nsCOMPtr<nsIWindowCreator> mWindowCreator;
}; };

View File

@ -34,6 +34,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "prlock.h"
#include "nsRegion.h" #include "nsRegion.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "nsTArray.h" #include "nsTArray.h"
@ -108,7 +109,14 @@ class RgnRectMemoryAllocator
nsRegion::RgnRect* mFreeListHead; nsRegion::RgnRect* mFreeListHead;
PRUint32 mFreeEntries; PRUint32 mFreeEntries;
void* mChunkListHead; void* mChunkListHead;
#if defined (DEBUG) #if 0
PRLock* mLock;
void InitLock () { mLock = PR_NewLock (); }
void DestroyLock () { PR_DestroyLock (mLock); }
void Lock () { PR_Lock (mLock); }
void Unlock () { PR_Unlock (mLock); }
#elif defined (DEBUG)
NS_DECL_OWNINGTHREAD NS_DECL_OWNINGTHREAD
void InitLock () { NS_ASSERT_OWNINGTHREAD (RgnRectMemoryAllocator); } void InitLock () { NS_ASSERT_OWNINGTHREAD (RgnRectMemoryAllocator); }

View File

@ -59,6 +59,7 @@
#include "pratom.h" #include "pratom.h"
#include "prmem.h" #include "prmem.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsAutoLock.h"
#include "nsTextFormatter.h" #include "nsTextFormatter.h"
#include "nsIErrorService.h" #include "nsIErrorService.h"
#include "nsITimelineService.h" #include "nsITimelineService.h"
@ -74,20 +75,20 @@
#include "prenv.h" #include "prenv.h"
#include "nsCRT.h" #include "nsCRT.h"
using namespace mozilla;
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID); static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID); static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
nsStringBundle::~nsStringBundle() nsStringBundle::~nsStringBundle()
{ {
if (mMonitor)
nsAutoMonitor::DestroyMonitor(mMonitor);
} }
nsStringBundle::nsStringBundle(const char* aURLSpec, nsStringBundle::nsStringBundle(const char* aURLSpec,
nsIStringBundleOverride* aOverrideStrings) : nsIStringBundleOverride* aOverrideStrings) :
mPropertiesURL(aURLSpec), mPropertiesURL(aURLSpec),
mOverrideStrings(aOverrideStrings), mOverrideStrings(aOverrideStrings),
mMonitor("nsStringBundle.mMonitor"), mMonitor(0),
mAttemptedLoad(PR_FALSE), mAttemptedLoad(PR_FALSE),
mLoaded(PR_FALSE) mLoaded(PR_FALSE)
{ {
@ -111,6 +112,10 @@ nsStringBundle::LoadProperties()
nsresult rv; nsresult rv;
mMonitor = nsAutoMonitor::NewMonitor("StringBundle monitor");
if (!mMonitor)
return NS_ERROR_OUT_OF_MEMORY;
// do it synchronously // do it synchronously
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), mPropertiesURL); rv = NS_NewURI(getter_AddRefs(uri), mPropertiesURL);
@ -148,7 +153,7 @@ nsStringBundle::LoadProperties()
nsresult nsresult
nsStringBundle::GetStringFromID(PRInt32 aID, nsAString& aResult) nsStringBundle::GetStringFromID(PRInt32 aID, nsAString& aResult)
{ {
MonitorAutoEnter automon(mMonitor); nsAutoMonitor automon(mMonitor);
nsCAutoString name; nsCAutoString name;
name.AppendInt(aID, 10); name.AppendInt(aID, 10);
@ -269,7 +274,7 @@ nsStringBundle::GetStringFromName(const PRUnichar *aName, PRUnichar **aResult)
rv = LoadProperties(); rv = LoadProperties();
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
MonitorAutoEnter automon(mMonitor); nsAutoMonitor automon(mMonitor);
*aResult = nsnull; *aResult = nsnull;
nsAutoString tmpstr; nsAutoString tmpstr;
rv = GetStringFromName(nsDependentString(aName), tmpstr); rv = GetStringFromName(nsDependentString(aName), tmpstr);

View File

@ -38,13 +38,13 @@
#ifndef nsStringBundle_h__ #ifndef nsStringBundle_h__
#define nsStringBundle_h__ #define nsStringBundle_h__
#include "mozilla/Monitor.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIPersistentProperties2.h" #include "nsIPersistentProperties2.h"
#include "nsString.h" #include "nsString.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsIStringBundleOverride.h" #include "nsIStringBundleOverride.h"
#include "nsAutoLock.h"
class nsStringBundle : public nsIStringBundle class nsStringBundle : public nsIStringBundle
{ {
@ -71,7 +71,7 @@ protected:
private: private:
nsCString mPropertiesURL; nsCString mPropertiesURL;
nsCOMPtr<nsIStringBundleOverride> mOverrideStrings; nsCOMPtr<nsIStringBundleOverride> mOverrideStrings;
mozilla::Monitor mMonitor; PRMonitor* mMonitor;
PRPackedBool mAttemptedLoad; PRPackedBool mAttemptedLoad;
PRPackedBool mLoaded; PRPackedBool mLoaded;

View File

@ -59,6 +59,7 @@
#include <langinfo.h> #include <langinfo.h>
#endif #endif
#include "nsPlatformCharset.h" #include "nsPlatformCharset.h"
#include "nsAutoLock.h"
#include "prinit.h" #include "prinit.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"

View File

@ -49,8 +49,6 @@
#include "mozilla/FunctionTimer.h" #include "mozilla/FunctionTimer.h"
#include "prsystem.h" #include "prsystem.h"
using namespace mozilla;
/***************************************************************************/ /***************************************************************************/
const char* XPCJSRuntime::mStrings[] = { const char* XPCJSRuntime::mStrings[] = {
@ -341,10 +339,10 @@ void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
// bad locking problems with the thread iteration otherwise. // bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown()) if(!self->GetXPConnect()->IsShuttingDown())
{ {
Mutex* threadLock = XPCPerThreadData::GetLock(); PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock) if(threadLock)
{ // scoped lock { // scoped lock
MutexAutoLock lock(*threadLock); nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull; XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread; XPCPerThreadData* thread;
@ -759,10 +757,10 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
// bad locking problems with the thread iteration otherwise. // bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown()) if(!self->GetXPConnect()->IsShuttingDown())
{ {
Mutex* threadLock = XPCPerThreadData::GetLock(); PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock) if(threadLock)
{ // scoped lock { // scoped lock
MutexAutoLock lock(*threadLock); nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull; XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread; XPCPerThreadData* thread;
@ -853,13 +851,13 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
// bad locking problems with the thread iteration otherwise. // bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown()) if(!self->GetXPConnect()->IsShuttingDown())
{ {
Mutex* threadLock = XPCPerThreadData::GetLock(); PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock) if(threadLock)
{ {
// Do the marking... // Do the marking...
{ // scoped lock { // scoped lock
MutexAutoLock lock(*threadLock); nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull; XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread; XPCPerThreadData* thread;

View File

@ -81,6 +81,7 @@
#include "nsIJSRuntimeService.h" #include "nsIJSRuntimeService.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAutoLock.h"
#include "nsXPTCUtils.h" #include "nsXPTCUtils.h"
#include "xptinfo.h" #include "xptinfo.h"
#include "xpcforwards.h" #include "xpcforwards.h"
@ -97,8 +98,6 @@
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsAutoJSValHolder.h" #include "nsAutoJSValHolder.h"
#include "mozilla/AutoRestore.h" #include "mozilla/AutoRestore.h"
#include "mozilla/Monitor.h"
#include "mozilla/Mutex.h"
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
@ -351,18 +350,26 @@ typedef nsDataHashtable<xpc::PtrAndPrincipalHashKey, JSCompartment *> XPCCompart
#pragma warning(disable : 4355) // OK to pass "this" in member initializer #pragma warning(disable : 4355) // OK to pass "this" in member initializer
#endif #endif
typedef mozilla::Monitor XPCLock; typedef PRMonitor XPCLock;
static inline void xpc_Wait(XPCLock* lock) static inline void xpc_Wait(XPCLock* lock)
{ {
NS_ASSERTION(lock, "xpc_Wait called with null lock!"); NS_ASSERTION(lock, "xpc_Wait called with null lock!");
lock->Wait(); #ifdef DEBUG
PRStatus result =
#endif
PR_Wait(lock, PR_INTERVAL_NO_TIMEOUT);
NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_Wait!");
} }
static inline void xpc_NotifyAll(XPCLock* lock) static inline void xpc_NotifyAll(XPCLock* lock)
{ {
NS_ASSERTION(lock, "xpc_NotifyAll called with null lock!"); NS_ASSERTION(lock, "xpc_NotifyAll called with null lock!");
lock->NotifyAll(); #ifdef DEBUG
PRStatus result =
#endif
PR_NotifyAll(lock);
NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_NotifyAll!");
} }
// This is a cloned subset of nsAutoMonitor. We want the use of a monitor - // This is a cloned subset of nsAutoMonitor. We want the use of a monitor -
@ -375,27 +382,36 @@ static inline void xpc_NotifyAll(XPCLock* lock)
// Note that xpconnect only makes *one* monitor and *mostly* holds it locked // Note that xpconnect only makes *one* monitor and *mostly* holds it locked
// only through very small critical sections. // only through very small critical sections.
class NS_STACK_CLASS XPCAutoLock { class NS_STACK_CLASS XPCAutoLock : public nsAutoLockBase {
public: public:
static XPCLock* NewLock(const char* name) static XPCLock* NewLock(const char* name)
{return new mozilla::Monitor(name);} {return nsAutoMonitor::NewMonitor(name);}
static void DestroyLock(XPCLock* lock) static void DestroyLock(XPCLock* lock)
{delete lock;} {nsAutoMonitor::DestroyMonitor(lock);}
XPCAutoLock(XPCLock* lock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) XPCAutoLock(XPCLock* lock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
: mLock(lock) #ifdef DEBUG_jband
: nsAutoLockBase(lock ? (void*) lock : (void*) this, eAutoMonitor),
#else
: nsAutoLockBase(lock, eAutoMonitor),
#endif
mLock(lock)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT; MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
if(mLock) if(mLock)
mLock->Enter(); PR_EnterMonitor(mLock);
} }
~XPCAutoLock() ~XPCAutoLock()
{ {
if(mLock) if(mLock)
{ {
mLock->Exit(); #ifdef DEBUG
PRStatus status =
#endif
PR_ExitMonitor(mLock);
NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed");
} }
} }
@ -421,22 +437,27 @@ private:
/************************************************/ /************************************************/
class NS_STACK_CLASS XPCAutoUnlock { class NS_STACK_CLASS XPCAutoUnlock : public nsAutoUnlockBase {
public: public:
XPCAutoUnlock(XPCLock* lock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) XPCAutoUnlock(XPCLock* lock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
: mLock(lock) : nsAutoUnlockBase(lock),
mLock(lock)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT; MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
if(mLock) if(mLock)
{ {
mLock->Exit(); #ifdef DEBUG
PRStatus status =
#endif
PR_ExitMonitor(mLock);
NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed");
} }
} }
~XPCAutoUnlock() ~XPCAutoUnlock()
{ {
if(mLock) if(mLock)
mLock->Enter(); PR_EnterMonitor(mLock);
} }
private: private:
@ -3652,8 +3673,6 @@ private:
class XPCPerThreadData class XPCPerThreadData
{ {
typedef mozilla::Mutex Mutex;
public: public:
// Get the instance of this object for the current thread // Get the instance of this object for the current thread
static inline XPCPerThreadData* GetData(JSContext *cx) static inline XPCPerThreadData* GetData(JSContext *cx)
@ -3744,7 +3763,7 @@ public:
PRBool IsValid() const {return mJSContextStack != nsnull;} PRBool IsValid() const {return mJSContextStack != nsnull;}
static Mutex* GetLock() {return gLock;} static PRLock* GetLock() {return gLock;}
// Must be called with the threads locked. // Must be called with the threads locked.
static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp); static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp);
@ -3790,7 +3809,7 @@ private:
#endif #endif
PRThread* mThread; PRThread* mThread;
static Mutex* gLock; static PRLock* gLock;
static XPCPerThreadData* gThreads; static XPCPerThreadData* gThreads;
static PRUintn gTLSIndex; static PRUintn gTLSIndex;

View File

@ -43,13 +43,10 @@
#include "xpcprivate.h" #include "xpcprivate.h"
#include "XPCWrapper.h" #include "XPCWrapper.h"
#include "mozilla/Mutex.h"
#include "nsDOMJSUtils.h" #include "nsDOMJSUtils.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsNullPrincipal.h" #include "nsNullPrincipal.h"
using namespace mozilla;
/***************************************************************************/ /***************************************************************************/
XPCJSContextStack::XPCJSContextStack() XPCJSContextStack::XPCJSContextStack()
@ -344,7 +341,7 @@ XPCJSContextStack::SetSafeJSContext(JSContext * aSafeJSContext)
/***************************************************************************/ /***************************************************************************/
PRUintn XPCPerThreadData::gTLSIndex = BAD_TLS_INDEX; PRUintn XPCPerThreadData::gTLSIndex = BAD_TLS_INDEX;
Mutex* XPCPerThreadData::gLock = nsnull; PRLock* XPCPerThreadData::gLock = nsnull;
XPCPerThreadData* XPCPerThreadData::gThreads = nsnull; XPCPerThreadData* XPCPerThreadData::gThreads = nsnull;
XPCPerThreadData *XPCPerThreadData::sMainThreadData = nsnull; XPCPerThreadData *XPCPerThreadData::sMainThreadData = nsnull;
void * XPCPerThreadData::sMainJSThread = nsnull; void * XPCPerThreadData::sMainJSThread = nsnull;
@ -366,7 +363,7 @@ XPCPerThreadData::XPCPerThreadData()
MOZ_COUNT_CTOR(xpcPerThreadData); MOZ_COUNT_CTOR(xpcPerThreadData);
if(gLock) if(gLock)
{ {
MutexAutoLock lock(*gLock); nsAutoLock lock(gLock);
mNextThread = gThreads; mNextThread = gThreads;
gThreads = this; gThreads = this;
} }
@ -400,7 +397,7 @@ XPCPerThreadData::~XPCPerThreadData()
// Unlink 'this' from the list of threads. // Unlink 'this' from the list of threads.
if(gLock) if(gLock)
{ {
MutexAutoLock lock(*gLock); nsAutoLock lock(gLock);
if(gThreads == this) if(gThreads == this)
gThreads = mNextThread; gThreads = mNextThread;
else else
@ -422,7 +419,7 @@ XPCPerThreadData::~XPCPerThreadData()
if(gLock && doDestroyLock) if(gLock && doDestroyLock)
{ {
delete gLock; nsAutoLock::DestroyLock(gLock);
gLock = nsnull; gLock = nsnull;
} }
} }
@ -468,12 +465,14 @@ XPCPerThreadData::GetDataImpl(JSContext *cx)
if(!gLock) if(!gLock)
{ {
gLock = new Mutex("XPCPerThreadData.gLock"); gLock = nsAutoLock::NewLock("XPCPerThreadData::gLock");
if(!gLock)
return nsnull;
} }
if(gTLSIndex == BAD_TLS_INDEX) if(gTLSIndex == BAD_TLS_INDEX)
{ {
MutexAutoLock lock(*gLock); nsAutoLock lock(gLock);
// check again now that we have the lock... // check again now that we have the lock...
if(gTLSIndex == BAD_TLS_INDEX) if(gTLSIndex == BAD_TLS_INDEX)
{ {
@ -534,7 +533,7 @@ XPCPerThreadData::CleanupAllThreads()
if(gLock) if(gLock)
{ {
MutexAutoLock lock(*gLock); nsAutoLock lock(gLock);
for(XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread) for(XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
count++; count++;

View File

@ -55,8 +55,6 @@
#include <io.h> #include <io.h>
#endif #endif
using namespace mozilla;
//---------------------------------------------- //----------------------------------------------
// nsJARManifestItem declaration // nsJARManifestItem declaration
//---------------------------------------------- //----------------------------------------------
@ -125,9 +123,8 @@ nsJAR::nsJAR(): mZip(new nsZipArchive()),
mGlobalStatus(JAR_MANIFEST_NOT_PARSED), mGlobalStatus(JAR_MANIFEST_NOT_PARSED),
mReleaseTime(PR_INTERVAL_NO_TIMEOUT), mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
mCache(nsnull), mCache(nsnull),
mLock("nsJAR::mLock"), mLock(nsnull),
mTotalItemsInManifest(0), mTotalItemsInManifest(0)
mOpened(PR_FALSE)
{ {
} }
@ -171,11 +168,13 @@ NS_IMETHODIMP
nsJAR::Open(nsIFile* zipFile) nsJAR::Open(nsIFile* zipFile)
{ {
NS_ENSURE_ARG_POINTER(zipFile); NS_ENSURE_ARG_POINTER(zipFile);
if (mOpened) return NS_ERROR_FAILURE; // Already open! if (mLock) return NS_ERROR_FAILURE; // Already open!
mZipFile = zipFile; mZipFile = zipFile;
mOuterZipEntry.Truncate(); mOuterZipEntry.Truncate();
mOpened = PR_TRUE;
mLock = nsAutoLock::NewLock("nsJAR::mLock");
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
#ifdef MOZ_OMNIJAR #ifdef MOZ_OMNIJAR
// The omnijar is special, it is opened early on and closed late // The omnijar is special, it is opened early on and closed late
@ -195,7 +194,7 @@ nsJAR::OpenInner(nsIZipReader *aZipReader, const char *aZipEntry)
{ {
NS_ENSURE_ARG_POINTER(aZipReader); NS_ENSURE_ARG_POINTER(aZipReader);
NS_ENSURE_ARG_POINTER(aZipEntry); NS_ENSURE_ARG_POINTER(aZipEntry);
if (mOpened) return NS_ERROR_FAILURE; // Already open! if (mLock) return NS_ERROR_FAILURE; // Already open!
PRBool exist; PRBool exist;
nsresult rv = aZipReader->HasEntry(nsDependentCString(aZipEntry), &exist); nsresult rv = aZipReader->HasEntry(nsDependentCString(aZipEntry), &exist);
@ -205,7 +204,8 @@ nsJAR::OpenInner(nsIZipReader *aZipReader, const char *aZipEntry)
rv = aZipReader->GetFile(getter_AddRefs(mZipFile)); rv = aZipReader->GetFile(getter_AddRefs(mZipFile));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mOpened = PR_TRUE; mLock = nsAutoLock::NewLock("nsJAR::mLock");
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
mOuterZipEntry.Assign(aZipEntry); mOuterZipEntry.Assign(aZipEntry);
@ -229,7 +229,11 @@ nsJAR::GetFile(nsIFile* *result)
NS_IMETHODIMP NS_IMETHODIMP
nsJAR::Close() nsJAR::Close()
{ {
mOpened = PR_FALSE; if (mLock) {
nsAutoLock::DestroyLock(mLock);
mLock = nsnull;
}
mParsedManifest = PR_FALSE; mParsedManifest = PR_FALSE;
mManifestData.Reset(); mManifestData.Reset();
mGlobalStatus = JAR_MANIFEST_NOT_PARSED; mGlobalStatus = JAR_MANIFEST_NOT_PARSED;
@ -256,7 +260,7 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile)
{ {
// nsZipArchive and zlib are not thread safe // nsZipArchive and zlib are not thread safe
// we need to use a lock to prevent bug #51267 // we need to use a lock to prevent bug #51267
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
nsresult rv; nsresult rv;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(outFile, &rv); nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(outFile, &rv);
@ -1056,7 +1060,7 @@ nsJARItem::GetLastModifiedTime(PRTime* aLastModTime)
NS_IMPL_THREADSAFE_ISUPPORTS3(nsZipReaderCache, nsIZipReaderCache, nsIObserver, nsISupportsWeakReference) NS_IMPL_THREADSAFE_ISUPPORTS3(nsZipReaderCache, nsIZipReaderCache, nsIObserver, nsISupportsWeakReference)
nsZipReaderCache::nsZipReaderCache() nsZipReaderCache::nsZipReaderCache()
: mLock("nsZipReaderCache.mLock") : mLock(nsnull)
, mZips(16) , mZips(16)
#ifdef ZIP_CACHE_HIT_RATE #ifdef ZIP_CACHE_HIT_RATE
, ,
@ -1084,7 +1088,8 @@ nsZipReaderCache::Init(PRUint32 cacheSize)
} }
// ignore failure of the observer registration. // ignore failure of the observer registration.
return NS_OK; mLock = nsAutoLock::NewLock("nsZipReaderCache::mLock");
return mLock ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
} }
static PRBool static PRBool
@ -1097,6 +1102,8 @@ DropZipReaderCache(nsHashKey *aKey, void *aData, void* closure)
nsZipReaderCache::~nsZipReaderCache() nsZipReaderCache::~nsZipReaderCache()
{ {
if (mLock)
nsAutoLock::DestroyLock(mLock);
mZips.Enumerate(DropZipReaderCache, nsnull); mZips.Enumerate(DropZipReaderCache, nsnull);
#ifdef ZIP_CACHE_HIT_RATE #ifdef ZIP_CACHE_HIT_RATE
@ -1113,7 +1120,7 @@ nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result)
NS_ENSURE_ARG_POINTER(zipFile); NS_ENSURE_ARG_POINTER(zipFile);
nsresult rv; nsresult rv;
nsCOMPtr<nsIZipReader> antiLockZipGrip; nsCOMPtr<nsIZipReader> antiLockZipGrip;
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
#ifdef ZIP_CACHE_HIT_RATE #ifdef ZIP_CACHE_HIT_RATE
mZipCacheLookups++; mZipCacheLookups++;
@ -1240,7 +1247,7 @@ nsresult
nsZipReaderCache::ReleaseZip(nsJAR* zip) nsZipReaderCache::ReleaseZip(nsJAR* zip)
{ {
nsresult rv; nsresult rv;
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// It is possible that two thread compete for this zip. The dangerous // It is possible that two thread compete for this zip. The dangerous
// case is where one thread Releases the zip and discovers that the ref // case is where one thread Releases the zip and discovers that the ref
@ -1329,7 +1336,7 @@ nsZipReaderCache::Observe(nsISupports *aSubject,
const PRUnichar *aSomeData) const PRUnichar *aSomeData)
{ {
if (strcmp(aTopic, "memory-pressure") == 0) { if (strcmp(aTopic, "memory-pressure") == 0) {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
while (PR_TRUE) { while (PR_TRUE) {
nsHashKey* flushable = nsnull; nsHashKey* flushable = nsnull;
mZips.Enumerate(FindFlushableZip, &flushable); mZips.Enumerate(FindFlushableZip, &flushable);
@ -1362,7 +1369,7 @@ nsZipReaderCache::Observe(nsISupports *aSubject,
uri.Insert(NS_LITERAL_CSTRING("file:"), 0); uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
nsCStringKey key(uri); nsCStringKey key(uri);
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key))); nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key)));
if (!zip) if (!zip)
return NS_OK; return NS_OK;

View File

@ -52,13 +52,13 @@
#include "prtypes.h" #include "prtypes.h"
#include "prinrval.h" #include "prinrval.h"
#include "mozilla/Mutex.h"
#include "nsIComponentManager.h" #include "nsIComponentManager.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsString.h" #include "nsString.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsStringEnumerator.h" #include "nsStringEnumerator.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "nsAutoLock.h"
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsZipArchive.h" #include "nsZipArchive.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
@ -140,11 +140,10 @@ class nsJAR : public nsIZipReader
PRInt16 mGlobalStatus; // Global signature verification status PRInt16 mGlobalStatus; // Global signature verification status
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
mozilla::Mutex mLock; PRLock* mLock;
PRInt64 mMtime; PRInt64 mMtime;
PRInt32 mTotalItemsInManifest; PRInt32 mTotalItemsInManifest;
PRBool mOpened;
nsresult ParseManifest(); nsresult ParseManifest();
void ReportError(const char* aFilename, PRInt16 errorCode); void ReportError(const char* aFilename, PRInt16 errorCode);
nsresult LoadEntry(const char* aFilename, char** aBuf, nsresult LoadEntry(const char* aFilename, char** aBuf,
@ -230,7 +229,7 @@ public:
nsresult ReleaseZip(nsJAR* reader); nsresult ReleaseZip(nsJAR* reader);
protected: protected:
mozilla::Mutex mLock; PRLock* mLock;
PRInt32 mCacheSize; PRInt32 mCacheSize;
nsSupportsHashtable mZips; nsSupportsHashtable mZips;

View File

@ -51,6 +51,7 @@
#include "jscntxt.h" #include "jscntxt.h"
#include "nsAutoLock.h"
#include "nsNPAPIPlugin.h" #include "nsNPAPIPlugin.h"
#include "nsNPAPIPluginInstance.h" #include "nsNPAPIPluginInstance.h"
#include "nsNPAPIPluginStreamListener.h" #include "nsNPAPIPluginStreamListener.h"
@ -107,7 +108,6 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "mozilla/Mutex.h"
#include "mozilla/PluginLibrary.h" #include "mozilla/PluginLibrary.h"
using mozilla::PluginLibrary; using mozilla::PluginLibrary;
@ -127,7 +127,6 @@ using mozilla::plugins::PluginModuleParent;
#include <windows.h> #include <windows.h>
#endif #endif
using namespace mozilla;
using namespace mozilla::plugins::parent; using namespace mozilla::plugins::parent;
// We should make this const... // We should make this const...
@ -191,7 +190,7 @@ static NPNetscapeFuncs sBrowserFuncs = {
_urlredirectresponse _urlredirectresponse
}; };
static Mutex *sPluginThreadAsyncCallLock = nsnull; static PRLock *sPluginThreadAsyncCallLock = nsnull;
static PRCList sPendingAsyncCalls = PR_INIT_STATIC_CLIST(&sPendingAsyncCalls); static PRCList sPendingAsyncCalls = PR_INIT_STATIC_CLIST(&sPendingAsyncCalls);
// POST/GET stream type // POST/GET stream type
@ -230,7 +229,7 @@ static void CheckClassInitialized()
return; return;
if (!sPluginThreadAsyncCallLock) if (!sPluginThreadAsyncCallLock)
sPluginThreadAsyncCallLock = new Mutex("nsNPAPIPlugin.sPluginThreadAsyncCallLock"); sPluginThreadAsyncCallLock = nsAutoLock::NewLock("sPluginThreadAsyncCallLock");
initialized = PR_TRUE; initialized = PR_TRUE;
@ -841,7 +840,7 @@ nsPluginThreadRunnable::nsPluginThreadRunnable(NPP instance,
PR_INIT_CLIST(this); PR_INIT_CLIST(this);
{ {
MutexAutoLock lock(*sPluginThreadAsyncCallLock); nsAutoLock lock(sPluginThreadAsyncCallLock);
nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance *)instance->ndata; nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance *)instance->ndata;
if (!inst || !inst->IsRunning()) { if (!inst || !inst->IsRunning()) {
@ -862,7 +861,7 @@ nsPluginThreadRunnable::~nsPluginThreadRunnable()
} }
{ {
MutexAutoLock lock(*sPluginThreadAsyncCallLock); nsAutoLock lock(sPluginThreadAsyncCallLock);
PR_REMOVE_LINK(this); PR_REMOVE_LINK(this);
} }
@ -888,7 +887,7 @@ OnPluginDestroy(NPP instance)
} }
{ {
MutexAutoLock lock(*sPluginThreadAsyncCallLock); nsAutoLock lock(sPluginThreadAsyncCallLock);
if (PR_CLIST_IS_EMPTY(&sPendingAsyncCalls)) { if (PR_CLIST_IS_EMPTY(&sPendingAsyncCalls)) {
return; return;
@ -914,23 +913,28 @@ OnShutdown()
"Pending async plugin call list not cleaned up!"); "Pending async plugin call list not cleaned up!");
if (sPluginThreadAsyncCallLock) { if (sPluginThreadAsyncCallLock) {
delete sPluginThreadAsyncCallLock; nsAutoLock::DestroyLock(sPluginThreadAsyncCallLock);
sPluginThreadAsyncCallLock = nsnull; sPluginThreadAsyncCallLock = nsnull;
} }
} }
AsyncCallbackAutoLock::AsyncCallbackAutoLock() void
EnterAsyncPluginThreadCallLock()
{ {
sPluginThreadAsyncCallLock->Lock(); if (sPluginThreadAsyncCallLock) {
PR_Lock(sPluginThreadAsyncCallLock);
}
} }
AsyncCallbackAutoLock::~AsyncCallbackAutoLock() void
ExitAsyncPluginThreadCallLock()
{ {
sPluginThreadAsyncCallLock->Unlock(); if (sPluginThreadAsyncCallLock) {
PR_Unlock(sPluginThreadAsyncCallLock);
}
} }
NPP NPPStack::sCurrentNPP = nsnull; NPP NPPStack::sCurrentNPP = nsnull;
const char * const char *

View File

@ -383,15 +383,10 @@ OnPluginDestroy(NPP instance);
void void
OnShutdown(); OnShutdown();
/** void
* within a lexical scope, locks and unlocks the mutex used to EnterAsyncPluginThreadCallLock();
* serialize modifications to plugin async callback state. void
*/ ExitAsyncPluginThreadCallLock();
struct NS_STACK_CLASS AsyncCallbackAutoLock
{
AsyncCallbackAutoLock();
~AsyncCallbackAutoLock();
};
class NPPStack class NPPStack
{ {

View File

@ -189,11 +189,10 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Stop()
// Make sure we lock while we're writing to mRunning after we've // Make sure we lock while we're writing to mRunning after we've
// started as other threads might be checking that inside a lock. // started as other threads might be checking that inside a lock.
{ EnterAsyncPluginThreadCallLock();
AsyncCallbackAutoLock lock; mRunning = DESTROYING;
mRunning = DESTROYING; mStopTime = TimeStamp::Now();
mStopTime = TimeStamp::Now(); ExitAsyncPluginThreadCallLock();
}
OnPluginDestroy(&mNPP); OnPluginDestroy(&mNPP);

View File

@ -41,10 +41,9 @@
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
#include "nsNetSegmentUtils.h" #include "nsNetSegmentUtils.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsAutoLock.h"
#include "prlog.h" #include "prlog.h"
using namespace mozilla;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
// //
// NSPR_LOG_MODULES=nsStreamCopier:5 // NSPR_LOG_MODULES=nsStreamCopier:5
@ -56,7 +55,7 @@ static PRLogModuleInfo *gStreamCopierLog = nsnull;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsAsyncStreamCopier::nsAsyncStreamCopier() nsAsyncStreamCopier::nsAsyncStreamCopier()
: mLock("nsAsyncStreamCopier.mLock") : mLock(nsnull)
, mMode(NS_ASYNCCOPY_VIA_READSEGMENTS) , mMode(NS_ASYNCCOPY_VIA_READSEGMENTS)
, mChunkSize(nsIOService::gDefaultSegmentSize) , mChunkSize(nsIOService::gDefaultSegmentSize)
, mStatus(NS_OK) , mStatus(NS_OK)
@ -72,12 +71,14 @@ nsAsyncStreamCopier::nsAsyncStreamCopier()
nsAsyncStreamCopier::~nsAsyncStreamCopier() nsAsyncStreamCopier::~nsAsyncStreamCopier()
{ {
LOG(("Destroying nsAsyncStreamCopier @%x\n", this)); LOG(("Destroying nsAsyncStreamCopier @%x\n", this));
if (mLock)
nsAutoLock::DestroyLock(mLock);
} }
PRBool PRBool
nsAsyncStreamCopier::IsComplete(nsresult *status) nsAsyncStreamCopier::IsComplete(nsresult *status)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (status) if (status)
*status = mStatus; *status = mStatus;
return !mIsPending; return !mIsPending;
@ -91,7 +92,7 @@ nsAsyncStreamCopier::Complete(nsresult status)
nsCOMPtr<nsIRequestObserver> observer; nsCOMPtr<nsIRequestObserver> observer;
nsCOMPtr<nsISupports> ctx; nsCOMPtr<nsISupports> ctx;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mCopierCtx = nsnull; mCopierCtx = nsnull;
if (mIsPending) { if (mIsPending) {
@ -156,7 +157,7 @@ nsAsyncStreamCopier::Cancel(nsresult status)
{ {
nsCOMPtr<nsISupports> copierCtx; nsCOMPtr<nsISupports> copierCtx;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mIsPending) if (!mIsPending)
return NS_OK; return NS_OK;
copierCtx.swap(mCopierCtx); copierCtx.swap(mCopierCtx);
@ -228,6 +229,11 @@ nsAsyncStreamCopier::Init(nsIInputStream *source,
{ {
NS_ASSERTION(sourceBuffered || sinkBuffered, "at least one stream must be buffered"); NS_ASSERTION(sourceBuffered || sinkBuffered, "at least one stream must be buffered");
NS_ASSERTION(!mLock, "already initialized");
mLock = nsAutoLock::NewLock("nsAsyncStreamCopier::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
if (chunkSize == 0) if (chunkSize == 0)
chunkSize = nsIOService::gDefaultSegmentSize; chunkSize = nsIOService::gDefaultSegmentSize;
mChunkSize = chunkSize; mChunkSize = chunkSize;

View File

@ -42,9 +42,9 @@
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"
#include "nsIAsyncOutputStream.h" #include "nsIAsyncOutputStream.h"
#include "nsIRequestObserver.h" #include "nsIRequestObserver.h"
#include "mozilla/Mutex.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "prlock.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -78,7 +78,7 @@ private:
nsCOMPtr<nsISupports> mCopierCtx; nsCOMPtr<nsISupports> mCopierCtx;
mozilla::Mutex mLock; PRLock *mLock;
nsAsyncCopyMode mMode; nsAsyncCopyMode mMode;
PRUint32 mChunkSize; PRUint32 mChunkSize;

View File

@ -47,6 +47,7 @@
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "prmon.h" #include "prmon.h"

View File

@ -43,6 +43,7 @@
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsIProxyAutoConfig.h" #include "nsIProxyAutoConfig.h"
#include "nsAutoLock.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIProtocolHandler.h" #include "nsIProtocolHandler.h"

View File

@ -40,14 +40,13 @@
#include "nsSocketTransport2.h" #include "nsSocketTransport2.h"
#include "nsServerSocket.h" #include "nsServerSocket.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsNetError.h" #include "nsNetError.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "prnetdb.h" #include "prnetdb.h"
#include "prio.h" #include "prio.h"
using namespace mozilla;
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -72,7 +71,7 @@ PostEvent(nsServerSocket *s, nsServerSocketFunc func)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsServerSocket::nsServerSocket() nsServerSocket::nsServerSocket()
: mLock("nsServerSocket.mLock") : mLock(nsnull)
, mFD(nsnull) , mFD(nsnull)
, mAttached(PR_FALSE) , mAttached(PR_FALSE)
{ {
@ -92,6 +91,9 @@ nsServerSocket::~nsServerSocket()
{ {
Close(); // just in case :) Close(); // just in case :)
if (mLock)
nsAutoLock::DestroyLock(mLock);
// release our reference to the STS // release our reference to the STS
nsSocketTransportService *serv = gSocketTransportService; nsSocketTransportService *serv = gSocketTransportService;
NS_IF_RELEASE(serv); NS_IF_RELEASE(serv);
@ -244,7 +246,7 @@ nsServerSocket::OnSocketDetached(PRFileDesc *fd)
// need to atomically clear mListener. see our Close() method. // need to atomically clear mListener. see our Close() method.
nsIServerSocketListener *listener = nsnull; nsIServerSocketListener *listener = nsnull;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mListener.swap(listener); mListener.swap(listener);
} }
// XXX we need to proxy the release to the listener's target thread to work // XXX we need to proxy the release to the listener's target thread to work
@ -288,6 +290,13 @@ nsServerSocket::InitWithAddress(const PRNetAddr *aAddr, PRInt32 aBackLog)
{ {
NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED); NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED);
if (!mLock)
{
mLock = nsAutoLock::NewLock("nsServerSocket::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
}
// //
// configure listening socket... // configure listening socket...
// //
@ -344,8 +353,9 @@ fail:
NS_IMETHODIMP NS_IMETHODIMP
nsServerSocket::Close() nsServerSocket::Close()
{ {
NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// we want to proxy the close operation to the socket thread if a listener // we want to proxy the close operation to the socket thread if a listener
// has been set. otherwise, we should just close the socket here... // has been set. otherwise, we should just close the socket here...
if (!mListener) if (!mListener)
@ -368,7 +378,7 @@ nsServerSocket::AsyncListen(nsIServerSocketListener *aListener)
NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_TRUE(mListener == nsnull, NS_ERROR_IN_PROGRESS); NS_ENSURE_TRUE(mListener == nsnull, NS_ERROR_IN_PROGRESS);
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD,
NS_GET_IID(nsIServerSocketListener), NS_GET_IID(nsIServerSocketListener),
aListener, aListener,

View File

@ -40,7 +40,6 @@
#include "nsIServerSocket.h" #include "nsIServerSocket.h"
#include "nsSocketTransportService2.h" #include "nsSocketTransportService2.h"
#include "mozilla/Mutex.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -68,7 +67,7 @@ private:
nsresult TryAttach(); nsresult TryAttach();
// lock protects access to mListener; so it is not cleared while being used. // lock protects access to mListener; so it is not cleared while being used.
mozilla::Mutex mLock; PRLock *mLock;
PRFileDesc *mFD; PRFileDesc *mFD;
PRNetAddr mAddr; PRNetAddr mAddr;
nsCOMPtr<nsIServerSocketListener> mListener; nsCOMPtr<nsIServerSocketListener> mListener;

View File

@ -50,6 +50,7 @@
#include "nsTransportUtils.h" #include "nsTransportUtils.h"
#include "nsProxyInfo.h" #include "nsProxyInfo.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "netCore.h" #include "netCore.h"
@ -74,8 +75,6 @@
#include "nsNativeConnectionHelper.h" #include "nsNativeConnectionHelper.h"
#endif #endif
using namespace mozilla;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID); static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
@ -238,7 +237,7 @@ nsSocketInputStream::OnSocketReady(nsresult condition)
nsCOMPtr<nsIInputStreamCallback> callback; nsCOMPtr<nsIInputStreamCallback> callback;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
// update condition, but be careful not to erase an already // update condition, but be careful not to erase an already
// existing error condition. // existing error condition.
@ -291,7 +290,7 @@ nsSocketInputStream::Available(PRUint32 *avail)
PRFileDesc *fd; PRFileDesc *fd;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (NS_FAILED(mCondition)) if (NS_FAILED(mCondition))
return mCondition; return mCondition;
@ -308,7 +307,7 @@ nsSocketInputStream::Available(PRUint32 *avail)
nsresult rv; nsresult rv;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
mTransport->ReleaseFD_Locked(fd); mTransport->ReleaseFD_Locked(fd);
@ -336,7 +335,7 @@ nsSocketInputStream::Read(char *buf, PRUint32 count, PRUint32 *countRead)
PRFileDesc *fd; PRFileDesc *fd;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (NS_FAILED(mCondition)) if (NS_FAILED(mCondition))
return (mCondition == NS_BASE_STREAM_CLOSED) ? NS_OK : mCondition; return (mCondition == NS_BASE_STREAM_CLOSED) ? NS_OK : mCondition;
@ -357,7 +356,7 @@ nsSocketInputStream::Read(char *buf, PRUint32 count, PRUint32 *countRead)
nsresult rv; nsresult rv;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
#ifdef ENABLE_SOCKET_TRACING #ifdef ENABLE_SOCKET_TRACING
if (n > 0) if (n > 0)
@ -410,7 +409,7 @@ nsSocketInputStream::CloseWithStatus(nsresult reason)
nsresult rv; nsresult rv;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (NS_SUCCEEDED(mCondition)) if (NS_SUCCEEDED(mCondition))
rv = mCondition = reason; rv = mCondition = reason;
@ -435,7 +434,7 @@ nsSocketInputStream::AsyncWait(nsIInputStreamCallback *callback,
// (different from callback when target is not null) // (different from callback when target is not null)
nsCOMPtr<nsIInputStreamCallback> directCallback; nsCOMPtr<nsIInputStreamCallback> directCallback;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (callback && target) { if (callback && target) {
// //
@ -497,7 +496,7 @@ nsSocketOutputStream::OnSocketReady(nsresult condition)
nsCOMPtr<nsIOutputStreamCallback> callback; nsCOMPtr<nsIOutputStreamCallback> callback;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
// update condition, but be careful not to erase an already // update condition, but be careful not to erase an already
// existing error condition. // existing error condition.
@ -559,7 +558,7 @@ nsSocketOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *countWrit
PRFileDesc *fd; PRFileDesc *fd;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (NS_FAILED(mCondition)) if (NS_FAILED(mCondition))
return mCondition; return mCondition;
@ -581,7 +580,7 @@ nsSocketOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *countWrit
nsresult rv; nsresult rv;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
#ifdef ENABLE_SOCKET_TRACING #ifdef ENABLE_SOCKET_TRACING
if (n > 0) if (n > 0)
@ -652,7 +651,7 @@ nsSocketOutputStream::CloseWithStatus(nsresult reason)
nsresult rv; nsresult rv;
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (NS_SUCCEEDED(mCondition)) if (NS_SUCCEEDED(mCondition))
rv = mCondition = reason; rv = mCondition = reason;
@ -673,7 +672,7 @@ nsSocketOutputStream::AsyncWait(nsIOutputStreamCallback *callback,
SOCKET_LOG(("nsSocketOutputStream::AsyncWait [this=%x]\n", this)); SOCKET_LOG(("nsSocketOutputStream::AsyncWait [this=%x]\n", this));
{ {
MutexAutoLock lock(mTransport->mLock); nsAutoLock lock(mTransport->mLock);
if (callback && target) { if (callback && target) {
// //
@ -714,7 +713,7 @@ nsSocketTransport::nsSocketTransport()
, mInputClosed(PR_TRUE) , mInputClosed(PR_TRUE)
, mOutputClosed(PR_TRUE) , mOutputClosed(PR_TRUE)
, mResolving(PR_FALSE) , mResolving(PR_FALSE)
, mLock("nsSocketTransport.mLock") , mLock(nsAutoLock::NewLock("nsSocketTransport::mLock"))
, mFD(nsnull) , mFD(nsnull)
, mFDref(0) , mFDref(0)
, mFDconnected(PR_FALSE) , mFDconnected(PR_FALSE)
@ -741,6 +740,9 @@ nsSocketTransport::~nsSocketTransport()
PL_strfree(mTypes[i]); PL_strfree(mTypes[i]);
free(mTypes); free(mTypes);
} }
if (mLock)
nsAutoLock::DestroyLock(mLock);
nsSocketTransportService *serv = gSocketTransportService; nsSocketTransportService *serv = gSocketTransportService;
NS_RELEASE(serv); // nulls argument NS_RELEASE(serv); // nulls argument
@ -751,6 +753,9 @@ nsSocketTransport::Init(const char **types, PRUint32 typeCount,
const nsACString &host, PRUint16 port, const nsACString &host, PRUint16 port,
nsIProxyInfo *givenProxyInfo) nsIProxyInfo *givenProxyInfo)
{ {
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsProxyInfo> proxyInfo; nsCOMPtr<nsProxyInfo> proxyInfo;
if (givenProxyInfo) { if (givenProxyInfo) {
proxyInfo = do_QueryInterface(givenProxyInfo); proxyInfo = do_QueryInterface(givenProxyInfo);
@ -832,6 +837,9 @@ nsSocketTransport::Init(const char **types, PRUint32 typeCount,
nsresult nsresult
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const PRNetAddr *addr) nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const PRNetAddr *addr)
{ {
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
NS_ASSERTION(!mFD, "already initialized"); NS_ASSERTION(!mFD, "already initialized");
char buf[64]; char buf[64];
@ -889,7 +897,7 @@ nsSocketTransport::SendStatus(nsresult status)
nsCOMPtr<nsITransportEventSink> sink; nsCOMPtr<nsITransportEventSink> sink;
PRUint64 progress; PRUint64 progress;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
sink = mEventSink; sink = mEventSink;
switch (status) { switch (status) {
case STATUS_SENDING_TO: case STATUS_SENDING_TO:
@ -1032,7 +1040,7 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, PRBool &proxyTransparent, PRBool
// remember security info and give notification callbacks to PSM... // remember security info and give notification callbacks to PSM...
nsCOMPtr<nsIInterfaceRequestor> callbacks; nsCOMPtr<nsIInterfaceRequestor> callbacks;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mSecInfo = secinfo; mSecInfo = secinfo;
callbacks = mCallbacks; callbacks = mCallbacks;
SOCKET_LOG((" [secinfo=%x callbacks=%x]\n", mSecInfo.get(), mCallbacks.get())); SOCKET_LOG((" [secinfo=%x callbacks=%x]\n", mSecInfo.get(), mCallbacks.get()));
@ -1151,7 +1159,7 @@ nsSocketTransport::InitiateSocket()
// assign mFD so that we can properly handle OnSocketDetached before we've // assign mFD so that we can properly handle OnSocketDetached before we've
// established a connection. // established a connection.
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mFD = fd; mFD = fd;
mFDref = 1; mFDref = 1;
mFDconnected = PR_FALSE; mFDconnected = PR_FALSE;
@ -1365,7 +1373,7 @@ nsSocketTransport::OnSocketConnected()
// assign mFD (must do this within the transport lock), but take care not // assign mFD (must do this within the transport lock), but take care not
// to trample over mFDref if mFD is already set. // to trample over mFDref if mFD is already set.
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_ASSERTION(mFD, "no socket"); NS_ASSERTION(mFD, "no socket");
NS_ASSERTION(mFDref == 1, "wrong socket ref count"); NS_ASSERTION(mFDref == 1, "wrong socket ref count");
mFDconnected = PR_TRUE; mFDconnected = PR_TRUE;
@ -1632,7 +1640,7 @@ nsSocketTransport::OnSocketDetached(PRFileDesc *fd)
nsCOMPtr<nsIInterfaceRequestor> ourCallbacks; nsCOMPtr<nsIInterfaceRequestor> ourCallbacks;
nsCOMPtr<nsITransportEventSink> ourEventSink; nsCOMPtr<nsITransportEventSink> ourEventSink;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mFD) { if (mFD) {
ReleaseFD_Locked(mFD); ReleaseFD_Locked(mFD);
// flag mFD as unusable; this prevents other consumers from // flag mFD as unusable; this prevents other consumers from
@ -1773,7 +1781,7 @@ nsSocketTransport::Close(nsresult reason)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::GetSecurityInfo(nsISupports **secinfo) nsSocketTransport::GetSecurityInfo(nsISupports **secinfo)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_IF_ADDREF(*secinfo = mSecInfo); NS_IF_ADDREF(*secinfo = mSecInfo);
return NS_OK; return NS_OK;
} }
@ -1781,7 +1789,7 @@ nsSocketTransport::GetSecurityInfo(nsISupports **secinfo)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::GetSecurityCallbacks(nsIInterfaceRequestor **callbacks) nsSocketTransport::GetSecurityCallbacks(nsIInterfaceRequestor **callbacks)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
NS_IF_ADDREF(*callbacks = mCallbacks); NS_IF_ADDREF(*callbacks = mCallbacks);
return NS_OK; return NS_OK;
} }
@ -1789,7 +1797,7 @@ nsSocketTransport::GetSecurityCallbacks(nsIInterfaceRequestor **callbacks)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::SetSecurityCallbacks(nsIInterfaceRequestor *callbacks) nsSocketTransport::SetSecurityCallbacks(nsIInterfaceRequestor *callbacks)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mCallbacks = callbacks; mCallbacks = callbacks;
// XXX should we tell PSM about this? // XXX should we tell PSM about this?
return NS_OK; return NS_OK;
@ -1808,7 +1816,7 @@ nsSocketTransport::SetEventSink(nsITransportEventSink *sink,
sink = temp.get(); sink = temp.get();
} }
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mEventSink = sink; mEventSink = sink;
return NS_OK; return NS_OK;
} }
@ -1820,7 +1828,7 @@ nsSocketTransport::IsAlive(PRBool *result)
PRFileDesc *fd; PRFileDesc *fd;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (NS_FAILED(mCondition)) if (NS_FAILED(mCondition))
return NS_OK; return NS_OK;
fd = GetFD_Locked(); fd = GetFD_Locked();
@ -1837,7 +1845,7 @@ nsSocketTransport::IsAlive(PRBool *result)
*result = PR_TRUE; *result = PR_TRUE;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
ReleaseFD_Locked(fd); ReleaseFD_Locked(fd);
} }
return NS_OK; return NS_OK;
@ -1880,7 +1888,7 @@ nsSocketTransport::GetSelfAddr(PRNetAddr *addr)
PRFileDesc *fd; PRFileDesc *fd;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
fd = GetFD_Locked(); fd = GetFD_Locked();
} }
@ -1891,7 +1899,7 @@ nsSocketTransport::GetSelfAddr(PRNetAddr *addr)
(PR_GetSockName(fd, addr) == PR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE; (PR_GetSockName(fd, addr) == PR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
ReleaseFD_Locked(fd); ReleaseFD_Locked(fd);
} }

View File

@ -42,7 +42,6 @@
#define ENABLE_SOCKET_TRACING #define ENABLE_SOCKET_TRACING
#endif #endif
#include "mozilla/Mutex.h"
#include "nsSocketTransportService2.h" #include "nsSocketTransportService2.h"
#include "nsString.h" #include "nsString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -135,8 +134,6 @@ class nsSocketTransport : public nsASocketHandler
, public nsIDNSListener , public nsIDNSListener
, public nsIClassInfo , public nsIClassInfo
{ {
typedef mozilla::Mutex Mutex;
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSITRANSPORT NS_DECL_NSITRANSPORT
@ -257,7 +254,7 @@ private:
// socket input/output objects. these may be accessed on any thread with // socket input/output objects. these may be accessed on any thread with
// the exception of some specific methods (XXX). // the exception of some specific methods (XXX).
Mutex mLock; // protects members in this section PRLock *mLock; // protects members in this section
PRFileDesc *mFD; PRFileDesc *mFD;
nsrefcnt mFDref; // mFD is closed when mFDref goes to zero. nsrefcnt mFDref; // mFD is closed when mFDref goes to zero.
PRBool mFDconnected; // mFD is available to consumer when TRUE. PRBool mFDconnected; // mFD is available to consumer when TRUE.

View File

@ -43,8 +43,10 @@
#include "nsSocketTransportService2.h" #include "nsSocketTransportService2.h"
#include "nsSocketTransport2.h" #include "nsSocketTransport2.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsAutoLock.h"
#include "nsNetError.h" #include "nsNetError.h"
#include "prnetdb.h" #include "prnetdb.h"
#include "prlock.h"
#include "prerror.h" #include "prerror.h"
#include "plstr.h" #include "plstr.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
@ -54,8 +56,6 @@
#include "mozilla/FunctionTimer.h" #include "mozilla/FunctionTimer.h"
using namespace mozilla;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
PRLogModuleInfo *gSocketTransportLog = nsnull; PRLogModuleInfo *gSocketTransportLog = nsnull;
#endif #endif
@ -72,7 +72,7 @@ nsSocketTransportService::nsSocketTransportService()
: mThread(nsnull) : mThread(nsnull)
, mThreadEvent(nsnull) , mThreadEvent(nsnull)
, mAutodialEnabled(PR_FALSE) , mAutodialEnabled(PR_FALSE)
, mLock("nsSocketTransportService::mLock") , mLock(nsAutoLock::NewLock("nsSocketTransportService::mLock"))
, mInitialized(PR_FALSE) , mInitialized(PR_FALSE)
, mShuttingDown(PR_FALSE) , mShuttingDown(PR_FALSE)
, mActiveCount(0) , mActiveCount(0)
@ -93,6 +93,9 @@ nsSocketTransportService::~nsSocketTransportService()
{ {
NS_ASSERTION(NS_IsMainThread(), "wrong thread"); NS_ASSERTION(NS_IsMainThread(), "wrong thread");
NS_ASSERTION(!mInitialized, "not shutdown properly"); NS_ASSERTION(!mInitialized, "not shutdown properly");
if (mLock)
nsAutoLock::DestroyLock(mLock);
if (mThreadEvent) if (mThreadEvent)
PR_DestroyPollableEvent(mThreadEvent); PR_DestroyPollableEvent(mThreadEvent);
@ -106,7 +109,7 @@ nsSocketTransportService::~nsSocketTransportService()
already_AddRefed<nsIThread> already_AddRefed<nsIThread>
nsSocketTransportService::GetThreadSafely() nsSocketTransportService::GetThreadSafely()
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
nsIThread* result = mThread; nsIThread* result = mThread;
NS_IF_ADDREF(result); NS_IF_ADDREF(result);
return result; return result;
@ -380,6 +383,8 @@ nsSocketTransportService::Init()
{ {
NS_TIME_FUNCTION; NS_TIME_FUNCTION;
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
NS_ERROR("wrong thread"); NS_ERROR("wrong thread");
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
@ -420,7 +425,7 @@ nsSocketTransportService::Init()
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// Install our mThread, protecting against concurrent readers // Install our mThread, protecting against concurrent readers
thread.swap(mThread); thread.swap(mThread);
} }
@ -451,7 +456,7 @@ nsSocketTransportService::Shutdown()
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// signal the socket thread to shutdown // signal the socket thread to shutdown
mShuttingDown = PR_TRUE; mShuttingDown = PR_TRUE;
@ -464,7 +469,7 @@ nsSocketTransportService::Shutdown()
// join with thread // join with thread
mThread->Shutdown(); mThread->Shutdown();
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// Drop our reference to mThread and make sure that any concurrent // Drop our reference to mThread and make sure that any concurrent
// readers are excluded // readers are excluded
mThread = nsnull; mThread = nsnull;
@ -523,7 +528,7 @@ nsSocketTransportService::SetAutodialEnabled(PRBool value)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransportService::OnDispatchedEvent(nsIThreadInternal *thread) nsSocketTransportService::OnDispatchedEvent(nsIThreadInternal *thread)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mThreadEvent) if (mThreadEvent)
PR_SetPollableEvent(mThreadEvent); PR_SetPollableEvent(mThreadEvent);
return NS_OK; return NS_OK;
@ -580,7 +585,7 @@ nsSocketTransportService::Run()
// now that our event queue is empty, check to see if we should exit // now that our event queue is empty, check to see if we should exit
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mShuttingDown) if (mShuttingDown)
break; break;
} }
@ -715,7 +720,7 @@ nsSocketTransportService::DoPollIteration(PRBool wait)
// new pollable event. If that fails, we fall back // new pollable event. If that fails, we fall back
// on "busy wait". // on "busy wait".
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
PR_DestroyPollableEvent(mThreadEvent); PR_DestroyPollableEvent(mThreadEvent);
mThreadEvent = PR_NewPollableEvent(); mThreadEvent = PR_NewPollableEvent();
} }

View File

@ -50,7 +50,6 @@
#include "prio.h" #include "prio.h"
#include "nsASocketHandler.h" #include "nsASocketHandler.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "mozilla/Mutex.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -76,8 +75,6 @@ class nsSocketTransportService : public nsPISocketTransportService
, public nsIRunnable , public nsIRunnable
, public nsIObserver , public nsIObserver
{ {
typedef mozilla::Mutex Mutex;
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSPISOCKETTRANSPORTSERVICE NS_DECL_NSPISOCKETTRANSPORTSERVICE
@ -129,7 +126,7 @@ private:
// initialization and shutdown (any thread) // initialization and shutdown (any thread)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
Mutex mLock; PRLock *mLock;
PRPackedBool mInitialized; PRPackedBool mInitialized;
PRPackedBool mShuttingDown; PRPackedBool mShuttingDown;
// indicates whether we are currently in the // indicates whether we are currently in the

View File

@ -38,6 +38,7 @@
#include "nsStreamTransportService.h" #include "nsStreamTransportService.h"
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "nsNetSegmentUtils.h" #include "nsNetSegmentUtils.h"
#include "nsAutoLock.h"
#include "nsInt64.h" #include "nsInt64.h"
#include "nsTransportUtils.h" #include "nsTransportUtils.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"

View File

@ -34,16 +34,14 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "mozilla/Mutex.h"
#include "nsTransportUtils.h" #include "nsTransportUtils.h"
#include "nsITransport.h" #include "nsITransport.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
using namespace mozilla;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class nsTransportStatusEvent; class nsTransportStatusEvent;
@ -59,7 +57,7 @@ public:
PRBool coalesceAll) PRBool coalesceAll)
: mSink(sink) : mSink(sink)
, mTarget(target) , mTarget(target)
, mLock("nsTransportEventSinkProxy.mLock") , mLock(nsAutoLock::NewLock("nsTransportEventSinkProxy::mLock"))
, mLastEvent(nsnull) , mLastEvent(nsnull)
, mCoalesceAll(coalesceAll) , mCoalesceAll(coalesceAll)
{ {
@ -68,6 +66,9 @@ public:
virtual ~nsTransportEventSinkProxy() virtual ~nsTransportEventSinkProxy()
{ {
if (mLock)
nsAutoLock::DestroyLock(mLock);
// our reference to mSink could be the last, so be sure to release // our reference to mSink could be the last, so be sure to release
// it on the target thread. otherwise, we could get into trouble. // it on the target thread. otherwise, we could get into trouble.
NS_ProxyRelease(mTarget, mSink); NS_ProxyRelease(mTarget, mSink);
@ -75,7 +76,7 @@ public:
nsITransportEventSink *mSink; nsITransportEventSink *mSink;
nsCOMPtr<nsIEventTarget> mTarget; nsCOMPtr<nsIEventTarget> mTarget;
Mutex mLock; PRLock *mLock;
nsTransportStatusEvent *mLastEvent; nsTransportStatusEvent *mLastEvent;
PRBool mCoalesceAll; PRBool mCoalesceAll;
}; };
@ -102,7 +103,7 @@ public:
// since this event is being handled, we need to clear the proxy's ref. // since this event is being handled, we need to clear the proxy's ref.
// if not coalescing all, then last event may not equal self! // if not coalescing all, then last event may not equal self!
{ {
MutexAutoLock lock(mProxy->mLock); nsAutoLock lock(mProxy->mLock);
if (mProxy->mLastEvent == this) if (mProxy->mLastEvent == this)
mProxy->mLastEvent = nsnull; mProxy->mLastEvent = nsnull;
} }
@ -132,7 +133,7 @@ nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsRefPtr<nsTransportStatusEvent> event; nsRefPtr<nsTransportStatusEvent> event;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// try to coalesce events! ;-) // try to coalesce events! ;-)
if (mLastEvent && (mCoalesceAll || mLastEvent->mStatus == status)) { if (mLastEvent && (mCoalesceAll || mLastEvent->mStatus == status)) {
@ -153,7 +154,7 @@ nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("unable to post transport status event"); NS_WARNING("unable to post transport status event");
MutexAutoLock lock(mLock); // cleanup.. don't reference anymore! nsAutoLock lock(mLock); // cleanup.. don't reference anymore!
mLastEvent = nsnull; mLastEvent = nsnull;
} }
} }

View File

@ -254,7 +254,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpHandler, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpsHandler, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpsHandler, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpAuthManager, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpAuthManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpChannelAuthProvider) NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpChannelAuthProvider)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpActivityDistributor) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpActivityDistributor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth) NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpDigestAuth) NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpDigestAuth)
#endif // !NECKO_PROTOCOL_http #endif // !NECKO_PROTOCOL_http

View File

@ -42,8 +42,6 @@
#define _nsCacheRequest_h_ #define _nsCacheRequest_h_
#include "nspr.h" #include "nspr.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsICache.h" #include "nsICache.h"
#include "nsICacheListener.h" #include "nsICacheListener.h"
@ -53,10 +51,6 @@
class nsCacheRequest : public PRCList class nsCacheRequest : public PRCList
{ {
typedef mozilla::CondVar CondVar;
typedef mozilla::MutexAutoLock MutexAutoLock;
typedef mozilla::Mutex Mutex;
private: private:
friend class nsCacheService; friend class nsCacheService;
friend class nsCacheEntry; friend class nsCacheEntry;
@ -70,8 +64,8 @@ private:
: mKey(key), : mKey(key),
mInfo(0), mInfo(0),
mListener(listener), mListener(listener),
mLock("nsCacheRequest.mLock"), mLock(nsnull),
mCondVar(mLock, "nsCacheRequest.mCondVar") mCondVar(nsnull)
{ {
MOZ_COUNT_CTOR(nsCacheRequest); MOZ_COUNT_CTOR(nsCacheRequest);
PR_INIT_CLIST(this); PR_INIT_CLIST(this);
@ -88,6 +82,8 @@ private:
{ {
MOZ_COUNT_DTOR(nsCacheRequest); MOZ_COUNT_DTOR(nsCacheRequest);
delete mKey; delete mKey;
if (mLock) PR_DestroyLock(mLock);
if (mCondVar) PR_DestroyCondVar(mCondVar);
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list"); NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
if (mListener) if (mListener)
@ -155,20 +151,40 @@ private:
MarkWaitingForValidation(); // set up for next time MarkWaitingForValidation(); // set up for next time
return NS_OK; // early exit; return NS_OK; // early exit;
} }
{
MutexAutoLock lock(mLock); if (!mLock) {
while (WaitingForValidation()) { mLock = PR_NewLock();
mCondVar.Wait(); if (!mLock) return NS_ERROR_OUT_OF_MEMORY;
NS_ASSERTION(!mCondVar,"we have mCondVar, but didn't have mLock?");
mCondVar = PR_NewCondVar(mLock);
if (!mCondVar) {
PR_DestroyLock(mLock);
return NS_ERROR_OUT_OF_MEMORY;
} }
MarkWaitingForValidation(); // set up for next time }
} PRStatus status = PR_SUCCESS;
PR_Lock(mLock);
while (WaitingForValidation() && (status == PR_SUCCESS) ) {
status = PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
}
MarkWaitingForValidation(); // set up for next time
PR_Unlock(mLock);
NS_ASSERTION(status == PR_SUCCESS, "PR_WaitCondVar() returned PR_FAILURE?");
if (status == PR_FAILURE)
return NS_ERROR_UNEXPECTED;
return NS_OK; return NS_OK;
} }
void WakeUp(void) { void WakeUp(void) {
DoneWaitingForValidation(); DoneWaitingForValidation();
MutexAutoLock lock(mLock); if (mLock) {
mCondVar.Notify(); PR_Lock(mLock);
PR_NotifyCondVar(mCondVar);
PR_Unlock(mLock);
}
} }
/** /**
@ -178,8 +194,8 @@ private:
PRUint32 mInfo; PRUint32 mInfo;
nsICacheListener * mListener; // strong ref nsICacheListener * mListener; // strong ref
nsCOMPtr<nsIThread> mThread; nsCOMPtr<nsIThread> mThread;
Mutex mLock; PRLock * mLock;
CondVar mCondVar; PRCondVar * mCondVar;
}; };
#endif // _nsCacheRequest_h_ #endif // _nsCacheRequest_h_

View File

@ -80,8 +80,6 @@
#include "mozilla/net/NeckoCommon.h" #include "mozilla/net/NeckoCommon.h"
#endif #endif
using namespace mozilla;
/****************************************************************************** /******************************************************************************
* nsCacheProfilePrefObserver * nsCacheProfilePrefObserver
*****************************************************************************/ *****************************************************************************/
@ -277,11 +275,12 @@ public:
} }
NS_IMETHOD Run() NS_IMETHOD Run()
{ {
nsCacheServiceAutoLock autoLock; mozilla::MonitorAutoEnter
autoMonitor(nsCacheService::gService->mMonitor);
#ifdef PR_LOGGING #ifdef PR_LOGGING
CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this)); CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this));
#endif #endif
nsCacheService::gService->mCondVar.Notify(); autoMonitor.Notify();
return NS_OK; return NS_OK;
} }
}; };
@ -810,9 +809,12 @@ nsCacheService::DispatchToCacheIOThread(nsIRunnable* event)
nsresult nsresult
nsCacheService::SyncWithCacheIOThread() nsCacheService::SyncWithCacheIOThread()
{ {
gService->mLock.AssertCurrentThreadOwns(); NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(),
"not holding cache-lock");
if (!gService->mCacheIOThread) return NS_ERROR_NOT_AVAILABLE; if (!gService->mCacheIOThread) return NS_ERROR_NOT_AVAILABLE;
mozilla::MonitorAutoEnter autoMonitor(gService->mMonitor);
nsCOMPtr<nsIRunnable> event = new nsBlockOnCacheThreadEvent(); nsCOMPtr<nsIRunnable> event = new nsBlockOnCacheThreadEvent();
// dispatch event - it will notify the monitor when it's done // dispatch event - it will notify the monitor when it's done
@ -823,8 +825,10 @@ nsCacheService::SyncWithCacheIOThread()
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
Unlock();
// wait until notified, then return // wait until notified, then return
rv = gService->mCondVar.Wait(); rv = autoMonitor.Wait();
Lock();
return rv; return rv;
} }
@ -981,8 +985,8 @@ nsCacheService * nsCacheService::gService = nsnull;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService) NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService)
nsCacheService::nsCacheService() nsCacheService::nsCacheService()
: mLock("nsCacheService.mLock"), : mLock(nsnull),
mCondVar(mLock, "nsCacheService.mCondVar"), mMonitor("block-on-cache-monitor"),
mInitialized(PR_FALSE), mInitialized(PR_FALSE),
mEnableMemoryDevice(PR_TRUE), mEnableMemoryDevice(PR_TRUE),
mEnableDiskDevice(PR_TRUE), mEnableDiskDevice(PR_TRUE),
@ -1003,6 +1007,13 @@ nsCacheService::nsCacheService()
// create list of cache devices // create list of cache devices
PR_INIT_CLIST(&mDoomedEntries); PR_INIT_CLIST(&mDoomedEntries);
// allocate service lock
mLock = PR_NewLock();
#if defined(DEBUG)
mLockedThread = nsnull;
#endif
} }
nsCacheService::~nsCacheService() nsCacheService::~nsCacheService()
@ -1010,6 +1021,7 @@ nsCacheService::~nsCacheService()
if (mInitialized) // Shutdown hasn't been called yet. if (mInitialized) // Shutdown hasn't been called yet.
(void) Shutdown(); (void) Shutdown();
PR_DestroyLock(mLock);
gService = nsnull; gService = nsnull;
} }
@ -1029,6 +1041,9 @@ nsCacheService::Init()
} }
#endif #endif
if (mLock == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
CACHE_LOG_INIT(); CACHE_LOG_INIT();
nsresult rv = NS_NewThread(getter_AddRefs(mCacheIOThread)); nsresult rv = NS_NewThread(getter_AddRefs(mCacheIOThread));
@ -2196,18 +2211,25 @@ nsCacheService::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize)
void void
nsCacheService::Lock() nsCacheService::Lock()
{ {
gService->mLock.Lock(); PR_Lock(gService->mLock);
#if defined(DEBUG)
gService->mLockedThread = PR_GetCurrentThread();
#endif
} }
void void
nsCacheService::Unlock() nsCacheService::Unlock()
{ {
gService->mLock.AssertCurrentThreadOwns(); NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(), "oops");
nsTArray<nsISupports*> doomed; nsTArray<nsISupports*> doomed;
doomed.SwapElements(gService->mDoomedObjects); doomed.SwapElements(gService->mDoomedObjects);
gService->mLock.Unlock(); #if defined(DEBUG)
gService->mLockedThread = nsnull;
#endif
PR_Unlock(gService->mLock);
for (PRUint32 i = 0; i < doomed.Length(); ++i) for (PRUint32 i = 0; i < doomed.Length(); ++i)
doomed[i]->Release(); doomed[i]->Release();
@ -2217,7 +2239,7 @@ void
nsCacheService::ReleaseObject_Locked(nsISupports * obj, nsCacheService::ReleaseObject_Locked(nsISupports * obj,
nsIEventTarget * target) nsIEventTarget * target)
{ {
gService->mLock.AssertCurrentThreadOwns(); NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(), "oops");
PRBool isCur; PRBool isCur;
if (!target || (NS_SUCCEEDED(target->IsOnCurrentThread(&isCur)) && isCur)) { if (!target || (NS_SUCCEEDED(target->IsOnCurrentThread(&isCur)) && isCur)) {

View File

@ -50,13 +50,13 @@
#include "nsCacheDevice.h" #include "nsCacheDevice.h"
#include "nsCacheEntry.h" #include "nsCacheEntry.h"
#include "prlock.h"
#include "prthread.h" #include "prthread.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsString.h" #include "nsString.h"
#include "nsProxiedService.h" #include "nsProxiedService.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/CondVar.h" #include "mozilla/Monitor.h"
#include "mozilla/Mutex.h"
class nsCacheRequest; class nsCacheRequest;
class nsCacheProfilePrefObserver; class nsCacheProfilePrefObserver;
@ -172,10 +172,6 @@ public:
nsresult Init(); nsresult Init();
void Shutdown(); void Shutdown();
static void AssertOwnsLock()
{ gService->mLock.AssertCurrentThreadOwns(); }
private: private:
friend class nsCacheServiceAutoLock; friend class nsCacheServiceAutoLock;
friend class nsOfflineCacheDevice; friend class nsOfflineCacheDevice;
@ -258,8 +254,13 @@ private:
nsCacheProfilePrefObserver * mObserver; nsCacheProfilePrefObserver * mObserver;
mozilla::Mutex mLock; PRLock * mLock;
mozilla::CondVar mCondVar;
mozilla::Monitor mMonitor;
#if defined(DEBUG)
PRThread * mLockedThread; // The thread holding mLock
#endif
nsCOMPtr<nsIThread> mCacheIOThread; nsCOMPtr<nsIThread> mCacheIOThread;

View File

@ -75,6 +75,7 @@
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsAutoLock.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsISimpleEnumerator.h" #include "nsISimpleEnumerator.h"
@ -397,8 +398,6 @@ nsDiskCacheDevice::Init()
nsresult nsresult
nsDiskCacheDevice::Shutdown() nsDiskCacheDevice::Shutdown()
{ {
nsCacheService::AssertOwnsLock();
nsresult rv = Shutdown_Private(PR_TRUE); nsresult rv = Shutdown_Private(PR_TRUE);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;

View File

@ -46,6 +46,7 @@
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsString.h" #include "nsString.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsNetError.h" #include "nsNetError.h"
@ -60,8 +61,6 @@
#include "mozilla/FunctionTimer.h" #include "mozilla/FunctionTimer.h"
using namespace mozilla;
static const char kPrefDnsCacheEntries[] = "network.dnsCacheEntries"; static const char kPrefDnsCacheEntries[] = "network.dnsCacheEntries";
static const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration"; static const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration";
static const char kPrefEnableIDN[] = "network.enableIDN"; static const char kPrefEnableIDN[] = "network.enableIDN";
@ -106,14 +105,13 @@ nsDNSRecord::GetCanonicalName(nsACString &result)
// if the record is for an IP address literal, then the canonical // if the record is for an IP address literal, then the canonical
// host name is the IP address literal. // host name is the IP address literal.
const char *cname; const char *cname;
{ PR_Lock(mHostRecord->addr_info_lock);
MutexAutoLock lock(*mHostRecord->addr_info_lock); if (mHostRecord->addr_info)
if (mHostRecord->addr_info) cname = PR_GetCanonNameFromAddrInfo(mHostRecord->addr_info);
cname = PR_GetCanonNameFromAddrInfo(mHostRecord->addr_info); else
else cname = mHostRecord->host;
cname = mHostRecord->host; result.Assign(cname);
result.Assign(cname); PR_Unlock(mHostRecord->addr_info_lock);
}
return NS_OK; return NS_OK;
} }
@ -126,7 +124,7 @@ nsDNSRecord::GetNextAddr(PRUint16 port, PRNetAddr *addr)
if (mDone) if (mDone)
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
mHostRecord->addr_info_lock->Lock(); PR_Lock(mHostRecord->addr_info_lock);
if (mHostRecord->addr_info) { if (mHostRecord->addr_info) {
if (!mIter) if (!mIter)
mIterGenCnt = mHostRecord->addr_info_gencnt; mIterGenCnt = mHostRecord->addr_info_gencnt;
@ -137,14 +135,14 @@ nsDNSRecord::GetNextAddr(PRUint16 port, PRNetAddr *addr)
mIterGenCnt = mHostRecord->addr_info_gencnt; mIterGenCnt = mHostRecord->addr_info_gencnt;
} }
mIter = PR_EnumerateAddrInfo(mIter, mHostRecord->addr_info, port, addr); mIter = PR_EnumerateAddrInfo(mIter, mHostRecord->addr_info, port, addr);
mHostRecord->addr_info_lock->Unlock(); PR_Unlock(mHostRecord->addr_info_lock);
if (!mIter) { if (!mIter) {
mDone = PR_TRUE; mDone = PR_TRUE;
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
} }
else { else {
mHostRecord->addr_info_lock->Unlock(); PR_Unlock(mHostRecord->addr_info_lock);
if (!mHostRecord->addr) { if (!mHostRecord->addr) {
// Both mHostRecord->addr_info and mHostRecord->addr are null. // Both mHostRecord->addr_info and mHostRecord->addr are null.
// This can happen if mHostRecord->addr_info expired and the // This can happen if mHostRecord->addr_info expired and the
@ -308,13 +306,14 @@ nsDNSSyncRequest::OnLookupComplete(nsHostResolver *resolver,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsDNSService::nsDNSService() nsDNSService::nsDNSService()
: mLock("nsDNSServer.mLock") : mLock(nsnull)
, mFirstTime(PR_TRUE)
{ {
} }
nsDNSService::~nsDNSService() nsDNSService::~nsDNSService()
{ {
if (mLock)
nsAutoLock::DestroyLock(mLock);
} }
NS_IMPL_THREADSAFE_ISUPPORTS3(nsDNSService, nsIDNSService, nsPIDNSService, NS_IMPL_THREADSAFE_ISUPPORTS3(nsDNSService, nsIDNSService, nsPIDNSService,
@ -327,6 +326,8 @@ nsDNSService::Init()
NS_ENSURE_TRUE(!mResolver, NS_ERROR_ALREADY_INITIALIZED); NS_ENSURE_TRUE(!mResolver, NS_ERROR_ALREADY_INITIALIZED);
PRBool firstTime = (mLock == nsnull);
// prefs // prefs
PRUint32 maxCacheEntries = 400; PRUint32 maxCacheEntries = 400;
PRUint32 maxCacheLifetime = 3; // minutes PRUint32 maxCacheLifetime = 3; // minutes
@ -356,8 +357,10 @@ nsDNSService::Init()
prefs->GetIntPref("network.proxy.type", &proxyType); prefs->GetIntPref("network.proxy.type", &proxyType);
} }
if (mFirstTime) { if (firstTime) {
mFirstTime = PR_FALSE; mLock = nsAutoLock::NewLock("nsDNSService::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
// register as prefs observer // register as prefs observer
if (prefs) { if (prefs) {
@ -393,7 +396,7 @@ nsDNSService::Init()
getter_AddRefs(res)); getter_AddRefs(res));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// now, set all of our member variables while holding the lock // now, set all of our member variables while holding the lock
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mResolver = res; mResolver = res;
mIDN = idn; mIDN = idn;
mIPv4OnlyDomains = ipv4OnlyDomains; // exchanges buffer ownership mIPv4OnlyDomains = ipv4OnlyDomains; // exchanges buffer ownership
@ -410,7 +413,7 @@ nsDNSService::Shutdown()
{ {
nsRefPtr<nsHostResolver> res; nsRefPtr<nsHostResolver> res;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
res = mResolver; res = mResolver;
mResolver = nsnull; mResolver = nsnull;
} }
@ -431,7 +434,7 @@ nsDNSService::AsyncResolve(const nsACString &hostname,
nsRefPtr<nsHostResolver> res; nsRefPtr<nsHostResolver> res;
nsCOMPtr<nsIIDNService> idn; nsCOMPtr<nsIIDNService> idn;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mDisablePrefetch && (flags & RESOLVE_SPECULATE)) if (mDisablePrefetch && (flags & RESOLVE_SPECULATE))
return NS_ERROR_DNS_LOOKUP_QUEUE_FULL; return NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
@ -490,7 +493,7 @@ nsDNSService::Resolve(const nsACString &hostname,
nsRefPtr<nsHostResolver> res; nsRefPtr<nsHostResolver> res;
nsCOMPtr<nsIIDNService> idn; nsCOMPtr<nsIIDNService> idn;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
res = mResolver; res = mResolver;
idn = mIDN; idn = mIDN;
} }
@ -585,7 +588,7 @@ nsDNSService::GetAFForLookup(const nsACString &host)
if (mDisableIPv6) if (mDisableIPv6)
return PR_AF_INET; return PR_AF_INET;
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
PRUint16 af = PR_AF_UNSPEC; PRUint16 af = PR_AF_UNSPEC;

View File

@ -40,7 +40,7 @@
#include "nsHostResolver.h" #include "nsHostResolver.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsString.h" #include "nsString.h"
#include "mozilla/Mutex.h" #include "prlock.h"
class nsDNSService : public nsPIDNSService class nsDNSService : public nsPIDNSService
, public nsIObserver , public nsIObserver
@ -61,7 +61,7 @@ private:
nsCOMPtr<nsIIDNService> mIDN; nsCOMPtr<nsIIDNService> mIDN;
// mLock protects access to mResolver and mIPv4OnlyDomains // mLock protects access to mResolver and mIPv4OnlyDomains
mozilla::Mutex mLock; PRLock *mLock;
// mIPv4OnlyDomains is a comma-separated list of domains for which only // mIPv4OnlyDomains is a comma-separated list of domains for which only
// IPv4 DNS lookups are performed. This allows the user to disable IPv6 on // IPv4 DNS lookups are performed. This allows the user to disable IPv6 on
@ -69,5 +69,4 @@ private:
nsAdoptingCString mIPv4OnlyDomains; nsAdoptingCString mIPv4OnlyDomains;
PRBool mDisableIPv6; PRBool mDisableIPv6;
PRBool mDisablePrefetch; PRBool mDisablePrefetch;
PRBool mFirstTime;
}; };

View File

@ -53,10 +53,12 @@
#include "nsNetError.h" #include "nsNetError.h"
#include "nsISupportsBase.h" #include "nsISupportsBase.h"
#include "nsISupportsUtils.h" #include "nsISupportsUtils.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "pratom.h" #include "pratom.h"
#include "prthread.h" #include "prthread.h"
#include "prerror.h" #include "prerror.h"
#include "prcvar.h"
#include "prtime.h" #include "prtime.h"
#include "prlong.h" #include "prlong.h"
#include "prlog.h" #include "prlog.h"
@ -66,8 +68,6 @@
#include "mozilla/FunctionTimer.h" #include "mozilla/FunctionTimer.h"
using namespace mozilla;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Use a persistent thread pool in order to avoid spinning up new threads all the time. // Use a persistent thread pool in order to avoid spinning up new threads all the time.
@ -181,10 +181,18 @@ private:
nsresult nsresult
nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result) nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
{ {
PRLock *lock = PR_NewLock();
if (!lock)
return NS_ERROR_OUT_OF_MEMORY;
size_t hostLen = strlen(key->host) + 1; size_t hostLen = strlen(key->host) + 1;
size_t size = hostLen + sizeof(nsHostRecord); size_t size = hostLen + sizeof(nsHostRecord);
nsHostRecord *rec = (nsHostRecord*) ::operator new(size); nsHostRecord *rec = (nsHostRecord*) ::operator new(size);
if (!rec) {
PR_DestroyLock(lock);
return NS_ERROR_OUT_OF_MEMORY;
}
rec->host = ((char *) rec) + sizeof(nsHostRecord); rec->host = ((char *) rec) + sizeof(nsHostRecord);
rec->flags = key->flags; rec->flags = key->flags;
@ -192,7 +200,7 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
rec->_refc = 1; // addref rec->_refc = 1; // addref
NS_LOG_ADDREF(rec, 1, "nsHostRecord", sizeof(nsHostRecord)); NS_LOG_ADDREF(rec, 1, "nsHostRecord", sizeof(nsHostRecord));
rec->addr_info_lock = new Mutex("nsHostRecord.addr_info_lock"); rec->addr_info_lock = lock;
rec->addr_info = nsnull; rec->addr_info = nsnull;
rec->addr_info_gencnt = 0; rec->addr_info_gencnt = 0;
rec->addr = nsnull; rec->addr = nsnull;
@ -211,7 +219,10 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
nsHostRecord::~nsHostRecord() nsHostRecord::~nsHostRecord()
{ {
delete addr_info_lock; if (addr_info_lock)
PR_DestroyLock(addr_info_lock);
if (addr_info)
PR_FreeAddrInfo(addr_info);
if (addr) if (addr)
free(addr); free(addr);
} }
@ -319,8 +330,8 @@ nsHostResolver::nsHostResolver(PRUint32 maxCacheEntries,
PRUint32 maxCacheLifetime) PRUint32 maxCacheLifetime)
: mMaxCacheEntries(maxCacheEntries) : mMaxCacheEntries(maxCacheEntries)
, mMaxCacheLifetime(maxCacheLifetime) , mMaxCacheLifetime(maxCacheLifetime)
, mLock("nsHostResolver.mLock") , mLock(nsnull)
, mIdleThreadCV(mLock, "nsHostResolver.mIdleThreadCV") , mIdleThreadCV(nsnull)
, mNumIdleThreads(0) , mNumIdleThreads(0)
, mThreadCount(0) , mThreadCount(0)
, mActiveAnyThreadCount(0) , mActiveAnyThreadCount(0)
@ -340,6 +351,12 @@ nsHostResolver::nsHostResolver(PRUint32 maxCacheEntries,
nsHostResolver::~nsHostResolver() nsHostResolver::~nsHostResolver()
{ {
if (mIdleThreadCV)
PR_DestroyCondVar(mIdleThreadCV);
if (mLock)
nsAutoLock::DestroyLock(mLock);
PL_DHashTableFinish(&mDB); PL_DHashTableFinish(&mDB);
} }
@ -348,6 +365,14 @@ nsHostResolver::Init()
{ {
NS_TIME_FUNCTION; NS_TIME_FUNCTION;
mLock = nsAutoLock::NewLock("nsHostResolver::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
mIdleThreadCV = PR_NewCondVar(mLock);
if (!mIdleThreadCV)
return NS_ERROR_OUT_OF_MEMORY;
PL_DHashTableInit(&mDB, &gHostDB_ops, nsnull, sizeof(nsHostDBEnt), 0); PL_DHashTableInit(&mDB, &gHostDB_ops, nsnull, sizeof(nsHostDBEnt), 0);
mShutdown = PR_FALSE; mShutdown = PR_FALSE;
@ -393,7 +418,7 @@ nsHostResolver::Shutdown()
PR_INIT_CLIST(&evictionQ); PR_INIT_CLIST(&evictionQ);
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
mShutdown = PR_TRUE; mShutdown = PR_TRUE;
@ -405,7 +430,7 @@ nsHostResolver::Shutdown()
mPendingCount = 0; mPendingCount = 0;
if (mNumIdleThreads) if (mNumIdleThreads)
mIdleThreadCV.NotifyAll(); PR_NotifyAllCondVar(mIdleThreadCV);
// empty host database // empty host database
PL_DHashTableEnumerate(&mDB, HostDB_RemoveEntry, nsnull); PL_DHashTableEnumerate(&mDB, HostDB_RemoveEntry, nsnull);
@ -487,7 +512,7 @@ nsHostResolver::ResolveHost(const char *host,
nsRefPtr<nsHostRecord> result; nsRefPtr<nsHostRecord> result;
nsresult status = NS_OK, rv = NS_OK; nsresult status = NS_OK, rv = NS_OK;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mShutdown) if (mShutdown)
rv = NS_ERROR_NOT_INITIALIZED; rv = NS_ERROR_NOT_INITIALIZED;
@ -577,7 +602,7 @@ nsHostResolver::ResolveHost(const char *host,
// Move from low to med. // Move from low to med.
MoveQueue(he->rec, mMediumQ); MoveQueue(he->rec, mMediumQ);
he->rec->flags = flags; he->rec->flags = flags;
mIdleThreadCV.Notify(); PR_NotifyCondVar(mIdleThreadCV);
} }
} }
} }
@ -597,7 +622,7 @@ nsHostResolver::DetachCallback(const char *host,
{ {
nsRefPtr<nsHostRecord> rec; nsRefPtr<nsHostRecord> rec;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
nsHostKey key = { host, flags, af }; nsHostKey key = { host, flags, af };
nsHostDBEnt *he = static_cast<nsHostDBEnt *> nsHostDBEnt *he = static_cast<nsHostDBEnt *>
@ -628,7 +653,7 @@ nsHostResolver::ConditionallyCreateThread(nsHostRecord *rec)
{ {
if (mNumIdleThreads) { if (mNumIdleThreads) {
// wake up idle thread to process this lookup // wake up idle thread to process this lookup
mIdleThreadCV.Notify(); PR_NotifyCondVar(mIdleThreadCV);
} }
else if ((mThreadCount < HighThreadThreshold) || else if ((mThreadCount < HighThreadThreshold) ||
(IsHighPriority(rec->flags) && mThreadCount < MAX_RESOLVER_THREADS)) { (IsHighPriority(rec->flags) && mThreadCount < MAX_RESOLVER_THREADS)) {
@ -709,7 +734,7 @@ nsHostResolver::GetHostToLookup(nsHostRecord **result)
PRBool timedOut = PR_FALSE; PRBool timedOut = PR_FALSE;
PRIntervalTime epoch, now, timeout; PRIntervalTime epoch, now, timeout;
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
timeout = (mNumIdleThreads >= HighThreadThreshold) ? mShortIdleTimeout : mLongIdleTimeout; timeout = (mNumIdleThreads >= HighThreadThreshold) ? mShortIdleTimeout : mLongIdleTimeout;
epoch = PR_IntervalNow(); epoch = PR_IntervalNow();
@ -749,7 +774,7 @@ nsHostResolver::GetHostToLookup(nsHostRecord **result)
// (3) the thread has been idle for too long // (3) the thread has been idle for too long
mNumIdleThreads++; mNumIdleThreads++;
mIdleThreadCV.Wait(timeout); PR_WaitCondVar(mIdleThreadCV, timeout);
mNumIdleThreads--; mNumIdleThreads--;
now = PR_IntervalNow(); now = PR_IntervalNow();
@ -778,7 +803,7 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
PRCList cbs; PRCList cbs;
PR_INIT_CLIST(&cbs); PR_INIT_CLIST(&cbs);
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
// grab list of callbacks to notify // grab list of callbacks to notify
MoveCList(rec->callbacks, cbs); MoveCList(rec->callbacks, cbs);
@ -786,12 +811,11 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
// update record fields. We might have a rec->addr_info already if a // update record fields. We might have a rec->addr_info already if a
// previous lookup result expired and we're reresolving it.. // previous lookup result expired and we're reresolving it..
PRAddrInfo *old_addr_info; PRAddrInfo *old_addr_info;
{ PR_Lock(rec->addr_info_lock);
MutexAutoLock lock(*rec->addr_info_lock); old_addr_info = rec->addr_info;
old_addr_info = rec->addr_info; rec->addr_info = result;
rec->addr_info = result; rec->addr_info_gencnt++;
rec->addr_info_gencnt++; PR_Unlock(rec->addr_info_lock);
}
if (old_addr_info) if (old_addr_info)
PR_FreeAddrInfo(old_addr_info); PR_FreeAddrInfo(old_addr_info);
rec->expiration = NowInMinutes(); rec->expiration = NowInMinutes();

View File

@ -40,11 +40,10 @@
#include "nscore.h" #include "nscore.h"
#include "nsAtomicRefcnt.h" #include "nsAtomicRefcnt.h"
#include "prcvar.h"
#include "prclist.h" #include "prclist.h"
#include "prnetdb.h" #include "prnetdb.h"
#include "pldhash.h" #include "pldhash.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
class nsHostResolver; class nsHostResolver;
@ -86,8 +85,6 @@ struct nsHostKey
*/ */
class nsHostRecord : public PRCList, public nsHostKey class nsHostRecord : public PRCList, public nsHostKey
{ {
typedef mozilla::Mutex Mutex;
public: public:
NS_DECL_REFCOUNTED_THREADSAFE(nsHostRecord) NS_DECL_REFCOUNTED_THREADSAFE(nsHostRecord)
@ -111,7 +108,7 @@ public:
* the other threads just read it. therefore the resolver worker * the other threads just read it. therefore the resolver worker
* thread doesn't need to lock when reading |addr_info|. * thread doesn't need to lock when reading |addr_info|.
*/ */
Mutex *addr_info_lock; PRLock *addr_info_lock;
int addr_info_gencnt; /* generation count of |addr_info| */ int addr_info_gencnt; /* generation count of |addr_info| */
PRAddrInfo *addr_info; PRAddrInfo *addr_info;
PRNetAddr *addr; PRNetAddr *addr;
@ -174,9 +171,6 @@ public:
*/ */
class nsHostResolver class nsHostResolver
{ {
typedef mozilla::CondVar CondVar;
typedef mozilla::Mutex Mutex;
public: public:
/** /**
* host resolver instances are reference counted. * host resolver instances are reference counted.
@ -253,8 +247,8 @@ private:
PRUint32 mMaxCacheEntries; PRUint32 mMaxCacheEntries;
PRUint32 mMaxCacheLifetime; PRUint32 mMaxCacheLifetime;
Mutex mLock; PRLock *mLock;
CondVar mIdleThreadCV; PRCondVar *mIdleThreadCV; // non-null if idle thread
PRUint32 mNumIdleThreads; PRUint32 mNumIdleThreads;
PRUint32 mThreadCount; PRUint32 mThreadCount;
PRUint32 mActiveAnyThreadCount; PRUint32 mActiveAnyThreadCount;

View File

@ -55,6 +55,7 @@
#include "nsFtpConnectionThread.h" #include "nsFtpConnectionThread.h"
#include "netCore.h" #include "netCore.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsAutoLock.h"
#include "nsIFTPChannel.h" #include "nsIFTPChannel.h"
#include "nsIUploadChannel.h" #include "nsIUploadChannel.h"
#include "nsIProxyInfo.h" #include "nsIProxyInfo.h"

View File

@ -60,6 +60,7 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIPrompt.h" #include "nsIPrompt.h"
#include "nsITransport.h" #include "nsITransport.h"

View File

@ -47,6 +47,7 @@
#include "nsISocketTransport.h" #include "nsISocketTransport.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsString.h" #include "nsString.h"

View File

@ -38,8 +38,8 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsHttp.h" #include "nsHttp.h"
#include "nsAutoLock.h"
#include "pldhash.h" #include "pldhash.h"
#include "mozilla/Mutex.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "prbit.h" #include "prbit.h"
@ -60,8 +60,6 @@ enum {
}; };
#undef HTTP_ATOM #undef HTTP_ATOM
using namespace mozilla;
// we keep a linked list of atoms allocated on the heap for easy clean up when // we keep a linked list of atoms allocated on the heap for easy clean up when
// the atom table is destroyed. The structure and value string are allocated // the atom table is destroyed. The structure and value string are allocated
// as one contiguous block. // as one contiguous block.
@ -73,7 +71,7 @@ struct HttpHeapAtom {
static struct PLDHashTable sAtomTable = {0}; static struct PLDHashTable sAtomTable = {0};
static struct HttpHeapAtom *sHeapAtoms = nsnull; static struct HttpHeapAtom *sHeapAtoms = nsnull;
static Mutex *sLock = nsnull; static PRLock *sLock = nsnull;
HttpHeapAtom * HttpHeapAtom *
NewHeapAtom(const char *value) { NewHeapAtom(const char *value) {
@ -131,7 +129,9 @@ nsHttp::CreateAtomTable()
NS_ASSERTION(!sAtomTable.ops, "atom table already initialized"); NS_ASSERTION(!sAtomTable.ops, "atom table already initialized");
if (!sLock) { if (!sLock) {
sLock = new Mutex("nsHttp.sLock"); sLock = nsAutoLock::NewLock("nsHttp::sLock");
if (!sLock)
return NS_ERROR_OUT_OF_MEMORY;
} }
// The capacity for this table is initialized to a value greater than the // The capacity for this table is initialized to a value greater than the
@ -179,7 +179,7 @@ nsHttp::DestroyAtomTable()
} }
if (sLock) { if (sLock) {
delete sLock; nsAutoLock::DestroyLock(sLock);
sLock = nsnull; sLock = nsnull;
} }
} }
@ -193,7 +193,7 @@ nsHttp::ResolveAtom(const char *str)
if (!str || !sAtomTable.ops) if (!str || !sAtomTable.ops)
return atom; return atom;
MutexAutoLock lock(*sLock); nsAutoLock lock(sLock);
PLDHashEntryStub *stub = reinterpret_cast<PLDHashEntryStub *> PLDHashEntryStub *stub = reinterpret_cast<PLDHashEntryStub *>
(PL_DHashTableOperate(&sAtomTable, str, PL_DHASH_ADD)); (PL_DHashTableOperate(&sAtomTable, str, PL_DHASH_ADD));

View File

@ -38,11 +38,10 @@
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsAutoLock.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
using namespace mozilla;
class nsHttpActivityEvent : public nsRunnable class nsHttpActivityEvent : public nsRunnable
{ {
public: public:
@ -92,12 +91,14 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsHttpActivityDistributor,
nsIHttpActivityObserver) nsIHttpActivityObserver)
nsHttpActivityDistributor::nsHttpActivityDistributor() nsHttpActivityDistributor::nsHttpActivityDistributor()
: mLock("nsHttpActivityDistributor.mLock") : mLock(nsnull)
{ {
} }
nsHttpActivityDistributor::~nsHttpActivityDistributor() nsHttpActivityDistributor::~nsHttpActivityDistributor()
{ {
if (mLock)
nsAutoLock::DestroyLock(mLock);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -110,7 +111,7 @@ nsHttpActivityDistributor::ObserveActivity(nsISupports *aHttpChannel,
{ {
nsRefPtr<nsIRunnable> event; nsRefPtr<nsIRunnable> event;
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mObservers.Count()) if (!mObservers.Count())
return NS_OK; return NS_OK;
@ -128,7 +129,7 @@ NS_IMETHODIMP
nsHttpActivityDistributor::GetIsActive(PRBool *isActive) nsHttpActivityDistributor::GetIsActive(PRBool *isActive)
{ {
NS_ENSURE_ARG_POINTER(isActive); NS_ENSURE_ARG_POINTER(isActive);
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
*isActive = !!mObservers.Count(); *isActive = !!mObservers.Count();
return NS_OK; return NS_OK;
} }
@ -136,7 +137,7 @@ nsHttpActivityDistributor::GetIsActive(PRBool *isActive)
NS_IMETHODIMP NS_IMETHODIMP
nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver *aObserver) nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver *aObserver)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mObservers.AppendObject(aObserver)) if (!mObservers.AppendObject(aObserver))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -147,10 +148,22 @@ nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver *aObserver)
NS_IMETHODIMP NS_IMETHODIMP
nsHttpActivityDistributor::RemoveObserver(nsIHttpActivityObserver *aObserver) nsHttpActivityDistributor::RemoveObserver(nsIHttpActivityObserver *aObserver)
{ {
MutexAutoLock lock(mLock); nsAutoLock lock(mLock);
if (!mObservers.RemoveObject(aObserver)) if (!mObservers.RemoveObject(aObserver))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return NS_OK; return NS_OK;
} }
nsresult
nsHttpActivityDistributor::Init()
{
NS_ENSURE_TRUE(!mLock, NS_ERROR_ALREADY_INITIALIZED);
mLock = nsAutoLock::NewLock("nsHttpActivityDistributor::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}

View File

@ -39,7 +39,7 @@
#include "nsIHttpActivityObserver.h" #include "nsIHttpActivityObserver.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "mozilla/Mutex.h" #include "prlock.h"
class nsHttpActivityDistributor : public nsIHttpActivityDistributor class nsHttpActivityDistributor : public nsIHttpActivityDistributor
{ {
@ -50,10 +50,11 @@ public:
nsHttpActivityDistributor(); nsHttpActivityDistributor();
virtual ~nsHttpActivityDistributor(); virtual ~nsHttpActivityDistributor();
nsresult Init();
protected: protected:
nsCOMArray<nsIHttpActivityObserver> mObservers; nsCOMArray<nsIHttpActivityObserver> mObservers;
mozilla::Mutex mLock; PRLock *mLock;
}; };
#endif // nsHttpActivityDistributor_h__ #endif // nsHttpActivityDistributor_h__

View File

@ -50,6 +50,7 @@
#include "nsStringStream.h" #include "nsStringStream.h"
#include "netCore.h" #include "netCore.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsAutoLock.h"
#include "prmem.h" #include "prmem.h"
#ifdef DEBUG #ifdef DEBUG

View File

@ -45,6 +45,7 @@
#include "nsAHttpTransaction.h" #include "nsAHttpTransaction.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "prlock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"

View File

@ -40,6 +40,7 @@
#include "nsHttpConnection.h" #include "nsHttpConnection.h"
#include "nsHttpPipeline.h" #include "nsHttpPipeline.h"
#include "nsHttpHandler.h" #include "nsHttpHandler.h"
#include "nsAutoLock.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -48,8 +49,6 @@
#include "nsIObserverService.h" #include "nsIObserverService.h"
using namespace mozilla;
// defined by the socket transport service while active // defined by the socket transport service while active
extern PRThread *gSocketThread; extern PRThread *gSocketThread;
@ -81,7 +80,7 @@ InsertTransactionSorted(nsTArray<nsHttpTransaction*> &pendingQ, nsHttpTransactio
nsHttpConnectionMgr::nsHttpConnectionMgr() nsHttpConnectionMgr::nsHttpConnectionMgr()
: mRef(0) : mRef(0)
, mMonitor("nsHttpConnectionMgr.mMonitor") , mMonitor(nsAutoMonitor::NewMonitor("nsHttpConnectionMgr"))
, mMaxConns(0) , mMaxConns(0)
, mMaxConnsPerHost(0) , mMaxConnsPerHost(0)
, mMaxConnsPerProxy(0) , mMaxConnsPerProxy(0)
@ -98,6 +97,9 @@ nsHttpConnectionMgr::nsHttpConnectionMgr()
nsHttpConnectionMgr::~nsHttpConnectionMgr() nsHttpConnectionMgr::~nsHttpConnectionMgr()
{ {
LOG(("Destroying nsHttpConnectionMgr @%x\n", this)); LOG(("Destroying nsHttpConnectionMgr @%x\n", this));
if (mMonitor)
nsAutoMonitor::DestroyMonitor(mMonitor);
} }
nsresult nsresult
@ -115,7 +117,7 @@ nsHttpConnectionMgr::EnsureSocketThreadTargetIfOnline()
} }
} }
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
// do nothing if already initialized or if we've shut down // do nothing if already initialized or if we've shut down
if (mSocketThreadTarget || mIsShuttingDown) if (mSocketThreadTarget || mIsShuttingDown)
@ -138,7 +140,7 @@ nsHttpConnectionMgr::Init(PRUint16 maxConns,
LOG(("nsHttpConnectionMgr::Init\n")); LOG(("nsHttpConnectionMgr::Init\n"));
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mMaxConns = maxConns; mMaxConns = maxConns;
mMaxConnsPerHost = maxConnsPerHost; mMaxConnsPerHost = maxConnsPerHost;
@ -159,7 +161,7 @@ nsHttpConnectionMgr::Shutdown()
{ {
LOG(("nsHttpConnectionMgr::Shutdown\n")); LOG(("nsHttpConnectionMgr::Shutdown\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
// do nothing if already shutdown // do nothing if already shutdown
if (!mSocketThreadTarget) if (!mSocketThreadTarget)
@ -192,7 +194,7 @@ nsHttpConnectionMgr::PostEvent(nsConnEventHandler handler, PRInt32 iparam, void
// care of initializing the socket thread target if that's the case. // care of initializing the socket thread target if that's the case.
EnsureSocketThreadTargetIfOnline(); EnsureSocketThreadTargetIfOnline();
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
nsresult rv; nsresult rv;
if (!mSocketThreadTarget) { if (!mSocketThreadTarget) {
@ -317,7 +319,7 @@ nsHttpConnectionMgr::GetSocketThreadTarget(nsIEventTarget **target)
// care of initializing the socket thread target if that's the case. // care of initializing the socket thread target if that's the case.
EnsureSocketThreadTargetIfOnline(); EnsureSocketThreadTargetIfOnline();
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
NS_IF_ADDREF(*target = mSocketThreadTarget); NS_IF_ADDREF(*target = mSocketThreadTarget);
return NS_OK; return NS_OK;
} }
@ -875,7 +877,7 @@ nsHttpConnectionMgr::OnMsgShutdown(PRInt32, void *)
mCT.Reset(ShutdownPassCB, this); mCT.Reset(ShutdownPassCB, this);
// signal shutdown complete // signal shutdown complete
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Notify(); mon.Notify();
} }

View File

@ -46,7 +46,7 @@
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "mozilla/Monitor.h" #include "prmon.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsITimer.h" #include "nsITimer.h"
@ -187,7 +187,7 @@ private:
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
PRInt32 mRef; PRInt32 mRef;
mozilla::Monitor mMonitor; PRMonitor *mMonitor;
nsCOMPtr<nsIEventTarget> mSocketThreadTarget; nsCOMPtr<nsIEventTarget> mSocketThreadTarget;
// connection limits // connection limits

View File

@ -69,6 +69,7 @@
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsAutoLock.h"
#include "prprf.h" #include "prprf.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsQuickSort.h" #include "nsQuickSort.h"

View File

@ -47,6 +47,7 @@
#include "nsIPipe.h" #include "nsIPipe.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsAutoLock.h"
#ifdef DEBUG #ifdef DEBUG
#include "prthread.h" #include "prthread.h"

View File

@ -53,6 +53,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "nsIOService.h" #include "nsIOService.h"
#include "nsAutoLock.h"
#include "nsAtomicRefcnt.h" #include "nsAtomicRefcnt.h"
#include "nsISeekableStream.h" #include "nsISeekableStream.h"

View File

@ -43,6 +43,7 @@
#endif #endif
#include "nsResProtocolHandler.h" #include "nsResProtocolHandler.h"
#include "nsAutoLock.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"

View File

@ -43,6 +43,7 @@
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsXPCOMCID.h" #include "nsXPCOMCID.h"
#include "nsAutoLock.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsWifiMonitor.h" #include "nsWifiMonitor.h"
@ -52,8 +53,6 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
using namespace mozilla;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
PRLogModuleInfo *gWifiMonitorLog; PRLogModuleInfo *gWifiMonitorLog;
#endif #endif
@ -65,12 +64,13 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsWifiMonitor,
nsWifiMonitor::nsWifiMonitor() nsWifiMonitor::nsWifiMonitor()
: mKeepGoing(PR_TRUE) : mKeepGoing(PR_TRUE)
, mMonitor("nsWifiMonitor.mMonitor")
{ {
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
gWifiMonitorLog = PR_NewLogModule("WifiMonitor"); gWifiMonitorLog = PR_NewLogModule("WifiMonitor");
#endif #endif
mMonitor = nsAutoMonitor::NewMonitor("nsWifiMonitor");
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService(); nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
if (obsSvc) if (obsSvc)
obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE); obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE);
@ -80,6 +80,8 @@ nsWifiMonitor::nsWifiMonitor()
nsWifiMonitor::~nsWifiMonitor() nsWifiMonitor::~nsWifiMonitor()
{ {
if (mMonitor)
nsAutoMonitor::DestroyMonitor(mMonitor);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -90,7 +92,7 @@ nsWifiMonitor::Observe(nsISupports *subject, const char *topic,
LOG(("Shutting down\n")); LOG(("Shutting down\n"));
mKeepGoing = PR_FALSE; mKeepGoing = PR_FALSE;
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Notify(); mon.Notify();
} }
return NS_OK; return NS_OK;
@ -109,7 +111,7 @@ NS_IMETHODIMP nsWifiMonitor::StartWatching(nsIWifiListener *aListener)
return rv; return rv;
} }
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mKeepGoing = PR_TRUE; mKeepGoing = PR_TRUE;
@ -127,7 +129,7 @@ NS_IMETHODIMP nsWifiMonitor::StopWatching(nsIWifiListener *aListener)
LOG(("removing listener\n")); LOG(("removing listener\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) { for (PRUint32 i = 0; i < mListeners.Length(); i++) {

View File

@ -40,11 +40,12 @@
#include "nsIWifiMonitor.h" #include "nsIWifiMonitor.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsAutoLock.h"
#include "nsIThread.h" #include "nsIThread.h"
#include "nsIRunnable.h" #include "nsIRunnable.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsIWifiMonitor.h" #include "nsIWifiMonitor.h"
#include "mozilla/Monitor.h" #include "prmon.h"
#include "prlog.h" #include "prlog.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsTArray.h" #include "nsTArray.h"
@ -97,7 +98,7 @@ class nsWifiMonitor : nsIRunnable, nsIWifiMonitor, nsIObserver
nsTArray<nsWifiListener> mListeners; nsTArray<nsWifiListener> mListeners;
mozilla::Monitor mMonitor; PRMonitor* mMonitor;
}; };

View File

@ -53,8 +53,6 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsIMutableArray.h" #include "nsIMutableArray.h"
using namespace mozilla;
// defined in osx_corewlan.mm // defined in osx_corewlan.mm
// basically relaces accesspoints in the passed reference // basically relaces accesspoints in the passed reference
// it lives in a separate file so that we can use objective c. // it lives in a separate file so that we can use objective c.
@ -77,7 +75,7 @@ nsWifiMonitor::DoScanWithCoreWLAN()
nsCOMArray<nsIWifiListener> currentListeners; nsCOMArray<nsIWifiListener> currentListeners;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) { for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) { if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -127,7 +125,7 @@ nsWifiMonitor::DoScanWithCoreWLAN()
// wait for some reasonable amount of time. pref? // wait for some reasonable amount of time. pref?
LOG(("waiting on monitor\n")); LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60)); mon.Wait(PR_SecondsToInterval(60));
} }
while (mKeepGoing); while (mKeepGoing);
@ -212,7 +210,7 @@ nsWifiMonitor::DoScanOld()
nsCOMArray<nsIWifiListener> currentListeners; nsCOMArray<nsIWifiListener> currentListeners;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) { for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) { if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -263,7 +261,7 @@ nsWifiMonitor::DoScanOld()
// wait for some reasonable amount of time. pref? // wait for some reasonable amount of time. pref?
LOG(("waiting on monitor\n")); LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60)); mon.Wait(PR_SecondsToInterval(60));
} }
while (mKeepGoing); while (mKeepGoing);

View File

@ -41,6 +41,7 @@
#include "dlfcn.h" #include "dlfcn.h"
#include "nsAutoPtr.h"
#include "nsWifiMonitor.h" #include "nsWifiMonitor.h"
#include "nsWifiAccessPoint.h" #include "nsWifiAccessPoint.h"
@ -49,7 +50,7 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsIMutableArray.h" #include "nsIMutableArray.h"
using namespace mozilla;
typedef int (*iw_open_t)(void); typedef int (*iw_open_t)(void);
@ -170,7 +171,7 @@ nsWifiMonitor::DoScan()
nsCOMArray<nsIWifiListener> currentListeners; nsCOMArray<nsIWifiListener> currentListeners;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) { for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) { if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -220,7 +221,7 @@ nsWifiMonitor::DoScan()
LOG(("waiting on monitor\n")); LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60)); mon.Wait(PR_SecondsToInterval(60));
} }

View File

@ -46,6 +46,7 @@
#include "winioctl.h" #include "winioctl.h"
#include "stdlib.h" #include "stdlib.h"
#include "nsAutoPtr.h"
#include "nsWifiMonitor.h" #include "nsWifiMonitor.h"
#include "nsWifiAccessPoint.h" #include "nsWifiAccessPoint.h"
@ -54,8 +55,6 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsIMutableArray.h" #include "nsIMutableArray.h"
using namespace mozilla;
nsresult nsresult
nsWifiMonitor::DoScan() nsWifiMonitor::DoScan()
{ {
@ -154,7 +153,7 @@ nsWifiMonitor::DoScan()
nsCOMArray<nsIWifiListener> currentListeners; nsCOMArray<nsIWifiListener> currentListeners;
{ {
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) { for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) { if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -202,7 +201,7 @@ nsWifiMonitor::DoScan()
// wait for some reasonable amount of time. pref? // wait for some reasonable amount of time. pref?
LOG(("waiting on monitor\n")); LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor); nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60)); mon.Wait(PR_SecondsToInterval(60));
} }
while (mKeepGoing); while (mKeepGoing);

View File

@ -54,6 +54,7 @@
#include "prenv.h" #include "prenv.h"
#include "prlock.h" #include "prlock.h"
#include "prcvar.h" #include "prcvar.h"
#include "nsAutoLock.h"
#include "nsParserCIID.h" #include "nsParserCIID.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -72,10 +73,6 @@
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "nsMimeTypes.h" #include "nsMimeTypes.h"
#include "nsViewSourceHTML.h" #include "nsViewSourceHTML.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
using namespace mozilla;
#define NS_PARSER_FLAG_PARSER_ENABLED 0x00000002 #define NS_PARSER_FLAG_PARSER_ENABLED 0x00000002
#define NS_PARSER_FLAG_OBSERVERS_ENABLED 0x00000004 #define NS_PARSER_FLAG_OBSERVERS_ENABLED 0x00000004
@ -201,8 +198,8 @@ private:
class nsSpeculativeScriptThread : public nsIRunnable { class nsSpeculativeScriptThread : public nsIRunnable {
public: public:
nsSpeculativeScriptThread() nsSpeculativeScriptThread()
: mLock("nsSpeculativeScriptThread.mLock"), : mLock(nsAutoLock::DestroyLock),
mCVar(mLock, "nsSpeculativeScriptThread.mCVar"), mCVar(PR_DestroyCondVar),
mKeepParsing(PR_FALSE), mKeepParsing(PR_FALSE),
mCurrentlyParsing(PR_FALSE), mCurrentlyParsing(PR_FALSE),
mNumConsumed(0), mNumConsumed(0),
@ -271,8 +268,8 @@ private:
// The following members are shared across the main thread and the // The following members are shared across the main thread and the
// speculatively parsing thread. // speculatively parsing thread.
Mutex mLock; Holder<PRLock> mLock;
CondVar mCVar; Holder<PRCondVar> mCVar;
volatile PRBool mKeepParsing; volatile PRBool mKeepParsing;
volatile PRBool mCurrentlyParsing; volatile PRBool mCurrentlyParsing;
@ -415,10 +412,10 @@ nsSpeculativeScriptThread::Run()
} }
{ {
MutexAutoLock al(mLock); nsAutoLock al(mLock.get());
mCurrentlyParsing = PR_FALSE; mCurrentlyParsing = PR_FALSE;
mCVar.Notify(); PR_NotifyCondVar(mCVar.get());
} }
return NS_OK; return NS_OK;
} }
@ -445,7 +442,17 @@ nsSpeculativeScriptThread::StartParsing(nsParser *aParser)
nsAutoString toScan; nsAutoString toScan;
CParserContext *context = aParser->PeekContext(); CParserContext *context = aParser->PeekContext();
if (!mTokenizer) { if (!mLock.get()) {
mLock = nsAutoLock::NewLock("nsSpeculativeScriptThread::mLock");
if (!mLock.get()) {
return NS_ERROR_OUT_OF_MEMORY;
}
mCVar = PR_NewCondVar(mLock.get());
if (!mCVar.get()) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!mPreloadedURIs.Init(15)) { if (!mPreloadedURIs.Init(15)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -512,12 +519,17 @@ nsSpeculativeScriptThread::StopParsing(PRBool /*aFromDocWrite*/)
{ {
NS_ASSERTION(NS_IsMainThread(), "Can't stop parsing from another thread"); NS_ASSERTION(NS_IsMainThread(), "Can't stop parsing from another thread");
if (!mLock.get()) {
// If we bailed early out of StartParsing, don't do anything.
return;
}
{ {
MutexAutoLock al(mLock); nsAutoLock al(mLock.get());
mKeepParsing = PR_FALSE; mKeepParsing = PR_FALSE;
if (mCurrentlyParsing) { if (mCurrentlyParsing) {
mCVar.Wait(); PR_WaitCondVar(mCVar.get(), PR_INTERVAL_NO_TIMEOUT);
NS_ASSERTION(!mCurrentlyParsing, "Didn't actually stop parsing?"); NS_ASSERTION(!mCurrentlyParsing, "Didn't actually stop parsing?");
} }
} }

View File

@ -85,8 +85,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsAutoLock.h"
using namespace mozilla;
#define SECURITY_STRING_BUNDLE_URL "chrome://pipnss/locale/security.properties" #define SECURITY_STRING_BUNDLE_URL "chrome://pipnss/locale/security.properties"
@ -160,8 +159,7 @@ class nsAutoAtomic {
#endif #endif
nsSecureBrowserUIImpl::nsSecureBrowserUIImpl() nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
: mMonitor("nsSecureBrowserUIImpl.mMonitor") : mNotifiedSecurityState(lis_no_security)
, mNotifiedSecurityState(lis_no_security)
, mNotifiedToplevelIsEV(PR_FALSE) , mNotifiedToplevelIsEV(PR_FALSE)
, mNewToplevelSecurityState(STATE_IS_INSECURE) , mNewToplevelSecurityState(STATE_IS_INSECURE)
, mNewToplevelIsEV(PR_FALSE) , mNewToplevelIsEV(PR_FALSE)
@ -175,6 +173,7 @@ nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
, mOnStateLocationChangeReentranceDetection(0) , mOnStateLocationChangeReentranceDetection(0)
#endif #endif
{ {
mMonitor = nsAutoMonitor::NewMonitor("security.secureBrowserUIImplMonitor");
mTransferringRequests.ops = nsnull; mTransferringRequests.ops = nsnull;
ResetStateTracking(); ResetStateTracking();
@ -190,6 +189,8 @@ nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
PL_DHashTableFinish(&mTransferringRequests); PL_DHashTableFinish(&mTransferringRequests);
mTransferringRequests.ops = nsnull; mTransferringRequests.ops = nsnull;
} }
if (mMonitor)
nsAutoMonitor::DestroyMonitor(mMonitor);
} }
NS_IMPL_THREADSAFE_ISUPPORTS6(nsSecureBrowserUIImpl, NS_IMPL_THREADSAFE_ISUPPORTS6(nsSecureBrowserUIImpl,
@ -277,7 +278,7 @@ nsSecureBrowserUIImpl::Init(nsIDOMWindow *aWindow)
NS_IMETHODIMP NS_IMETHODIMP
nsSecureBrowserUIImpl::GetState(PRUint32* aState) nsSecureBrowserUIImpl::GetState(PRUint32* aState)
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
return MapInternalToExternalState(aState, mNotifiedSecurityState, mNotifiedToplevelIsEV); return MapInternalToExternalState(aState, mNotifiedSecurityState, mNotifiedToplevelIsEV);
} }
@ -341,7 +342,7 @@ nsSecureBrowserUIImpl::GetTooltipText(nsAString& aText)
nsXPIDLString tooltip; nsXPIDLString tooltip;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
state = mNotifiedSecurityState; state = mNotifiedSecurityState;
tooltip = mInfoTooltip; tooltip = mInfoTooltip;
} }
@ -460,7 +461,7 @@ nsSecureBrowserUIImpl::Notify(nsIDOMHTMLFormElement* aDOMForm,
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -496,7 +497,7 @@ nsSecureBrowserUIImpl::OnProgressChange(nsIWebProgress* aWebProgress,
void nsSecureBrowserUIImpl::ResetStateTracking() void nsSecureBrowserUIImpl::ResetStateTracking()
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
mInfoTooltip.Truncate(); mInfoTooltip.Truncate();
mDocumentRequestsInProgress = 0; mDocumentRequestsInProgress = 0;
@ -558,7 +559,7 @@ nsSecureBrowserUIImpl::EvaluateAndUpdateSecurityState(nsIRequest* aRequest, nsIS
// see code that is directly above // see code that is directly above
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
mNewToplevelSecurityStateKnown = PR_TRUE; mNewToplevelSecurityStateKnown = PR_TRUE;
mNewToplevelSecurityState = temp_NewToplevelSecurityState; mNewToplevelSecurityState = temp_NewToplevelSecurityState;
mNewToplevelIsEV = temp_NewToplevelIsEV; mNewToplevelIsEV = temp_NewToplevelIsEV;
@ -591,7 +592,7 @@ nsSecureBrowserUIImpl::UpdateSubrequestMembers(nsISupports *securityInfo)
PRUint32 reqState = GetSecurityStateFromSecurityInfo(securityInfo); PRUint32 reqState = GetSecurityStateFromSecurityInfo(securityInfo);
// the code above this line should run without a lock // the code above this line should run without a lock
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
if (reqState & STATE_IS_SECURE) { if (reqState & STATE_IS_SECURE) {
if (reqState & STATE_SECURE_LOW || reqState & STATE_SECURE_MED) { if (reqState & STATE_SECURE_LOW || reqState & STATE_SECURE_MED) {
@ -724,7 +725,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
nsCOMPtr<nsINetUtil> ioService; nsCOMPtr<nsINetUtil> ioService;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
isViewSource = mIsViewSource; isViewSource = mIsViewSource;
@ -736,7 +737,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
ioService = do_GetService(NS_IOSERVICE_CONTRACTID); ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
if (ioService) if (ioService)
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
mIOService = ioService; mIOService = ioService;
} }
} }
@ -1013,7 +1014,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
// The listing of a request in mTransferringRequests // The listing of a request in mTransferringRequests
// means, there has already been data transfered. // means, there has already been data transfered.
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_ADD); PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_ADD);
return NS_OK; return NS_OK;
@ -1025,8 +1026,8 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
&& &&
aProgressStateFlags & STATE_IS_REQUEST) aProgressStateFlags & STATE_IS_REQUEST)
{ {
{ /* scope for the MonitorAutoEnter */ { /* scope for the nsAutoMonitor */
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
PLDHashEntryHdr *entry = PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_LOOKUP); PLDHashEntryHdr *entry = PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_LOOKUP);
if (PL_DHASH_ENTRY_IS_BUSY(entry)) if (PL_DHASH_ENTRY_IS_BUSY(entry))
{ {
@ -1084,7 +1085,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
PRInt32 newSubNo = 0; PRInt32 newSubNo = 0;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
inProgress = (mDocumentRequestsInProgress!=0); inProgress = (mDocumentRequestsInProgress!=0);
if (allowSecurityStateChange && !inProgress) if (allowSecurityStateChange && !inProgress)
@ -1154,7 +1155,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
} }
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
if (allowSecurityStateChange && !inProgress) if (allowSecurityStateChange && !inProgress)
{ {
@ -1190,7 +1191,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
nsCOMPtr<nsISecurityEventSink> temp_ToplevelEventSink; nsCOMPtr<nsISecurityEventSink> temp_ToplevelEventSink;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
temp_DocumentRequestsInProgress = mDocumentRequestsInProgress; temp_DocumentRequestsInProgress = mDocumentRequestsInProgress;
if (allowSecurityStateChange) if (allowSecurityStateChange)
{ {
@ -1218,7 +1219,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
} }
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
if (allowSecurityStateChange) if (allowSecurityStateChange)
{ {
mToplevelEventSink = temp_ToplevelEventSink; mToplevelEventSink = temp_ToplevelEventSink;
@ -1263,7 +1264,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
PRBool temp_NewToplevelSecurityStateKnown; PRBool temp_NewToplevelSecurityStateKnown;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
temp_NewToplevelSecurityStateKnown = mNewToplevelSecurityStateKnown; temp_NewToplevelSecurityStateKnown = mNewToplevelSecurityStateKnown;
} }
@ -1309,7 +1310,7 @@ nsresult nsSecureBrowserUIImpl::UpdateSecurityState(nsIRequest* aRequest,
// returns true if our overall state has changed and we must send out notifications // returns true if our overall state has changed and we must send out notifications
PRBool nsSecureBrowserUIImpl::UpdateMyFlags(PRBool &showWarning, lockIconState &warnSecurityState) PRBool nsSecureBrowserUIImpl::UpdateMyFlags(PRBool &showWarning, lockIconState &warnSecurityState)
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
PRBool mustTellTheWorld = PR_FALSE; PRBool mustTellTheWorld = PR_FALSE;
lockIconState newSecurityState; lockIconState newSecurityState;
@ -1459,7 +1460,7 @@ nsresult nsSecureBrowserUIImpl::TellTheWorld(PRBool showWarning,
PRBool temp_NotifiedToplevelIsEV; PRBool temp_NotifiedToplevelIsEV;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
temp_ToplevelEventSink = mToplevelEventSink; temp_ToplevelEventSink = mToplevelEventSink;
temp_NotifiedSecurityState = mNotifiedSecurityState; temp_NotifiedSecurityState = mNotifiedSecurityState;
temp_NotifiedToplevelIsEV = mNotifiedToplevelIsEV; temp_NotifiedToplevelIsEV = mNotifiedToplevelIsEV;
@ -1546,7 +1547,7 @@ nsSecureBrowserUIImpl::OnLocationChange(nsIWebProgress* aWebProgress,
} }
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
if (updateIsViewSource) { if (updateIsViewSource) {
mIsViewSource = temp_IsViewSource; mIsViewSource = temp_IsViewSource;
} }
@ -1594,7 +1595,7 @@ nsSecureBrowserUIImpl::OnLocationChange(nsIWebProgress* aWebProgress,
PRBool temp_NewToplevelSecurityStateKnown; PRBool temp_NewToplevelSecurityStateKnown;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
temp_NewToplevelSecurityStateKnown = mNewToplevelSecurityStateKnown; temp_NewToplevelSecurityStateKnown = mNewToplevelSecurityStateKnown;
} }
@ -1645,7 +1646,7 @@ nsSecureBrowserUIImpl::GetSSLStatus(nsISupports** _result)
{ {
NS_ENSURE_ARG_POINTER(_result); NS_ENSURE_ARG_POINTER(_result);
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
switch (mNotifiedSecurityState) switch (mNotifiedSecurityState)
{ {
@ -1697,7 +1698,7 @@ nsSecureBrowserUIImpl::GetBundleString(const PRUnichar* name,
nsCOMPtr<nsIStringBundle> temp_StringBundle; nsCOMPtr<nsIStringBundle> temp_StringBundle;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
temp_StringBundle = mStringBundle; temp_StringBundle = mStringBundle;
} }
@ -1841,7 +1842,7 @@ ConfirmEnteringSecure()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -1864,7 +1865,7 @@ ConfirmEnteringWeak()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -1887,7 +1888,7 @@ ConfirmLeavingSecure()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -1910,7 +1911,7 @@ ConfirmMixedMode()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -1940,7 +1941,7 @@ ConfirmPostToInsecure()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }
@ -1972,7 +1973,7 @@ ConfirmPostToInsecureFromSecure()
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
{ {
MonitorAutoEnter lock(mMonitor); nsAutoMonitor lock(mMonitor);
window = do_QueryReferent(mWindow); window = do_QueryReferent(mWindow);
NS_ASSERTION(window, "Window has gone away?!"); NS_ASSERTION(window, "Window has gone away?!");
} }

View File

@ -42,7 +42,6 @@
#ifndef nsSecureBrowserUIImpl_h_ #ifndef nsSecureBrowserUIImpl_h_
#define nsSecureBrowserUIImpl_h_ #define nsSecureBrowserUIImpl_h_
#include "mozilla/Monitor.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsString.h" #include "nsString.h"
@ -61,6 +60,7 @@
#include "nsISSLStatusProvider.h" #include "nsISSLStatusProvider.h"
#include "nsIAssociatedContentSecurity.h" #include "nsIAssociatedContentSecurity.h"
#include "pldhash.h" #include "pldhash.h"
#include "prmon.h"
#include "nsINetUtil.h" #include "nsINetUtil.h"
class nsITransportSecurityInfo; class nsITransportSecurityInfo;
@ -97,7 +97,7 @@ public:
nsIArray* invalidElements) { return NS_OK; }; nsIArray* invalidElements) { return NS_OK; };
protected: protected:
mozilla::Monitor mMonitor; PRMonitor *mMonitor;
nsWeakPtr mWindow; nsWeakPtr mWindow;
nsCOMPtr<nsINetUtil> mIOService; nsCOMPtr<nsINetUtil> mIOService;

View File

@ -52,6 +52,7 @@
#include "nsPromiseFlatString.h" #include "nsPromiseFlatString.h"
#include "nsProxiedService.h" #include "nsProxiedService.h"
#include "nsStringBuffer.h" #include "nsStringBuffer.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nspr.h" #include "nspr.h"
#include "pk11pub.h" #include "pk11pub.h"
@ -62,8 +63,6 @@
#include "nsNSSCleaner.h" #include "nsNSSCleaner.h"
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate) NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
using namespace mozilla;
static const char kCertOverrideFileName[] = "cert_override.txt"; static const char kCertOverrideFileName[] = "cert_override.txt";
void void
@ -120,12 +119,14 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsCertOverrideService,
nsISupportsWeakReference) nsISupportsWeakReference)
nsCertOverrideService::nsCertOverrideService() nsCertOverrideService::nsCertOverrideService()
: monitor("nsCertOverrideService.monitor")
{ {
monitor = nsAutoMonitor::NewMonitor("security.certOverrideServiceMonitor");
} }
nsCertOverrideService::~nsCertOverrideService() nsCertOverrideService::~nsCertOverrideService()
{ {
if (monitor)
nsAutoMonitor::DestroyMonitor(monitor);
} }
nsresult nsresult
@ -179,7 +180,7 @@ nsCertOverrideService::Observe(nsISupports *aSubject,
// The profile is about to change, // The profile is about to change,
// or is going away because the application is shutting down. // or is going away because the application is shutting down.
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) { if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
RemoveAllFromMemory(); RemoveAllFromMemory();
@ -196,7 +197,7 @@ nsCertOverrideService::Observe(nsISupports *aSubject,
// Now read from the new profile location. // Now read from the new profile location.
// we also need to update the cached file location // we also need to update the cached file location
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mSettingsFile)); nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mSettingsFile));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
@ -212,7 +213,7 @@ nsCertOverrideService::Observe(nsISupports *aSubject,
void void
nsCertOverrideService::RemoveAllFromMemory() nsCertOverrideService::RemoveAllFromMemory()
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
mSettingsTable.Clear(); mSettingsTable.Clear();
} }
@ -232,7 +233,7 @@ void
nsCertOverrideService::RemoveAllTemporaryOverrides() nsCertOverrideService::RemoveAllTemporaryOverrides()
{ {
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
mSettingsTable.EnumerateEntries(RemoveTemporariesCallback, nsnull); mSettingsTable.EnumerateEntries(RemoveTemporariesCallback, nsnull);
// no need to write, as temporaries are never written to disk // no need to write, as temporaries are never written to disk
} }
@ -241,7 +242,7 @@ nsCertOverrideService::RemoveAllTemporaryOverrides()
nsresult nsresult
nsCertOverrideService::Read() nsCertOverrideService::Read()
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsresult rv; nsresult rv;
nsCOMPtr<nsIInputStream> fileInputStream; nsCOMPtr<nsIInputStream> fileInputStream;
@ -360,7 +361,7 @@ WriteEntryCallback(nsCertOverrideEntry *aEntry,
nsresult nsresult
nsCertOverrideService::Write() nsCertOverrideService::Write()
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
if (!mSettingsFile) { if (!mSettingsFile) {
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
@ -554,7 +555,7 @@ nsCertOverrideService::RememberValidityOverride(const nsACString & aHostName, PR
} }
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
AddEntryToList(aHostName, aPort, AddEntryToList(aHostName, aPort,
aTemporary ? aCert : nsnull, aTemporary ? aCert : nsnull,
// keep a reference to the cert for temporary overrides // keep a reference to the cert for temporary overrides
@ -593,7 +594,7 @@ nsCertOverrideService::HasMatchingOverride(const nsACString & aHostName, PRInt32
nsCertOverride settings; nsCertOverride settings;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsCertOverrideEntry *entry = mSettingsTable.GetEntry(hostPort.get()); nsCertOverrideEntry *entry = mSettingsTable.GetEntry(hostPort.get());
if (!entry) if (!entry)
@ -640,7 +641,7 @@ nsCertOverrideService::GetValidityOverride(const nsACString & aHostName, PRInt32
nsCertOverride settings; nsCertOverride settings;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsCertOverrideEntry *entry = mSettingsTable.GetEntry(hostPort.get()); nsCertOverrideEntry *entry = mSettingsTable.GetEntry(hostPort.get());
if (entry) { if (entry) {
@ -672,7 +673,7 @@ nsCertOverrideService::AddEntryToList(const nsACString &aHostName, PRInt32 aPort
GetHostWithPort(aHostName, aPort, hostPort); GetHostWithPort(aHostName, aPort, hostPort);
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsCertOverrideEntry *entry = mSettingsTable.PutEntry(hostPort.get()); nsCertOverrideEntry *entry = mSettingsTable.PutEntry(hostPort.get());
if (!entry) { if (!entry) {
@ -707,7 +708,7 @@ nsCertOverrideService::ClearValidityOverride(const nsACString & aHostName, PRInt
nsCAutoString hostPort; nsCAutoString hostPort;
GetHostWithPort(aHostName, aPort, hostPort); GetHostWithPort(aHostName, aPort, hostPort);
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
mSettingsTable.RemoveEntry(hostPort.get()); mSettingsTable.RemoveEntry(hostPort.get());
Write(); Write();
} }
@ -837,7 +838,7 @@ nsCertOverrideService::IsCertUsedForOverrides(nsIX509Cert *aCert,
cai.mDottedOidForStoringNewHashes = mDottedOidForStoringNewHashes; cai.mDottedOidForStoringNewHashes = mDottedOidForStoringNewHashes;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
mSettingsTable.EnumerateEntries(FindMatchingCertCallback, &cai); mSettingsTable.EnumerateEntries(FindMatchingCertCallback, &cai);
} }
*_retval = cai.counter; *_retval = cai.counter;
@ -903,7 +904,7 @@ nsCertOverrideService::EnumerateCertOverrides(nsIX509Cert *aCert,
capac.mDottedOidForStoringNewHashes = mDottedOidForStoringNewHashes; capac.mDottedOidForStoringNewHashes = mDottedOidForStoringNewHashes;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
mSettingsTable.EnumerateEntries(EnumerateCertOverridesCallback, &capac); mSettingsTable.EnumerateEntries(EnumerateCertOverridesCallback, &capac);
} }
return NS_OK; return NS_OK;

View File

@ -41,12 +41,12 @@
#ifndef __NSCERTOVERRIDESERVICE_H__ #ifndef __NSCERTOVERRIDESERVICE_H__
#define __NSCERTOVERRIDESERVICE_H__ #define __NSCERTOVERRIDESERVICE_H__
#include "mozilla/Monitor.h"
#include "nsICertOverrideService.h" #include "nsICertOverrideService.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsString.h" #include "nsString.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "prmon.h"
#include "secoidt.h" #include "secoidt.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
@ -190,7 +190,7 @@ public:
static void GetHostWithPort(const nsACString & aHostName, PRInt32 aPort, nsACString& _retval); static void GetHostWithPort(const nsACString & aHostName, PRInt32 aPort, nsACString& _retval);
protected: protected:
mozilla::Monitor monitor; PRMonitor *monitor;
nsCOMPtr<nsIFile> mSettingsFile; nsCOMPtr<nsIFile> mSettingsFile;
nsTHashtable<nsCertOverrideEntry> mSettingsTable; nsTHashtable<nsCertOverrideEntry> mSettingsTable;

View File

@ -36,11 +36,10 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsMemory.h" #include "nsMemory.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCertVerificationThread.h" #include "nsCertVerificationThread.h"
using namespace mozilla;
nsCertVerificationThread *nsCertVerificationThread::verification_thread_singleton; nsCertVerificationThread *nsCertVerificationThread::verification_thread_singleton;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCertVerificationResult, nsICertVerificationResult) NS_IMPL_THREADSAFE_ISUPPORTS1(nsCertVerificationResult, nsICertVerificationResult)
@ -116,10 +115,10 @@ nsresult nsCertVerificationThread::addJob(nsBaseVerificationJob *aJob)
if (!verification_thread_singleton->mThreadHandle) if (!verification_thread_singleton->mThreadHandle)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
MutexAutoLock threadLock(verification_thread_singleton->mMutex); nsAutoLock threadLock(verification_thread_singleton->mMutex);
verification_thread_singleton->mJobQ.Push(aJob); verification_thread_singleton->mJobQ.Push(aJob);
verification_thread_singleton->mCond.NotifyAll(); PR_NotifyAllCondVar(verification_thread_singleton->mCond);
return NS_OK; return NS_OK;
} }
@ -131,12 +130,12 @@ void nsCertVerificationThread::Run(void)
nsBaseVerificationJob *job = nsnull; nsBaseVerificationJob *job = nsnull;
{ {
MutexAutoLock threadLock(verification_thread_singleton->mMutex); nsAutoLock threadLock(verification_thread_singleton->mMutex);
while (!mExitRequested && (0 == verification_thread_singleton->mJobQ.GetSize())) { while (!mExitRequested && (0 == verification_thread_singleton->mJobQ.GetSize())) {
// no work to do ? let's wait a moment // no work to do ? let's wait a moment
mCond.Wait(); PR_WaitCondVar(mCond, PR_INTERVAL_NO_TIMEOUT);
} }
if (mExitRequested) if (mExitRequested)
@ -153,7 +152,7 @@ void nsCertVerificationThread::Run(void)
} }
{ {
MutexAutoLock threadLock(verification_thread_singleton->mMutex); nsAutoLock threadLock(verification_thread_singleton->mMutex);
while (verification_thread_singleton->mJobQ.GetSize()) { while (verification_thread_singleton->mJobQ.GetSize()) {
nsCertVerificationJob *job = nsCertVerificationJob *job =

View File

@ -48,6 +48,7 @@
#include "nsPromiseFlatString.h" #include "nsPromiseFlatString.h"
#include "nsProxiedService.h" #include "nsProxiedService.h"
#include "nsStringBuffer.h" #include "nsStringBuffer.h"
#include "nsAutoLock.h"
#include "nspr.h" #include "nspr.h"
#include "pk11pub.h" #include "pk11pub.h"
#include "certdb.h" #include "certdb.h"
@ -55,9 +56,6 @@
#include "ssl.h" // For SSL_ClearSessionCache #include "ssl.h" // For SSL_ClearSessionCache
#include "nsNSSCleaner.h" #include "nsNSSCleaner.h"
using namespace mozilla;
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate) NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
NS_IMPL_THREADSAFE_ISUPPORTS2(nsClientAuthRememberService, NS_IMPL_THREADSAFE_ISUPPORTS2(nsClientAuthRememberService,
@ -65,13 +63,15 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsClientAuthRememberService,
nsISupportsWeakReference) nsISupportsWeakReference)
nsClientAuthRememberService::nsClientAuthRememberService() nsClientAuthRememberService::nsClientAuthRememberService()
: monitor("nsClientAuthRememberService.monitor")
{ {
monitor = nsAutoMonitor::NewMonitor("security.clientAuthRememberServiceMonitor");
} }
nsClientAuthRememberService::~nsClientAuthRememberService() nsClientAuthRememberService::~nsClientAuthRememberService()
{ {
RemoveAllFromMemory(); RemoveAllFromMemory();
if (monitor)
nsAutoMonitor::DestroyMonitor(monitor);
} }
nsresult nsresult
@ -110,7 +110,7 @@ nsClientAuthRememberService::Observe(nsISupports *aSubject,
// The profile is about to change, // The profile is about to change,
// or is going away because the application is shutting down. // or is going away because the application is shutting down.
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
RemoveAllFromMemory(); RemoveAllFromMemory();
} }
@ -119,7 +119,7 @@ nsClientAuthRememberService::Observe(nsISupports *aSubject,
void nsClientAuthRememberService::ClearRememberedDecisions() void nsClientAuthRememberService::ClearRememberedDecisions()
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
RemoveAllFromMemory(); RemoveAllFromMemory();
} }
@ -165,7 +165,7 @@ nsClientAuthRememberService::RememberDecision(const nsACString & aHostName,
return rv; return rv;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
if (aClientCert) { if (aClientCert) {
nsNSSCertificate pipCert(aClientCert); nsNSSCertificate pipCert(aClientCert);
char *dbkey = NULL; char *dbkey = NULL;
@ -211,7 +211,7 @@ nsClientAuthRememberService::HasRememberedDecision(const nsACString & aHostName,
nsClientAuthRemember settings; nsClientAuthRemember settings;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsClientAuthRememberEntry *entry = mSettingsTable.GetEntry(hostCert.get()); nsClientAuthRememberEntry *entry = mSettingsTable.GetEntry(hostCert.get());
if (!entry) if (!entry)
return NS_OK; return NS_OK;
@ -233,7 +233,7 @@ nsClientAuthRememberService::AddEntryToList(const nsACString &aHostName,
GetHostWithCert(aHostName, fingerprint, hostCert); GetHostWithCert(aHostName, fingerprint, hostCert);
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
nsClientAuthRememberEntry *entry = mSettingsTable.PutEntry(hostCert.get()); nsClientAuthRememberEntry *entry = mSettingsTable.PutEntry(hostCert.get());
if (!entry) { if (!entry) {

View File

@ -40,7 +40,6 @@
#ifndef __NSCLIENTAUTHREMEMBER_H__ #ifndef __NSCLIENTAUTHREMEMBER_H__
#define __NSCLIENTAUTHREMEMBER_H__ #define __NSCLIENTAUTHREMEMBER_H__
#include "mozilla/Monitor.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsIX509Cert.h" #include "nsIX509Cert.h"
@ -48,6 +47,7 @@
#include "nsNSSCertificate.h" #include "nsNSSCertificate.h"
#include "nsString.h" #include "nsString.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "prmon.h"
class nsClientAuthRemember class nsClientAuthRemember
{ {
@ -163,7 +163,7 @@ public:
void ClearRememberedDecisions(); void ClearRememberedDecisions();
protected: protected:
mozilla::Monitor monitor; PRMonitor *monitor;
nsTHashtable<nsClientAuthRememberEntry> mSettingsTable; nsTHashtable<nsClientAuthRememberEntry> mSettingsTable;
void RemoveAllFromMemory(); void RemoveAllFromMemory();

View File

@ -44,13 +44,11 @@
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsNSSShutDown.h" #include "nsNSSShutDown.h"
using namespace mozilla;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread) NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread)
nsKeygenThread::nsKeygenThread() nsKeygenThread::nsKeygenThread()
:mutex("nsKeygenThread.mutex"), :mutex(nsnull),
iAmRunning(PR_FALSE), iAmRunning(PR_FALSE),
keygenReady(PR_FALSE), keygenReady(PR_FALSE),
statusDialogClosed(PR_FALSE), statusDialogClosed(PR_FALSE),
@ -65,10 +63,14 @@ nsKeygenThread::nsKeygenThread()
wincx(nsnull), wincx(nsnull),
threadHandle(nsnull) threadHandle(nsnull)
{ {
mutex = PR_NewLock();
} }
nsKeygenThread::~nsKeygenThread() nsKeygenThread::~nsKeygenThread()
{ {
if (mutex) {
PR_DestroyLock(mutex);
}
} }
void nsKeygenThread::SetParams( void nsKeygenThread::SetParams(
@ -80,7 +82,7 @@ void nsKeygenThread::SetParams(
void *a_wincx ) void *a_wincx )
{ {
nsNSSShutDownPreventionLock locker; nsNSSShutDownPreventionLock locker;
MutexAutoLock lock(mutex); PR_Lock(mutex);
if (!alreadyReceivedParams) { if (!alreadyReceivedParams) {
alreadyReceivedParams = PR_TRUE; alreadyReceivedParams = PR_TRUE;
@ -96,6 +98,8 @@ void nsKeygenThread::SetParams(
isSensitive = a_isSensitive; isSensitive = a_isSensitive;
wincx = a_wincx; wincx = a_wincx;
} }
PR_Unlock(mutex);
} }
nsresult nsKeygenThread::GetParams( nsresult nsKeygenThread::GetParams(
@ -107,8 +111,8 @@ nsresult nsKeygenThread::GetParams(
} }
nsresult rv; nsresult rv;
MutexAutoLock lock(mutex); PR_Lock(mutex);
// GetParams must not be called until thread creator called // GetParams must not be called until thread creator called
// Join on this thread. // Join on this thread.
@ -127,6 +131,8 @@ nsresult nsKeygenThread::GetParams(
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
} }
PR_Unlock(mutex);
return rv; return rv;
} }
@ -138,6 +144,9 @@ static void PR_CALLBACK nsKeygenThreadRunner(void *arg)
nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver) nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver)
{ {
if (!mutex)
return NS_OK;
if (!aObserver) if (!aObserver)
return NS_OK; return NS_OK;
@ -148,9 +157,10 @@ nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver)
NS_PROXY_SYNC | NS_PROXY_ALWAYS, NS_PROXY_SYNC | NS_PROXY_ALWAYS,
getter_AddRefs(obs)); getter_AddRefs(obs));
MutexAutoLock lock(mutex); PR_Lock(mutex);
if (iAmRunning || keygenReady) { if (iAmRunning || keygenReady) {
PR_Unlock(mutex);
return NS_OK; return NS_OK;
} }
@ -164,6 +174,8 @@ nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver)
// bool thread_started_ok = (threadHandle != nsnull); // bool thread_started_ok = (threadHandle != nsnull);
// we might want to return "thread started ok" to caller in the future // we might want to return "thread started ok" to caller in the future
NS_ASSERTION(threadHandle, "Could not create nsKeygenThreadRunner thread\n"); NS_ASSERTION(threadHandle, "Could not create nsKeygenThreadRunner thread\n");
PR_Unlock(mutex);
return NS_OK; return NS_OK;
} }
@ -175,7 +187,10 @@ nsresult nsKeygenThread::UserCanceled(PRBool *threadAlreadyClosedDialog)
*threadAlreadyClosedDialog = PR_FALSE; *threadAlreadyClosedDialog = PR_FALSE;
MutexAutoLock lock(mutex); if (!mutex)
return NS_OK;
PR_Lock(mutex);
if (keygenReady) if (keygenReady)
*threadAlreadyClosedDialog = statusDialogClosed; *threadAlreadyClosedDialog = statusDialogClosed;
@ -186,6 +201,8 @@ nsresult nsKeygenThread::UserCanceled(PRBool *threadAlreadyClosedDialog)
// it again to avoid problems. // it again to avoid problems.
statusDialogClosed = PR_TRUE; statusDialogClosed = PR_TRUE;
PR_Unlock(mutex);
return NS_OK; return NS_OK;
} }
@ -194,13 +211,14 @@ void nsKeygenThread::Run(void)
nsNSSShutDownPreventionLock locker; nsNSSShutDownPreventionLock locker;
PRBool canGenerate = PR_FALSE; PRBool canGenerate = PR_FALSE;
{ PR_Lock(mutex);
MutexAutoLock lock(mutex);
if (alreadyReceivedParams) { if (alreadyReceivedParams) {
canGenerate = PR_TRUE; canGenerate = PR_TRUE;
keygenReady = PR_FALSE; keygenReady = PR_FALSE;
} }
}
PR_Unlock(mutex);
if (canGenerate) if (canGenerate)
privateKey = PK11_GenerateKeyPair(slot, keyGenMechanism, privateKey = PK11_GenerateKeyPair(slot, keyGenMechanism,
@ -214,8 +232,7 @@ void nsKeygenThread::Run(void)
// to care for cleaning this up. // to care for cleaning this up.
nsCOMPtr<nsIObserver> obs; nsCOMPtr<nsIObserver> obs;
{ PR_Lock(mutex);
MutexAutoLock lock(mutex);
keygenReady = PR_TRUE; keygenReady = PR_TRUE;
iAmRunning = PR_FALSE; iAmRunning = PR_FALSE;
@ -233,7 +250,8 @@ void nsKeygenThread::Run(void)
obs = observer; obs = observer;
observer = nsnull; observer = nsnull;
}
PR_Unlock(mutex);
if (obs) if (obs)
obs->Observe(nsnull, "keygen-finished", nsnull); obs->Observe(nsnull, "keygen-finished", nsnull);

View File

@ -42,7 +42,6 @@
#include "keyhi.h" #include "keyhi.h"
#include "nspr.h" #include "nspr.h"
#include "mozilla/Mutex.h"
#include "nsIKeygenThread.h" #include "nsIKeygenThread.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -51,7 +50,7 @@ class nsIObserver;
class nsKeygenThread : public nsIKeygenThread class nsKeygenThread : public nsIKeygenThread
{ {
private: private:
mozilla::Mutex mutex; PRLock *mutex;
nsCOMPtr<nsIObserver> observer; nsCOMPtr<nsIObserver> observer;

View File

@ -64,6 +64,7 @@
#include "nsIUploadChannel.h" #include "nsIUploadChannel.h"
#include "nsSSLThread.h" #include "nsSSLThread.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsAutoLock.h"
#include "nsIThread.h" #include "nsIThread.h"
#include "nsIWindowWatcher.h" #include "nsIWindowWatcher.h"
#include "nsIPrompt.h" #include "nsIPrompt.h"
@ -76,8 +77,6 @@
#include "nssb64.h" #include "nssb64.h"
#include "secerr.h" #include "secerr.h"
using namespace mozilla;
static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID); static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate) NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
@ -373,8 +372,11 @@ nsNSSHttpRequestSession::internal_send_receive_attempt(PRBool &retryable_error,
if (!mListener) if (!mListener)
return SECFailure; return SECFailure;
Mutex& waitLock = mListener->mLock; if (NS_FAILED(mListener->InitLocks()))
CondVar& waitCondition = mListener->mCondition; return SECFailure;
PRLock *waitLock = mListener->mLock;
PRCondVar *waitCondition = mListener->mCondition;
volatile PRBool &waitFlag = mListener->mWaitFlag; volatile PRBool &waitFlag = mListener->mWaitFlag;
waitFlag = PR_TRUE; waitFlag = PR_TRUE;
@ -396,7 +398,7 @@ nsNSSHttpRequestSession::internal_send_receive_attempt(PRBool &retryable_error,
PRBool request_canceled = PR_FALSE; PRBool request_canceled = PR_FALSE;
{ {
MutexAutoLock locker(waitLock); nsAutoLock locker(waitLock);
const PRIntervalTime start_time = PR_IntervalNow(); const PRIntervalTime start_time = PR_IntervalNow();
PRIntervalTime wait_interval; PRIntervalTime wait_interval;
@ -424,11 +426,12 @@ nsNSSHttpRequestSession::internal_send_receive_attempt(PRBool &retryable_error,
// thread manager. Thanks a lot to Christian Biesinger who // thread manager. Thanks a lot to Christian Biesinger who
// made me aware of this possibility. (kaie) // made me aware of this possibility. (kaie)
MutexAutoUnlock unlock(waitLock); locker.unlock();
NS_ProcessNextEvent(nsnull); NS_ProcessNextEvent(nsnull);
locker.lock();
} }
waitCondition.Wait(wait_interval); PR_WaitCondVar(waitCondition, wait_interval);
if (!waitFlag) if (!waitFlag)
break; break;
@ -554,8 +557,8 @@ void nsNSSHttpInterface::unregisterHttpClient()
nsHTTPListener::nsHTTPListener() nsHTTPListener::nsHTTPListener()
: mResultData(nsnull), : mResultData(nsnull),
mResultLen(0), mResultLen(0),
mLock("nsHTTPListener.mLock"), mLock(nsnull),
mCondition(mLock, "nsHTTPListener.mCondition"), mCondition(nsnull),
mWaitFlag(PR_TRUE), mWaitFlag(PR_TRUE),
mResponsibleForDoneSignal(PR_FALSE), mResponsibleForDoneSignal(PR_FALSE),
mLoadGroup(nsnull), mLoadGroup(nsnull),
@ -563,11 +566,34 @@ nsHTTPListener::nsHTTPListener()
{ {
} }
nsresult nsHTTPListener::InitLocks()
{
mLock = nsAutoLock::NewLock("nsHttpListener::mLock");
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
mCondition = PR_NewCondVar(mLock);
if (!mCondition)
{
nsAutoLock::DestroyLock(mLock);
mLock = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
nsHTTPListener::~nsHTTPListener() nsHTTPListener::~nsHTTPListener()
{ {
if (mResponsibleForDoneSignal) if (mResponsibleForDoneSignal)
send_done_signal(); send_done_signal();
if (mCondition)
PR_DestroyCondVar(mCondition);
if (mLock)
nsAutoLock::DestroyLock(mLock);
if (mLoader) { if (mLoader) {
nsCOMPtr<nsIThread> mainThread(do_GetMainThread()); nsCOMPtr<nsIThread> mainThread(do_GetMainThread());
NS_ProxyRelease(mainThread, mLoader); NS_ProxyRelease(mainThread, mLoader);
@ -581,16 +607,18 @@ nsHTTPListener::FreeLoadGroup(PRBool aCancelLoad)
{ {
nsILoadGroup *lg = nsnull; nsILoadGroup *lg = nsnull;
MutexAutoLock locker(mLock); if (mLock) {
nsAutoLock locker(mLock);
if (mLoadGroup) { if (mLoadGroup) {
if (mLoadGroupOwnerThread != PR_GetCurrentThread()) { if (mLoadGroupOwnerThread != PR_GetCurrentThread()) {
NS_ASSERTION(PR_FALSE, NS_ASSERTION(PR_FALSE,
"attempt to access nsHTTPDownloadEvent::mLoadGroup on multiple threads, leaking it!"); "attempt to access nsHTTPDownloadEvent::mLoadGroup on multiple threads, leaking it!");
} }
else { else {
lg = mLoadGroup; lg = mLoadGroup;
mLoadGroup = nsnull; mLoadGroup = nsnull;
}
} }
} }
@ -660,9 +688,9 @@ void nsHTTPListener::send_done_signal()
mResponsibleForDoneSignal = PR_FALSE; mResponsibleForDoneSignal = PR_FALSE;
{ {
MutexAutoLock locker(mLock); nsAutoLock locker(mLock);
mWaitFlag = PR_FALSE; mWaitFlag = PR_FALSE;
mCondition.NotifyAll(); PR_NotifyAllCondVar(mCondition);
} }
} }

View File

@ -45,8 +45,6 @@
#include "nspr.h" #include "nspr.h"
#include "ocspt.h" #include "ocspt.h"
#include "nsIStreamLoader.h" #include "nsIStreamLoader.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
char* PR_CALLBACK char* PR_CALLBACK
PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg); PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
@ -83,8 +81,10 @@ public:
const PRUint8* mResultData; // not owned, refers to mLoader const PRUint8* mResultData; // not owned, refers to mLoader
PRUint32 mResultLen; PRUint32 mResultLen;
mozilla::Mutex mLock; nsresult InitLocks();
mozilla::CondVar mCondition;
PRLock *mLock;
PRCondVar *mCondition;
volatile PRBool mWaitFlag; volatile PRBool mWaitFlag;
PRBool mResponsibleForDoneSignal; PRBool mResponsibleForDoneSignal;

View File

@ -36,18 +36,18 @@
#include "nsNSSCertCache.h" #include "nsNSSCertCache.h"
#include "nsNSSCertificate.h" #include "nsNSSCertificate.h"
#include "nsAutoLock.h"
#include "cert.h" #include "cert.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsNSSHelper.h" #include "nsNSSHelper.h"
using namespace mozilla;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsNSSCertCache, nsINSSCertCache) NS_IMPL_THREADSAFE_ISUPPORTS1(nsNSSCertCache, nsINSSCertCache)
nsNSSCertCache::nsNSSCertCache() nsNSSCertCache::nsNSSCertCache()
:mutex("nsNSSCertCache.mutex"), mCertList(nsnull) :mCertList(nsnull)
{ {
mutex = nsAutoLock::NewLock("nsNSSCertCache::mutex");
} }
nsNSSCertCache::~nsNSSCertCache() nsNSSCertCache::~nsNSSCertCache()
@ -69,6 +69,11 @@ void nsNSSCertCache::destructorSafeDestroyNSSReference()
{ {
if (isAlreadyShutDown()) if (isAlreadyShutDown())
return; return;
if (mutex) {
nsAutoLock::DestroyLock(mutex);
mutex = nsnull;
}
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -83,7 +88,7 @@ nsNSSCertCache::CacheAllCerts()
CERTCertList *newList = PK11_ListCerts(PK11CertListUnique, cxt); CERTCertList *newList = PK11_ListCerts(PK11CertListUnique, cxt);
if (newList) { if (newList) {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
mCertList = new nsNSSCertList(newList, PR_TRUE); // adopt mCertList = new nsNSSCertList(newList, PR_TRUE); // adopt
} }
@ -98,7 +103,7 @@ nsNSSCertCache::CacheCertList(nsIX509CertList *list)
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
mCertList = list; mCertList = list;
//NS_ADDREF(mCertList); //NS_ADDREF(mCertList);
} }
@ -114,7 +119,7 @@ nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list)
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
if (!mCertList) { if (!mCertList) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
@ -132,6 +137,6 @@ void* nsNSSCertCache::GetCachedCerts()
if (isAlreadyShutDown()) if (isAlreadyShutDown())
return nsnull; return nsnull;
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
return mCertList->GetRawCertList(); return mCertList->GetRawCertList();
} }

View File

@ -40,7 +40,6 @@
#include "nsINSSCertCache.h" #include "nsINSSCertCache.h"
#include "nsIX509CertList.h" #include "nsIX509CertList.h"
#include "certt.h" #include "certt.h"
#include "mozilla/Mutex.h"
#include "nsNSSShutDown.h" #include "nsNSSShutDown.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -55,7 +54,7 @@ public:
virtual ~nsNSSCertCache(); virtual ~nsNSSCertCache();
private: private:
mozilla::Mutex mutex; PRLock *mutex;
nsCOMPtr<nsIX509CertList> mCertList; nsCOMPtr<nsIX509CertList> mCertList;
virtual void virtualDestroyNSSReference(); virtual void virtualDestroyNSSReference();
void destructorSafeDestroyNSSReference(); void destructorSafeDestroyNSSReference();

View File

@ -62,6 +62,7 @@
#include "nsTime.h" #include "nsTime.h"
#include "nsIProxyObjectManager.h" #include "nsIProxyObjectManager.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsAutoLock.h"
#include "nsUsageArrayHelper.h" #include "nsUsageArrayHelper.h"
#include "nsICertificateDialogs.h" #include "nsICertificateDialogs.h"
#include "nsNSSCertHelper.h" #include "nsNSSCertHelper.h"

View File

@ -72,6 +72,7 @@
#include "nsIPrefBranch2.h" #include "nsIPrefBranch2.h"
#include "nsIDateTimeFormat.h" #include "nsIDateTimeFormat.h"
#include "nsDateTimeFormatCID.h" #include "nsDateTimeFormatCID.h"
#include "nsAutoLock.h"
#include "nsIDOMEvent.h" #include "nsIDOMEvent.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsIDOMDocumentEvent.h" #include "nsIDOMDocumentEvent.h"
@ -132,8 +133,6 @@ extern "C" {
#include "p12plcy.h" #include "p12plcy.h"
} }
using namespace mozilla;
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo* gPIPNSSLog = nsnull; PRLogModuleInfo* gPIPNSSLog = nsnull;
#endif #endif
@ -369,12 +368,11 @@ PRBool EnsureNSSInitialized(EnsureNSSOperator op)
} }
nsNSSComponent::nsNSSComponent() nsNSSComponent::nsNSSComponent()
:mutex("nsNSSComponent.mutex"), :mNSSInitialized(PR_FALSE), mThreadList(nsnull),
mNSSInitialized(PR_FALSE),
mCrlTimerLock("nsNSSComponent.mCrlTimerLock"),
mThreadList(nsnull),
mSSLThread(NULL), mCertVerificationThread(NULL) mSSLThread(NULL), mCertVerificationThread(NULL)
{ {
mutex = nsAutoLock::NewLock("nsNSSComponent::mutex");
#ifdef PR_LOGGING #ifdef PR_LOGGING
if (!gPIPNSSLog) if (!gPIPNSSLog)
gPIPNSSLog = PR_NewLogModule("pipnss"); gPIPNSSLog = PR_NewLogModule("pipnss");
@ -384,6 +382,7 @@ nsNSSComponent::nsNSSComponent()
crlDownloadTimerOn = PR_FALSE; crlDownloadTimerOn = PR_FALSE;
crlsScheduledForDownload = nsnull; crlsScheduledForDownload = nsnull;
mTimer = nsnull; mTimer = nsnull;
mCrlTimerLock = nsnull;
mObserversRegistered = PR_FALSE; mObserversRegistered = PR_FALSE;
// In order to keep startup time lower, we delay loading and // In order to keep startup time lower, we delay loading and
@ -416,13 +415,13 @@ nsNSSComponent::~nsNSSComponent()
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent::dtor\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent::dtor\n"));
if (mUpdateTimerInitialized) { if (mUpdateTimerInitialized) {
{ PR_Lock(mCrlTimerLock);
MutexAutoLock lock(mCrlTimerLock); if (crlDownloadTimerOn) {
if (crlDownloadTimerOn) { mTimer->Cancel();
mTimer->Cancel();
}
crlDownloadTimerOn = PR_FALSE;
} }
crlDownloadTimerOn = PR_FALSE;
PR_Unlock(mCrlTimerLock);
PR_DestroyLock(mCrlTimerLock);
if(crlsScheduledForDownload != nsnull){ if(crlsScheduledForDownload != nsnull){
crlsScheduledForDownload->Reset(); crlsScheduledForDownload->Reset();
delete crlsScheduledForDownload; delete crlsScheduledForDownload;
@ -438,6 +437,11 @@ nsNSSComponent::~nsNSSComponent()
--mInstanceCount; --mInstanceCount;
delete mShutdownObjectList; delete mShutdownObjectList;
if (mutex) {
nsAutoLock::DestroyLock(mutex);
mutex = nsnull;
}
// We are being freed, drop the haveLoaded flag to re-enable // We are being freed, drop the haveLoaded flag to re-enable
// potential nss initialization later. // potential nss initialization later.
EnsureNSSInitialized(nssShutdown); EnsureNSSInitialized(nssShutdown);
@ -1298,10 +1302,9 @@ nsNSSComponent::Notify(nsITimer *timer)
nsresult rv; nsresult rv;
//Timer has fired. So set the flag accordingly //Timer has fired. So set the flag accordingly
{ PR_Lock(mCrlTimerLock);
MutexAutoLock lock(mCrlTimerLock); crlDownloadTimerOn = PR_FALSE;
crlDownloadTimerOn = PR_FALSE; PR_Unlock(mCrlTimerLock);
}
//First, handle this download //First, handle this download
rv = DownloadCrlSilently(); rv = DownloadCrlSilently();
@ -1343,7 +1346,8 @@ nsNSSComponent::DefineNextTimer()
//This part should be synchronized because this function might be called from separate //This part should be synchronized because this function might be called from separate
//threads //threads
MutexAutoLock lock(mCrlTimerLock); //Lock the lock
PR_Lock(mCrlTimerLock);
if (crlDownloadTimerOn) { if (crlDownloadTimerOn) {
mTimer->Cancel(); mTimer->Cancel();
@ -1352,7 +1356,8 @@ nsNSSComponent::DefineNextTimer()
rv = getParamsForNextCrlToDownload(&mDownloadURL, &nextFiring, &mCrlUpdateKey); rv = getParamsForNextCrlToDownload(&mDownloadURL, &nextFiring, &mCrlUpdateKey);
//If there are no more crls to be updated any time in future //If there are no more crls to be updated any time in future
if(NS_FAILED(rv)){ if(NS_FAILED(rv)){
// Return - no error - just implies nothing to schedule //Free the lock and return - no error - just implies nothing to schedule
PR_Unlock(mCrlTimerLock);
return NS_OK; return NS_OK;
} }
@ -1370,8 +1375,11 @@ nsNSSComponent::DefineNextTimer()
interval, interval,
nsITimer::TYPE_ONE_SHOT); nsITimer::TYPE_ONE_SHOT);
crlDownloadTimerOn = PR_TRUE; crlDownloadTimerOn = PR_TRUE;
//Release
PR_Unlock(mCrlTimerLock);
return NS_OK; return NS_OK;
} }
//Note that the StopCRLUpdateTimer and InitializeCRLUpdateTimer functions should never be called //Note that the StopCRLUpdateTimer and InitializeCRLUpdateTimer functions should never be called
@ -1388,13 +1396,15 @@ nsNSSComponent::StopCRLUpdateTimer()
delete crlsScheduledForDownload; delete crlsScheduledForDownload;
crlsScheduledForDownload = nsnull; crlsScheduledForDownload = nsnull;
} }
{
MutexAutoLock lock(mCrlTimerLock); PR_Lock(mCrlTimerLock);
if (crlDownloadTimerOn) { if (crlDownloadTimerOn) {
mTimer->Cancel(); mTimer->Cancel();
}
crlDownloadTimerOn = PR_FALSE;
} }
crlDownloadTimerOn = PR_FALSE;
PR_Unlock(mCrlTimerLock);
PR_DestroyLock(mCrlTimerLock);
mUpdateTimerInitialized = PR_FALSE; mUpdateTimerInitialized = PR_FALSE;
} }
@ -1413,6 +1423,7 @@ nsNSSComponent::InitializeCRLUpdateTimer()
return rv; return rv;
} }
crlsScheduledForDownload = new nsHashtable(16, PR_TRUE); crlsScheduledForDownload = new nsHashtable(16, PR_TRUE);
mCrlTimerLock = PR_NewLock();
DefineNextTimer(); DefineNextTimer();
mUpdateTimerInitialized = PR_TRUE; mUpdateTimerInitialized = PR_TRUE;
} }
@ -1550,7 +1561,7 @@ nsNSSComponent::InitializeNSS(PRBool showWarningBox)
which_nss_problem = problem_none; which_nss_problem = problem_none;
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
// Init phase 1, prepare own variables used for NSS // Init phase 1, prepare own variables used for NSS
@ -1810,7 +1821,7 @@ nsNSSComponent::ShutdownNSS()
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent::ShutdownNSS\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("nsNSSComponent::ShutdownNSS\n"));
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (hashTableCerts) { if (hashTableCerts) {
@ -1863,7 +1874,7 @@ nsNSSComponent::Init()
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("Beginning NSS initialization\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("Beginning NSS initialization\n"));
if (!mShutdownObjectList) if (!mutex || !mShutdownObjectList)
{ {
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS init, out of memory in constructor\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("NSS init, out of memory in constructor\n"));
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -2072,7 +2083,7 @@ nsNSSComponent::VerifySignature(const char* aRSABuf, PRUint32 aRSABufLen,
} }
if (!mScriptSecurityManager) { if (!mScriptSecurityManager) {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
// re-test the condition to prevent double initialization // re-test the condition to prevent double initialization
if (!mScriptSecurityManager) { if (!mScriptSecurityManager) {
mScriptSecurityManager = mScriptSecurityManager =
@ -2127,7 +2138,7 @@ nsNSSComponent::RandomUpdate(void *entropy, PRInt32 bufLen)
// Asynchronous event happening often, // Asynchronous event happening often,
// must not interfere with initialization or profile switch. // must not interfere with initialization or profile switch.
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
if (!mNSSInitialized) if (!mNSSInitialized)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
@ -2181,7 +2192,7 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic,
PRBool needsInit = PR_TRUE; PRBool needsInit = PR_TRUE;
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
if (mNSSInitialized) { if (mNSSInitialized) {
// We have already initialized NSS before the profile came up, // We have already initialized NSS before the profile came up,
@ -2437,7 +2448,7 @@ nsNSSComponent::RememberCert(CERTCertificate *cert)
// Must not interfere with init / shutdown / profile switch. // Must not interfere with init / shutdown / profile switch.
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
if (!hashTableCerts || !cert) if (!hashTableCerts || !cert)
return NS_OK; return NS_OK;
@ -2513,7 +2524,7 @@ nsNSSComponent::DoProfileBeforeChange(nsISupports* aSubject)
PRBool needsCleanup = PR_TRUE; PRBool needsCleanup = PR_TRUE;
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
if (!mNSSInitialized) { if (!mNSSInitialized) {
// Make sure we don't try to cleanup if we have already done so. // Make sure we don't try to cleanup if we have already done so.
@ -2561,7 +2572,7 @@ nsNSSComponent::GetClientAuthRememberService(nsClientAuthRememberService **cars)
NS_IMETHODIMP NS_IMETHODIMP
nsNSSComponent::IsNSSInitialized(PRBool *initialized) nsNSSComponent::IsNSSInitialized(PRBool *initialized)
{ {
MutexAutoLock lock(mutex); nsAutoLock lock(mutex);
*initialized = mNSSInitialized; *initialized = mNSSInitialized;
return NS_OK; return NS_OK;
} }

View File

@ -44,7 +44,6 @@
#ifndef _nsNSSComponent_h_ #ifndef _nsNSSComponent_h_
#define _nsNSSComponent_h_ #define _nsNSSComponent_h_
#include "mozilla/Mutex.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsISignatureVerifier.h" #include "nsISignatureVerifier.h"
#include "nsIURIContentListener.h" #include "nsIURIContentListener.h"
@ -63,6 +62,7 @@
#include "nsITimer.h" #include "nsITimer.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "prlock.h"
#include "nsICryptoHash.h" #include "nsICryptoHash.h"
#include "nsICryptoHMAC.h" #include "nsICryptoHMAC.h"
#include "hasht.h" #include "hasht.h"
@ -228,6 +228,7 @@ private:
void destructorSafeDestroyNSSReference(); void destructorSafeDestroyNSSReference();
}; };
struct PRLock;
class nsNSSShutDownList; class nsNSSShutDownList;
class nsSSLThread; class nsSSLThread;
class nsCertVerificationThread; class nsCertVerificationThread;
@ -240,8 +241,6 @@ class nsNSSComponent : public nsISignatureVerifier,
public nsSupportsWeakReference, public nsSupportsWeakReference,
public nsITimerCallback public nsITimerCallback
{ {
typedef mozilla::Mutex Mutex;
public: public:
NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID ) NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID )
@ -327,7 +326,7 @@ private:
void DoProfileBeforeChange(nsISupports* aSubject); void DoProfileBeforeChange(nsISupports* aSubject);
void DoProfileChangeNetRestore(); void DoProfileChangeNetRestore();
Mutex mutex; PRLock *mutex;
nsCOMPtr<nsIScriptSecurityManager> mScriptSecurityManager; nsCOMPtr<nsIScriptSecurityManager> mScriptSecurityManager;
nsCOMPtr<nsIStringBundle> mPIPNSSBundle; nsCOMPtr<nsIStringBundle> mPIPNSSBundle;
@ -340,7 +339,7 @@ private:
PLHashTable *hashTableCerts; PLHashTable *hashTableCerts;
nsAutoString mDownloadURL; nsAutoString mDownloadURL;
nsAutoString mCrlUpdateKey; nsAutoString mCrlUpdateKey;
Mutex mCrlTimerLock; PRLock *mCrlTimerLock;
nsHashtable *crlsScheduledForDownload; nsHashtable *crlsScheduledForDownload;
PRBool crlDownloadTimerOn; PRBool crlDownloadTimerOn;
PRBool mUpdateTimerInitialized; PRBool mUpdateTimerInitialized;

View File

@ -74,6 +74,7 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "nsAutoLock.h"
#include "nsSSLThread.h" #include "nsSSLThread.h"
#include "nsNSSShutDown.h" #include "nsNSSShutDown.h"
#include "nsSSLStatus.h" #include "nsSSLStatus.h"
@ -99,7 +100,6 @@
#include "keyhi.h" #include "keyhi.h"
#include "secport.h" #include "secport.h"
using namespace mozilla;
//#define DEBUG_SSL_VERBOSE //Enable this define to get minimal //#define DEBUG_SSL_VERBOSE //Enable this define to get minimal
//reports when doing SSL read/write //reports when doing SSL read/write
@ -936,7 +936,7 @@ void nsSSLIOLayerHelpers::Cleanup()
PR_DestroyPollableEvent(mSharedPollableEvent); PR_DestroyPollableEvent(mSharedPollableEvent);
if (mutex) { if (mutex) {
delete mutex; nsAutoLock::DestroyLock(mutex);
mutex = nsnull; mutex = nsnull;
} }
@ -1801,7 +1801,7 @@ nsSSLIOLayerHelpers::rememberTolerantSite(PRFileDesc* ssl_layer_fd,
nsCAutoString key; nsCAutoString key;
getSiteKey(socketInfo, key); getSiteKey(socketInfo, key);
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
nsSSLIOLayerHelpers::mTLSTolerantSites->Put(key); nsSSLIOLayerHelpers::mTLSTolerantSites->Put(key);
} }
@ -2073,7 +2073,7 @@ nsSSLIOLayerPoll(PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
PRBool nsSSLIOLayerHelpers::nsSSLIOLayerInitialized = PR_FALSE; PRBool nsSSLIOLayerHelpers::nsSSLIOLayerInitialized = PR_FALSE;
PRDescIdentity nsSSLIOLayerHelpers::nsSSLIOLayerIdentity; PRDescIdentity nsSSLIOLayerHelpers::nsSSLIOLayerIdentity;
PRIOMethods nsSSLIOLayerHelpers::nsSSLIOLayerMethods; PRIOMethods nsSSLIOLayerHelpers::nsSSLIOLayerMethods;
Mutex *nsSSLIOLayerHelpers::mutex = nsnull; PRLock *nsSSLIOLayerHelpers::mutex = nsnull;
nsCStringHashSet *nsSSLIOLayerHelpers::mTLSIntolerantSites = nsnull; nsCStringHashSet *nsSSLIOLayerHelpers::mTLSIntolerantSites = nsnull;
nsCStringHashSet *nsSSLIOLayerHelpers::mTLSTolerantSites = nsnull; nsCStringHashSet *nsSSLIOLayerHelpers::mTLSTolerantSites = nsnull;
nsPSMRememberCertErrorsTable *nsSSLIOLayerHelpers::mHostsWithCertErrors = nsnull; nsPSMRememberCertErrorsTable *nsSSLIOLayerHelpers::mHostsWithCertErrors = nsnull;
@ -2275,7 +2275,9 @@ nsresult nsSSLIOLayerHelpers::Init()
nsSSLIOLayerMethods.poll = nsSSLIOLayerPoll; nsSSLIOLayerMethods.poll = nsSSLIOLayerPoll;
} }
mutex = new Mutex("nsSSLIOLayerHelpers.mutex"); mutex = nsAutoLock::NewLock("nsSSLIOLayerHelpers::mutex");
if (!mutex)
return NS_ERROR_OUT_OF_MEMORY;
mSharedPollableEvent = PR_NewPollableEvent(); mSharedPollableEvent = PR_NewPollableEvent();
@ -2313,7 +2315,7 @@ nsresult nsSSLIOLayerHelpers::Init()
void nsSSLIOLayerHelpers::addIntolerantSite(const nsCString &str) void nsSSLIOLayerHelpers::addIntolerantSite(const nsCString &str)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
// Remember intolerant site only if it is not known as tolerant // Remember intolerant site only if it is not known as tolerant
if (!mTLSTolerantSites->Contains(str)) if (!mTLSTolerantSites->Contains(str))
nsSSLIOLayerHelpers::mTLSIntolerantSites->Put(str); nsSSLIOLayerHelpers::mTLSIntolerantSites->Put(str);
@ -2321,19 +2323,19 @@ void nsSSLIOLayerHelpers::addIntolerantSite(const nsCString &str)
void nsSSLIOLayerHelpers::removeIntolerantSite(const nsCString &str) void nsSSLIOLayerHelpers::removeIntolerantSite(const nsCString &str)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
nsSSLIOLayerHelpers::mTLSIntolerantSites->Remove(str); nsSSLIOLayerHelpers::mTLSIntolerantSites->Remove(str);
} }
PRBool nsSSLIOLayerHelpers::isKnownAsIntolerantSite(const nsCString &str) PRBool nsSSLIOLayerHelpers::isKnownAsIntolerantSite(const nsCString &str)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
return mTLSIntolerantSites->Contains(str); return mTLSIntolerantSites->Contains(str);
} }
void nsSSLIOLayerHelpers::setRenegoUnrestrictedSites(const nsCString &str) void nsSSLIOLayerHelpers::setRenegoUnrestrictedSites(const nsCString &str)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
if (mRenegoUnrestrictedSites) { if (mRenegoUnrestrictedSites) {
delete mRenegoUnrestrictedSites; delete mRenegoUnrestrictedSites;
@ -2358,31 +2360,31 @@ void nsSSLIOLayerHelpers::setRenegoUnrestrictedSites(const nsCString &str)
PRBool nsSSLIOLayerHelpers::isRenegoUnrestrictedSite(const nsCString &str) PRBool nsSSLIOLayerHelpers::isRenegoUnrestrictedSite(const nsCString &str)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
return mRenegoUnrestrictedSites->Contains(str); return mRenegoUnrestrictedSites->Contains(str);
} }
void nsSSLIOLayerHelpers::setTreatUnsafeNegotiationAsBroken(PRBool broken) void nsSSLIOLayerHelpers::setTreatUnsafeNegotiationAsBroken(PRBool broken)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
mTreatUnsafeNegotiationAsBroken = broken; mTreatUnsafeNegotiationAsBroken = broken;
} }
PRBool nsSSLIOLayerHelpers::treatUnsafeNegotiationAsBroken() PRBool nsSSLIOLayerHelpers::treatUnsafeNegotiationAsBroken()
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
return mTreatUnsafeNegotiationAsBroken; return mTreatUnsafeNegotiationAsBroken;
} }
void nsSSLIOLayerHelpers::setWarnLevelMissingRFC5746(PRInt32 level) void nsSSLIOLayerHelpers::setWarnLevelMissingRFC5746(PRInt32 level)
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
mWarnLevelMissingRFC5746 = level; mWarnLevelMissingRFC5746 = level;
} }
PRInt32 nsSSLIOLayerHelpers::getWarnLevelMissingRFC5746() PRInt32 nsSSLIOLayerHelpers::getWarnLevelMissingRFC5746()
{ {
MutexAutoLock lock(*mutex); nsAutoLock lock(mutex);
return mWarnLevelMissingRFC5746; return mWarnLevelMissingRFC5746;
} }

View File

@ -44,7 +44,6 @@
#include "prtypes.h" #include "prtypes.h"
#include "prio.h" #include "prio.h"
#include "certt.h" #include "certt.h"
#include "mozilla/Mutex.h"
#include "nsString.h" #include "nsString.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
@ -283,7 +282,7 @@ public:
static PRDescIdentity nsSSLIOLayerIdentity; static PRDescIdentity nsSSLIOLayerIdentity;
static PRIOMethods nsSSLIOLayerMethods; static PRIOMethods nsSSLIOLayerMethods;
static mozilla::Mutex *mutex; static PRLock *mutex;
static nsCStringHashSet *mTLSIntolerantSites; static nsCStringHashSet *mTLSIntolerantSites;
static nsCStringHashSet *mTLSTolerantSites; static nsCStringHashSet *mTLSTolerantSites;
static nsPSMRememberCertErrorsTable* mHostsWithCertErrors; static nsPSMRememberCertErrorsTable* mHostsWithCertErrors;

View File

@ -38,8 +38,6 @@
#include "nsNSSShutDown.h" #include "nsNSSShutDown.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
using namespace mozilla;
#ifdef PR_LOGGING #ifdef PR_LOGGING
extern PRLogModuleInfo* gPIPNSSLog; extern PRLogModuleInfo* gPIPNSSLog;
#endif #endif
@ -79,8 +77,8 @@ static PLDHashTableOps gSetOps = {
nsNSSShutDownList *nsNSSShutDownList::singleton = nsnull; nsNSSShutDownList *nsNSSShutDownList::singleton = nsnull;
nsNSSShutDownList::nsNSSShutDownList() nsNSSShutDownList::nsNSSShutDownList()
:mListLock("nsNSSShutDownList.mListLock")
{ {
mListLock = PR_NewLock();
mActiveSSLSockets = 0; mActiveSSLSockets = 0;
mPK11LogoutCancelObjects.ops = nsnull; mPK11LogoutCancelObjects.ops = nsnull;
mObjects.ops = nsnull; mObjects.ops = nsnull;
@ -92,6 +90,10 @@ nsNSSShutDownList::nsNSSShutDownList()
nsNSSShutDownList::~nsNSSShutDownList() nsNSSShutDownList::~nsNSSShutDownList()
{ {
if (mListLock) {
PR_DestroyLock(mListLock);
mListLock = nsnull;
}
if (mObjects.ops) { if (mObjects.ops) {
PL_DHashTableFinish(&mObjects); PL_DHashTableFinish(&mObjects);
mObjects.ops = nsnull; mObjects.ops = nsnull;
@ -110,8 +112,9 @@ void nsNSSShutDownList::remember(nsNSSShutDownObject *o)
return; return;
PR_ASSERT(o); PR_ASSERT(o);
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_ADD); PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_ADD);
PR_Unlock(singleton->mListLock);
} }
void nsNSSShutDownList::forget(nsNSSShutDownObject *o) void nsNSSShutDownList::forget(nsNSSShutDownObject *o)
@ -120,8 +123,9 @@ void nsNSSShutDownList::forget(nsNSSShutDownObject *o)
return; return;
PR_ASSERT(o); PR_ASSERT(o);
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_REMOVE); PL_DHashTableOperate(&singleton->mObjects, o, PL_DHASH_REMOVE);
PR_Unlock(singleton->mListLock);
} }
void nsNSSShutDownList::remember(nsOnPK11LogoutCancelObject *o) void nsNSSShutDownList::remember(nsOnPK11LogoutCancelObject *o)
@ -130,8 +134,9 @@ void nsNSSShutDownList::remember(nsOnPK11LogoutCancelObject *o)
return; return;
PR_ASSERT(o); PR_ASSERT(o);
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_ADD); PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_ADD);
PR_Unlock(singleton->mListLock);
} }
void nsNSSShutDownList::forget(nsOnPK11LogoutCancelObject *o) void nsNSSShutDownList::forget(nsOnPK11LogoutCancelObject *o)
@ -140,8 +145,9 @@ void nsNSSShutDownList::forget(nsOnPK11LogoutCancelObject *o)
return; return;
PR_ASSERT(o); PR_ASSERT(o);
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_REMOVE); PL_DHashTableOperate(&singleton->mPK11LogoutCancelObjects, o, PL_DHASH_REMOVE);
PR_Unlock(singleton->mListLock);
} }
void nsNSSShutDownList::trackSSLSocketCreate() void nsNSSShutDownList::trackSSLSocketCreate()
@ -149,8 +155,9 @@ void nsNSSShutDownList::trackSSLSocketCreate()
if (!singleton) if (!singleton)
return; return;
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
++singleton->mActiveSSLSockets; ++singleton->mActiveSSLSockets;
PR_Unlock(singleton->mListLock);
} }
void nsNSSShutDownList::trackSSLSocketClose() void nsNSSShutDownList::trackSSLSocketClose()
@ -158,8 +165,9 @@ void nsNSSShutDownList::trackSSLSocketClose()
if (!singleton) if (!singleton)
return; return;
MutexAutoLock lock(singleton->mListLock); PR_Lock(singleton->mListLock);
--singleton->mActiveSSLSockets; --singleton->mActiveSSLSockets;
PR_Unlock(singleton->mListLock);
} }
PRBool nsNSSShutDownList::areSSLSocketsActive() PRBool nsNSSShutDownList::areSSLSocketsActive()
@ -172,8 +180,12 @@ PRBool nsNSSShutDownList::areSSLSocketsActive()
return PR_FALSE; return PR_FALSE;
} }
MutexAutoLock lock(singleton->mListLock); PRBool retval;
return (singleton->mActiveSSLSockets > 0); PR_Lock(singleton->mListLock);
retval = (singleton->mActiveSSLSockets > 0);
PR_Unlock(singleton->mListLock);
return retval;
} }
nsresult nsNSSShutDownList::doPK11Logout() nsresult nsNSSShutDownList::doPK11Logout()
@ -184,8 +196,9 @@ nsresult nsNSSShutDownList::doPK11Logout()
// We only must ensure that our objects do not go away. // We only must ensure that our objects do not go away.
// This is guaranteed by holding the list lock. // This is guaranteed by holding the list lock.
MutexAutoLock lock(singleton->mListLock); PR_Lock(mListLock);
PL_DHashTableEnumerate(&mPK11LogoutCancelObjects, doPK11LogoutHelper, 0); PL_DHashTableEnumerate(&mPK11LogoutCancelObjects, doPK11LogoutHelper, 0);
PR_Unlock(mListLock);
return NS_OK; return NS_OK;
} }
@ -234,8 +247,9 @@ nsresult nsNSSShutDownList::evaporateAllNSSResources()
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("now evaporating NSS resources\n")); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("now evaporating NSS resources\n"));
int removedCount; int removedCount;
do { do {
MutexAutoLock lock(mListLock); PR_Lock(mListLock);
removedCount = PL_DHashTableEnumerate(&mObjects, evaporateAllNSSResourcesHelper, 0); removedCount = PL_DHashTableEnumerate(&mObjects, evaporateAllNSSResourcesHelper, 0);
PR_Unlock(mListLock);
} while (removedCount > 0); } while (removedCount > 0);
mActivityState.releaseCurrentThreadActivityRestriction(); mActivityState.releaseCurrentThreadActivityRestriction();
@ -246,15 +260,17 @@ PLDHashOperator PR_CALLBACK
nsNSSShutDownList::evaporateAllNSSResourcesHelper(PLDHashTable *table, nsNSSShutDownList::evaporateAllNSSResourcesHelper(PLDHashTable *table,
PLDHashEntryHdr *hdr, PRUint32 number, void *arg) PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
{ {
ObjectHashEntry *entry = static_cast<ObjectHashEntry*>(hdr); ObjectHashEntry *entry = static_cast<ObjectHashEntry*>(hdr);
{ PR_Unlock(singleton->mListLock);
MutexAutoUnlock unlock(singleton->mListLock);
entry->obj->shutdown(nsNSSShutDownObject::calledFromList); entry->obj->shutdown(nsNSSShutDownObject::calledFromList);
}
// Never free more than one entry, because other threads might be calling PR_Lock(singleton->mListLock);
// us and remove themselves while we are iterating over the list,
// and the behaviour of changing the list while iterating is undefined. // Never free more than one entry, because other threads might be calling
return (PLDHashOperator)(PL_DHASH_STOP | PL_DHASH_REMOVE); // us and remove themselves while we are iterating over the list,
// and the behaviour of changing the list while iterating is undefined.
return (PLDHashOperator)(PL_DHASH_STOP | PL_DHASH_REMOVE);
} }
nsNSSShutDownList *nsNSSShutDownList::construct() nsNSSShutDownList *nsNSSShutDownList::construct()
@ -269,129 +285,173 @@ nsNSSShutDownList *nsNSSShutDownList::construct()
} }
nsNSSActivityState::nsNSSActivityState() nsNSSActivityState::nsNSSActivityState()
:mNSSActivityStateLock("nsNSSActivityState.mNSSActivityStateLock"), :mNSSActivityStateLock(nsnull),
mNSSActivityChanged(mNSSActivityStateLock, mNSSActivityChanged(nsnull),
"nsNSSActivityState.mNSSActivityStateLock"),
mNSSActivityCounter(0), mNSSActivityCounter(0),
mBlockingUICounter(0), mBlockingUICounter(0),
mIsUIForbidden(PR_FALSE), mIsUIForbidden(PR_FALSE),
mNSSRestrictedThread(nsnull) mNSSRestrictedThread(nsnull)
{ {
mNSSActivityStateLock = PR_NewLock();
if (!mNSSActivityStateLock)
return;
mNSSActivityChanged = PR_NewCondVar(mNSSActivityStateLock);
} }
nsNSSActivityState::~nsNSSActivityState() nsNSSActivityState::~nsNSSActivityState()
{ {
if (mNSSActivityChanged) {
PR_DestroyCondVar(mNSSActivityChanged);
mNSSActivityChanged = nsnull;
}
if (mNSSActivityStateLock) {
PR_DestroyLock(mNSSActivityStateLock);
mNSSActivityStateLock = nsnull;
}
} }
void nsNSSActivityState::enter() void nsNSSActivityState::enter()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
while (mNSSRestrictedThread && mNSSRestrictedThread != PR_GetCurrentThread()) { while (mNSSRestrictedThread && mNSSRestrictedThread != PR_GetCurrentThread()) {
mNSSActivityChanged.Wait(); PR_WaitCondVar(mNSSActivityChanged, PR_INTERVAL_NO_TIMEOUT);
} }
++mNSSActivityCounter; ++mNSSActivityCounter;
PR_Unlock(mNSSActivityStateLock);
} }
void nsNSSActivityState::leave() void nsNSSActivityState::leave()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
--mNSSActivityCounter; --mNSSActivityCounter;
mNSSActivityChanged.NotifyAll(); if (!mNSSActivityCounter) {
PR_NotifyAllCondVar(mNSSActivityChanged);
}
PR_Unlock(mNSSActivityStateLock);
} }
void nsNSSActivityState::enterBlockingUIState() void nsNSSActivityState::enterBlockingUIState()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
++mBlockingUICounter; ++mBlockingUICounter;
PR_Unlock(mNSSActivityStateLock);
} }
void nsNSSActivityState::leaveBlockingUIState() void nsNSSActivityState::leaveBlockingUIState()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
--mBlockingUICounter; --mBlockingUICounter;
PR_Unlock(mNSSActivityStateLock);
} }
PRBool nsNSSActivityState::isBlockingUIActive() PRBool nsNSSActivityState::isBlockingUIActive()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PRBool retval;
return (mBlockingUICounter > 0);
PR_Lock(mNSSActivityStateLock);
retval = (mBlockingUICounter > 0);
PR_Unlock(mNSSActivityStateLock);
return retval;
} }
PRBool nsNSSActivityState::isUIForbidden() PRBool nsNSSActivityState::isUIForbidden()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PRBool retval;
return mIsUIForbidden;
PR_Lock(mNSSActivityStateLock);
retval = mIsUIForbidden;
PR_Unlock(mNSSActivityStateLock);
return retval;
} }
PRBool nsNSSActivityState::ifPossibleDisallowUI(RealOrTesting rot) PRBool nsNSSActivityState::ifPossibleDisallowUI(RealOrTesting rot)
{ {
PRBool retval = PR_FALSE; PRBool retval = PR_FALSE;
MutexAutoLock lock(mNSSActivityStateLock);
// Checking and disallowing the UI must be done atomically. PR_Lock(mNSSActivityStateLock);
if (!mBlockingUICounter) { // Checking and disallowing the UI must be done atomically.
// No UI is currently shown, we are able to evaporate.
retval = PR_TRUE; if (!mBlockingUICounter) {
if (rot == do_it_for_real) { // No UI is currently shown, we are able to evaporate.
// Remember to disallow UI. retval = PR_TRUE;
mIsUIForbidden = PR_TRUE; if (rot == do_it_for_real) {
// Remember to disallow UI.
mIsUIForbidden = PR_TRUE;
// to clear the "forbidden" state, // to clear the "forbidden" state,
// one must either call // one must either call
// restrictActivityToCurrentThread() + releaseCurrentThreadActivityRestriction() // restrictActivityToCurrentThread() + releaseCurrentThreadActivityRestriction()
// or cancel the operation by calling // or cancel the operation by calling
// unprepareCurrentThreadRestriction() // unprepareCurrentThreadRestriction()
}
} }
}
PR_Unlock(mNSSActivityStateLock);
return retval; return retval;
} }
void nsNSSActivityState::allowUI() void nsNSSActivityState::allowUI()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
mIsUIForbidden = PR_FALSE; mIsUIForbidden = PR_FALSE;
PR_Unlock(mNSSActivityStateLock);
} }
PRStatus nsNSSActivityState::restrictActivityToCurrentThread() PRStatus nsNSSActivityState::restrictActivityToCurrentThread()
{ {
PRStatus retval = PR_FAILURE; PRStatus retval = PR_FAILURE;
MutexAutoLock lock(mNSSActivityStateLock);
PR_Lock(mNSSActivityStateLock);
if (!mBlockingUICounter) { if (!mBlockingUICounter) {
while (0 < mNSSActivityCounter && !mBlockingUICounter) { while (0 < mNSSActivityCounter && !mBlockingUICounter) {
mNSSActivityChanged.Wait(PR_TicksPerSecond()); PR_WaitCondVar(mNSSActivityChanged, PR_TicksPerSecond());
} }
if (mBlockingUICounter) { if (mBlockingUICounter) {
// This should never happen. // This should never happen.
// If we arrive here, our logic is broken. // If we arrive here, our logic is broken.
PR_ASSERT(0); PR_ASSERT(0);
}
else {
mNSSRestrictedThread = PR_GetCurrentThread();
retval = PR_SUCCESS;
}
} }
else {
mNSSRestrictedThread = PR_GetCurrentThread(); PR_Unlock(mNSSActivityStateLock);
retval = PR_SUCCESS;
}
}
return retval; return retval;
} }
void nsNSSActivityState::releaseCurrentThreadActivityRestriction() void nsNSSActivityState::releaseCurrentThreadActivityRestriction()
{ {
MutexAutoLock lock(mNSSActivityStateLock); PR_Lock(mNSSActivityStateLock);
mNSSRestrictedThread = nsnull; mNSSRestrictedThread = nsnull;
mIsUIForbidden = PR_FALSE; mIsUIForbidden = PR_FALSE;
mNSSActivityChanged.NotifyAll(); PR_NotifyAllCondVar(mNSSActivityChanged);
PR_Unlock(mNSSActivityStateLock);
} }
nsNSSShutDownPreventionLock::nsNSSShutDownPreventionLock() nsNSSShutDownPreventionLock::nsNSSShutDownPreventionLock()

View File

@ -41,8 +41,6 @@
#include "nscore.h" #include "nscore.h"
#include "nspr.h" #include "nspr.h"
#include "pldhash.h" #include "pldhash.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
class nsNSSShutDownObject; class nsNSSShutDownObject;
class nsOnPK11LogoutCancelObject; class nsOnPK11LogoutCancelObject;
@ -91,12 +89,12 @@ public:
private: private:
// The lock protecting all our member variables. // The lock protecting all our member variables.
mozilla::Mutex mNSSActivityStateLock; PRLock *mNSSActivityStateLock;
// The activity variable, bound to our lock, // The activity variable, bound to our lock,
// used either to signal the activity counter reaches zero, // used either to signal the activity counter reaches zero,
// or a thread restriction has been released. // or a thread restriction has been released.
mozilla::CondVar mNSSActivityChanged; PRCondVar *mNSSActivityChanged;
// The number of active scopes holding resources. // The number of active scopes holding resources.
int mNSSActivityCounter; int mNSSActivityCounter;
@ -188,7 +186,7 @@ private:
doPK11LogoutHelper(PLDHashTable *table, PLDHashEntryHdr *hdr, doPK11LogoutHelper(PLDHashTable *table, PLDHashEntryHdr *hdr,
PRUint32 number, void *arg); PRUint32 number, void *arg);
protected: protected:
mozilla::Mutex mListLock; PRLock* mListLock;
static nsNSSShutDownList *singleton; static nsNSSShutDownList *singleton;
PLDHashTable mObjects; PLDHashTable mObjects;
PRUint32 mActiveSSLSockets; PRUint32 mActiveSSLSockets;

View File

@ -36,8 +36,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsPSMBackgroundThread.h" #include "nsPSMBackgroundThread.h"
#include "nsAutoLock.h"
using namespace mozilla;
void PR_CALLBACK nsPSMBackgroundThread::nsThreadRunner(void *arg) void PR_CALLBACK nsPSMBackgroundThread::nsThreadRunner(void *arg)
{ {
@ -47,14 +46,19 @@ void PR_CALLBACK nsPSMBackgroundThread::nsThreadRunner(void *arg)
nsPSMBackgroundThread::nsPSMBackgroundThread() nsPSMBackgroundThread::nsPSMBackgroundThread()
: mThreadHandle(nsnull), : mThreadHandle(nsnull),
mMutex("nsPSMBackgroundThread.mMutex"), mMutex(nsnull),
mCond(mMutex, "nsPSMBackgroundThread.mCond"), mCond(nsnull),
mExitRequested(PR_FALSE) mExitRequested(PR_FALSE)
{ {
mMutex = nsAutoLock::NewLock("nsPSMBackgroundThread::mMutex");
mCond = PR_NewCondVar(mMutex);
} }
nsresult nsPSMBackgroundThread::startThread() nsresult nsPSMBackgroundThread::startThread()
{ {
if (!mMutex || !mCond)
return NS_ERROR_OUT_OF_MEMORY;
mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsThreadRunner, static_cast<void*>(this), mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsThreadRunner, static_cast<void*>(this),
PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
@ -68,6 +72,11 @@ nsresult nsPSMBackgroundThread::startThread()
nsPSMBackgroundThread::~nsPSMBackgroundThread() nsPSMBackgroundThread::~nsPSMBackgroundThread()
{ {
if (mCond)
PR_DestroyCondVar(mCond);
if (mMutex)
nsAutoLock::DestroyLock(mMutex);
} }
void nsPSMBackgroundThread::requestExit() void nsPSMBackgroundThread::requestExit()
@ -76,13 +85,13 @@ void nsPSMBackgroundThread::requestExit()
return; return;
{ {
MutexAutoLock threadLock(mMutex); nsAutoLock threadLock(mMutex);
if (mExitRequested) if (mExitRequested)
return; return;
mExitRequested = PR_TRUE; mExitRequested = PR_TRUE;
mCond.NotifyAll(); PR_NotifyAllCondVar(mCond);
} }
PR_JoinThread(mThreadHandle); PR_JoinThread(mThreadHandle);

View File

@ -40,8 +40,6 @@
#include "nspr.h" #include "nspr.h"
#include "nscore.h" #include "nscore.h"
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
class nsPSMBackgroundThread class nsPSMBackgroundThread
{ {
@ -56,10 +54,10 @@ protected:
// and to protect access to mExitRequested. // and to protect access to mExitRequested.
// Derived classes may use it to protect additional // Derived classes may use it to protect additional
// resources. // resources.
mozilla::Mutex mMutex; PRLock *mMutex;
// Used to signal the thread's Run loop // Used to signal the thread's Run loop
mozilla::CondVar mCond; PRCondVar *mCond;
// Has termination of the SSL thread been requested? // Has termination of the SSL thread been requested?
PRBool mExitRequested; PRBool mExitRequested;

View File

@ -43,8 +43,6 @@
#include "nsPKCS11Slot.h" #include "nsPKCS11Slot.h"
#include "nsProtectedAuthThread.h" #include "nsProtectedAuthThread.h"
using namespace mozilla;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtectedAuthThread, nsIProtectedAuthThread) NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtectedAuthThread, nsIProtectedAuthThread)
static void PR_CALLBACK nsProtectedAuthThreadRunner(void *arg) static void PR_CALLBACK nsProtectedAuthThreadRunner(void *arg)
@ -54,7 +52,7 @@ static void PR_CALLBACK nsProtectedAuthThreadRunner(void *arg)
} }
nsProtectedAuthThread::nsProtectedAuthThread() nsProtectedAuthThread::nsProtectedAuthThread()
: mMutex("nsProtectedAuthThread.mMutex") : mMutex(nsnull)
, mIAmRunning(PR_FALSE) , mIAmRunning(PR_FALSE)
, mStatusObserverNotified(PR_FALSE) , mStatusObserverNotified(PR_FALSE)
, mLoginReady(PR_FALSE) , mLoginReady(PR_FALSE)
@ -63,15 +61,21 @@ nsProtectedAuthThread::nsProtectedAuthThread()
, mLoginResult(SECFailure) , mLoginResult(SECFailure)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mMutex = PR_NewLock();
} }
nsProtectedAuthThread::~nsProtectedAuthThread() nsProtectedAuthThread::~nsProtectedAuthThread()
{ {
if (mMutex)
PR_DestroyLock(mMutex);
} }
NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver) NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver)
{ {
NS_ENSURE_ARG(aObserver); NS_ENSURE_ARG(aObserver);
if (!mMutex)
return NS_ERROR_FAILURE;
if (!mSlot) if (!mSlot)
// We need pointer to the slot // We need pointer to the slot
@ -86,9 +90,10 @@ NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
MutexAutoLock lock(mMutex); PR_Lock(mMutex);
if (mIAmRunning || mLoginReady) { if (mIAmRunning || mLoginReady) {
PR_Unlock(mMutex);
return NS_OK; return NS_OK;
} }
@ -102,26 +107,31 @@ NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver)
// we might want to return "thread started ok" to caller in the future // we might want to return "thread started ok" to caller in the future
NS_ASSERTION(mThreadHandle, "Could not create nsProtectedAuthThreadRunner thread\n"); NS_ASSERTION(mThreadHandle, "Could not create nsProtectedAuthThreadRunner thread\n");
PR_Unlock(mMutex);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsProtectedAuthThread::GetTokenName(nsAString &_retval) NS_IMETHODIMP nsProtectedAuthThread::GetTokenName(nsAString &_retval)
{ {
MutexAutoLock lock(mMutex); PR_Lock(mMutex);
// Get token name // Get token name
CopyUTF8toUTF16(nsDependentCString(PK11_GetTokenName(mSlot)), _retval); CopyUTF8toUTF16(nsDependentCString(PK11_GetTokenName(mSlot)), _retval);
PR_Unlock(mMutex);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval) NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval)
{ {
nsRefPtr<nsPKCS11Slot> slot; PR_Lock(mMutex);
{
MutexAutoLock lock(mMutex); nsRefPtr<nsPKCS11Slot> slot = new nsPKCS11Slot(mSlot);
slot = new nsPKCS11Slot(mSlot);
} PR_Unlock(mMutex);
if (!slot) if (!slot)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -130,9 +140,11 @@ NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval)
void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot) void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot)
{ {
MutexAutoLock lock(mMutex); PR_Lock(mMutex);
mSlot = (aSlot) ? PK11_ReferenceSlot(aSlot) : 0; mSlot = (aSlot) ? PK11_ReferenceSlot(aSlot) : 0;
PR_Unlock(mMutex);
} }
SECStatus nsProtectedAuthThread::GetResult() SECStatus nsProtectedAuthThread::GetResult()
@ -147,28 +159,29 @@ void nsProtectedAuthThread::Run(void)
mLoginResult = PK11_CheckUserPassword(mSlot, 0); mLoginResult = PK11_CheckUserPassword(mSlot, 0);
nsCOMPtr<nsIObserver> observer; nsCOMPtr<nsIObserver> observer;
PR_Lock(mMutex);
mLoginReady = PR_TRUE;
mIAmRunning = PR_FALSE;
// Forget the slot
if (mSlot)
{ {
MutexAutoLock lock(mMutex); PK11_FreeSlot(mSlot);
mSlot = 0;
mLoginReady = PR_TRUE;
mIAmRunning = PR_FALSE;
// Forget the slot
if (mSlot)
{
PK11_FreeSlot(mSlot);
mSlot = 0;
}
if (!mStatusObserverNotified)
{
observer = mStatusObserver;
}
mStatusObserver = nsnull;
mStatusObserverNotified = PR_TRUE;
} }
if (!mStatusObserverNotified)
{
observer = mStatusObserver;
}
mStatusObserver = nsnull;
mStatusObserverNotified = PR_TRUE;
PR_Unlock(mMutex);
if (observer) if (observer)
observer->Observe(nsnull, "operation-completed", nsnull); observer->Observe(nsnull, "operation-completed", nsnull);
} }

View File

@ -41,13 +41,12 @@
#include "keyhi.h" #include "keyhi.h"
#include "nspr.h" #include "nspr.h"
#include "mozilla/Mutex.h"
#include "nsIProtectedAuthThread.h" #include "nsIProtectedAuthThread.h"
class nsProtectedAuthThread : public nsIProtectedAuthThread class nsProtectedAuthThread : public nsIProtectedAuthThread
{ {
private: private:
mozilla::Mutex mMutex; PRLock *mMutex;
nsCOMPtr<nsIObserver> mStatusObserver; nsCOMPtr<nsIObserver> mStatusObserver;

View File

@ -46,6 +46,7 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "nsPromiseFlatString.h" #include "nsPromiseFlatString.h"
#include "nsStringBuffer.h" #include "nsStringBuffer.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nspr.h" #include "nspr.h"
#include "pk11pub.h" #include "pk11pub.h"
@ -53,22 +54,21 @@
#include "sechash.h" #include "sechash.h"
#include "nsNSSCleaner.h" #include "nsNSSCleaner.h"
using namespace mozilla;
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate) NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsRecentBadCertsService, NS_IMPL_THREADSAFE_ISUPPORTS1(nsRecentBadCertsService,
nsIRecentBadCertsService) nsIRecentBadCertsService)
nsRecentBadCertsService::nsRecentBadCertsService() nsRecentBadCertsService::nsRecentBadCertsService()
:monitor("nsRecentBadCertsService.monitor") :mNextStorePosition(0)
,mNextStorePosition(0)
{ {
monitor = nsAutoMonitor::NewMonitor("security.recentBadCertsMonitor");
} }
nsRecentBadCertsService::~nsRecentBadCertsService() nsRecentBadCertsService::~nsRecentBadCertsService()
{ {
if (monitor)
nsAutoMonitor::DestroyMonitor(monitor);
} }
nsresult nsresult
@ -99,7 +99,7 @@ nsRecentBadCertsService::GetRecentBadCert(const nsAString & aHostNameWithPort,
PRBool isUntrusted = PR_FALSE; PRBool isUntrusted = PR_FALSE;
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
for (size_t i=0; i<const_recently_seen_list_size; ++i) { for (size_t i=0; i<const_recently_seen_list_size; ++i) {
if (mCerts[i].mHostWithPort.Equals(aHostNameWithPort)) { if (mCerts[i].mHostWithPort.Equals(aHostNameWithPort)) {
SECStatus srv = SECITEM_CopyItem(nsnull, &foundDER, &mCerts[i].mDERCert); SECStatus srv = SECITEM_CopyItem(nsnull, &foundDER, &mCerts[i].mDERCert);
@ -172,7 +172,7 @@ nsRecentBadCertsService::AddBadCert(const nsAString &hostWithPort,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
{ {
MonitorAutoEnter lock(monitor); nsAutoMonitor lock(monitor);
RecentBadCert &updatedEntry = mCerts[mNextStorePosition]; RecentBadCert &updatedEntry = mCerts[mNextStorePosition];
++mNextStorePosition; ++mNextStorePosition;

View File

@ -40,10 +40,10 @@
#ifndef __RECENTBADCERTS_H__ #ifndef __RECENTBADCERTS_H__
#define __RECENTBADCERTS_H__ #define __RECENTBADCERTS_H__
#include "mozilla/Monitor.h"
#include "nsIRecentBadCertsService.h" #include "nsIRecentBadCertsService.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsString.h" #include "nsString.h"
#include "prmon.h"
#include "secitem.h" #include "secitem.h"
class RecentBadCert class RecentBadCert
@ -105,7 +105,7 @@ public:
nsresult Init(); nsresult Init();
protected: protected:
mozilla::Monitor monitor; PRMonitor *monitor;
enum {const_recently_seen_list_size = 5}; enum {const_recently_seen_list_size = 5};
RecentBadCert mCerts[const_recently_seen_list_size]; RecentBadCert mCerts[const_recently_seen_list_size];

Some files were not shown because too many files have changed in this diff Show More