Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg

Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
This commit is contained in:
Chris Jones ext:(%20and%20Kyle%20Huey%20%3Ckhuey%40kylehuey.com%3E) 2011-03-31 23:29:02 -05:00
parent 57daf2f775
commit 0bb511a3d7
165 changed files with 1383 additions and 2723 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "prlock.h"
#include "nsRegion.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
@ -109,14 +108,7 @@ class RgnRectMemoryAllocator
nsRegion::RgnRect* mFreeListHead;
PRUint32 mFreeEntries;
void* mChunkListHead;
#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)
#if defined (DEBUG)
NS_DECL_OWNINGTHREAD
void InitLock () { NS_ASSERT_OWNINGTHREAD (RgnRectMemoryAllocator); }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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