Merge backout

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

View File

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

View File

@ -40,13 +40,11 @@
#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,
@ -211,8 +209,6 @@ 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
@ -433,7 +429,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(MonitorAutoEnter& aMonitor);
void CloseInternal(nsAutoMonitor* aMonitor);
// Update mPrincipal given that data has been received from aPrincipal
void UpdatePrincipal(nsIPrincipal* aPrincipal);

View File

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

View File

@ -48,7 +48,6 @@
#include "nsITimer.h"
#include "ImageLayers.h"
#include "mozilla/Monitor.h"
#include "mozilla/Mutex.h"
class nsHTMLMediaElement;
class nsMediaStream;
@ -90,7 +89,6 @@ public:
typedef mozilla::layers::ImageContainer ImageContainer;
typedef mozilla::layers::Image Image;
typedef mozilla::Monitor Monitor;
typedef mozilla::Mutex Mutex;
nsMediaDecoder();
virtual ~nsMediaDecoder();
@ -443,7 +441,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.
Mutex mVideoUpdateLock;
PRLock* 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 namespace mozilla;
using mozilla::TimeStamp;
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("nsMediaChannelStream.mLock"),
mLock(nsAutoLock::NewLock("media.channel.stream")),
mCacheSuspendCount(0)
{
}
@ -80,6 +80,9 @@ 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
@ -268,7 +271,7 @@ nsMediaChannelStream::OnStartRequest(nsIRequest* aRequest)
}
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.Start(TimeStamp::Now());
}
@ -294,7 +297,7 @@ nsMediaChannelStream::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
"How can OnStopRequest fire while we're suspended?");
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now());
}
@ -380,7 +383,7 @@ nsMediaChannelStream::OnDataAvailable(nsIRequest* aRequest,
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.AddBytes(aCount);
}
@ -409,6 +412,8 @@ 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;
@ -544,7 +549,7 @@ void nsMediaChannelStream::CloseChannel()
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now());
}
@ -623,7 +628,7 @@ void nsMediaChannelStream::Suspend(PRBool aCloseImmediately)
element->DownloadSuspended();
} else if (mSuspendCount == 0) {
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.Stop(TimeStamp::Now());
}
mChannel->Suspend();
@ -651,7 +656,7 @@ void nsMediaChannelStream::Resume()
if (mChannel) {
// Just wake up our existing channel
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mChannelStatistics.Start(TimeStamp::Now());
}
// if an error occurs after Resume, assume it's because the server
@ -757,7 +762,7 @@ nsMediaChannelStream::CacheClientSeek(PRInt64 aOffset, PRBool aResume)
// No need to mess with the channel, since we're making a new one
--mSuspendCount;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientSeek(aResume=true) without previous CacheClientSuspend!");
--mCacheSuspendCount;
}
@ -775,7 +780,7 @@ nsresult
nsMediaChannelStream::CacheClientSuspend()
{
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
++mCacheSuspendCount;
}
Suspend(PR_FALSE);
@ -789,7 +794,7 @@ nsMediaChannelStream::CacheClientResume()
{
Resume();
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
NS_ASSERTION(mCacheSuspendCount > 0, "CacheClientResume without previous CacheClientSuspend!");
--mCacheSuspendCount;
}
@ -819,14 +824,14 @@ nsMediaChannelStream::IsDataCachedToEndOfStream(PRInt64 aOffset)
PRBool
nsMediaChannelStream::IsSuspendedByCache()
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
return mCacheSuspendCount > 0;
}
PRBool
nsMediaChannelStream::IsSuspended()
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
return mSuspendCount > 0;
}
@ -857,7 +862,7 @@ nsMediaChannelStream::Unpin()
double
nsMediaChannelStream::GetDownloadRate(PRPackedBool* aIsReliable)
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
return mChannelStatistics.GetRate(TimeStamp::Now(), aIsReliable);
}
@ -872,11 +877,14 @@ class nsMediaFileStream : public nsMediaStream
public:
nsMediaFileStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
nsMediaStream(aDecoder, aChannel, aURI), mSize(-1),
mLock("nsMediaFileStream.mLock")
mLock(nsAutoLock::NewLock("media.file.stream"))
{
}
~nsMediaFileStream()
{
if (mLock) {
nsAutoLock::DestroyLock(mLock);
}
}
// Main thread
@ -927,7 +935,7 @@ private:
// Read or Seek is in progress since it resets various internal
// values to null.
// This lock protects mSeekable and mInput.
Mutex mLock;
PRLock* mLock;
// Seekable stream interface to file. This can be used from any
// thread.
@ -1033,7 +1041,7 @@ nsresult nsMediaFileStream::Close()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (mChannel) {
mChannel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
mChannel = nsnull;
@ -1079,7 +1087,7 @@ nsMediaStream* nsMediaFileStream::CloneData(nsMediaDecoder* aDecoder)
nsresult nsMediaFileStream::ReadFromCache(char* aBuffer, PRInt64 aOffset, PRUint32 aCount)
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (!mInput || !mSeekable)
return NS_ERROR_FAILURE;
PRInt64 offset = 0;
@ -1108,7 +1116,7 @@ nsresult nsMediaFileStream::ReadFromCache(char* aBuffer, PRInt64 aOffset, PRUint
nsresult nsMediaFileStream::Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes)
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (!mInput)
return NS_ERROR_FAILURE;
return mInput->Read(aBuffer, aCount, aBytes);
@ -1118,7 +1126,7 @@ nsresult nsMediaFileStream::Seek(PRInt32 aWhence, PRInt64 aOffset)
{
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (!mSeekable)
return NS_ERROR_FAILURE;
return mSeekable->Seek(aWhence, aOffset);
@ -1128,7 +1136,7 @@ PRInt64 nsMediaFileStream::Tell()
{
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (!mSeekable)
return 0;

View File

@ -38,7 +38,6 @@
#if !defined(nsMediaStream_h_)
#define nsMediaStream_h_
#include "mozilla/Mutex.h"
#include "mozilla/XPCOM.h"
#include "nsIChannel.h"
#include "nsIPrincipal.h"
@ -46,6 +45,7 @@
#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,8 +344,6 @@ protected:
*/
class nsMediaChannelStream : public nsMediaStream
{
typedef mozilla::Mutex Mutex;
public:
nsMediaChannelStream(nsMediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI);
~nsMediaChannelStream();
@ -470,7 +468,7 @@ protected:
nsMediaCacheStream mCacheStream;
// This lock protects mChannelStatistics and mCacheSuspendCount
Mutex mLock;
PRLock* mLock;
nsChannelStatistics mChannelStatistics;
PRUint32 mCacheSuspendCount;
};

View File

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

View File

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

View File

@ -50,6 +50,7 @@
#include "nsPIDOMWindow.h"
// Other includes
#include "nsAutoLock.h"
#include "nsContentUtils.h"
#include "nsDOMJSUtils.h"
#include "nsProxyRelease.h"
@ -59,15 +60,13 @@
#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("nsDOMWorkerPool.mMonitor"),
mMonitor(nsnull),
mCanceled(PR_FALSE),
mSuspended(PR_FALSE),
mWindowID(aDocument ? aDocument->OuterWindowID() : 0)
@ -90,6 +89,10 @@ nsDOMWorkerPool::~nsDOMWorkerPool()
if (document) {
NS_ProxyRelease(mainThread, document, PR_FALSE);
}
if (mMonitor) {
nsAutoMonitor::DestroyMonitor(mMonitor);
}
}
NS_IMPL_THREADSAFE_ADDREF(nsDOMWorkerPool)
@ -99,6 +102,10 @@ 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;
}
@ -110,7 +117,7 @@ nsDOMWorkerPool::NoteWorker(nsDOMWorker* aWorker)
PRBool suspendWorker;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
if (mCanceled) {
return NS_ERROR_ABORT;
@ -137,7 +144,7 @@ nsDOMWorkerPool::NoteDyingWorker(nsDOMWorker* aWorker)
PRBool removeFromThreadService = PR_FALSE;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
NS_ASSERTION(mWorkers.Contains(aWorker), "Worker from a different pool?!");
mWorkers.RemoveElement(aWorker);
@ -156,7 +163,7 @@ nsDOMWorkerPool::NoteDyingWorker(nsDOMWorker* aWorker)
void
nsDOMWorkerPool::GetWorkers(nsTArray<nsDOMWorker*>& aArray)
{
mMonitor.AssertCurrentThreadIn();
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMonitor);
NS_ASSERTION(!aArray.Length(), "Should be empty!");
#ifdef DEBUG
@ -174,7 +181,7 @@ nsDOMWorkerPool::Cancel()
nsAutoTArray<nsDOMWorker*, 10> workers;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
mCanceled = PR_TRUE;
@ -186,7 +193,7 @@ nsDOMWorkerPool::Cancel()
for (PRUint32 index = 0; index < count; index++) {
workers[index]->Cancel();
}
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
mon.NotifyAll();
}
}
@ -198,7 +205,7 @@ nsDOMWorkerPool::Suspend()
nsAutoTArray<nsDOMWorker*, 10> workers;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
NS_ASSERTION(!mSuspended, "Suspended more than once!");
mSuspended = PR_TRUE;
@ -219,7 +226,7 @@ nsDOMWorkerPool::Resume()
nsAutoTArray<nsDOMWorker*, 10> workers;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
NS_ASSERTION(mSuspended, "Not suspended!");
mSuspended = PR_FALSE;
@ -232,7 +239,7 @@ nsDOMWorkerPool::Resume()
for (PRUint32 index = 0; index < count; index++) {
workers[index]->Resume();
}
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor 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,8 +55,6 @@ class nsIScriptGlobalObject;
class nsDOMWorkerPool
{
typedef mozilla::Monitor Monitor;
public:
nsDOMWorkerPool(nsIScriptGlobalObject* aGlobalObject,
nsIDocument* aDocument);
@ -81,7 +79,7 @@ public:
nsresult NoteWorker(nsDOMWorker* aWorker);
void NoteDyingWorker(nsDOMWorker* aWorker);
Monitor& GetMonitor() {
PRMonitor* Monitor() {
return mMonitor;
}
@ -107,7 +105,7 @@ private:
nsTArray<nsDOMWorker*> mWorkers;
// Monitor for suspending and resuming workers.
Monitor mMonitor;
PRMonitor* mMonitor;
PRPackedBool mCanceled;
PRPackedBool mSuspended;

View File

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

View File

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

View File

@ -45,6 +45,7 @@
#include "nsIXPConnect.h"
// Other includes
#include "nsAutoLock.h"
#include "nsAXPCNativeCallContext.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
@ -58,8 +59,6 @@
#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
@ -494,7 +493,7 @@ nsDOMWorkerXHR::Cancel()
{
// This lock is here to prevent a race between Cancel and GetUpload, not to
// protect mCanceled.
MutexAutoLock lock(mWorker->GetLock());
nsAutoLock lock(mWorker->Lock());
mCanceled = PR_TRUE;
mUpload = nsnull;
@ -830,7 +829,7 @@ nsDOMWorkerXHR::GetUpload(nsIXMLHttpRequestUpload** aUpload)
return NS_ERROR_ABORT;
}
MutexAutoLock lock(worker->GetLock());
nsAutoLock lock(worker->Lock());
if (mCanceled) {
return NS_ERROR_ABORT;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -59,6 +59,7 @@
#include "pratom.h"
#include "prmem.h"
#include "nsCOMArray.h"
#include "nsAutoLock.h"
#include "nsTextFormatter.h"
#include "nsIErrorService.h"
#include "nsITimelineService.h"
@ -74,20 +75,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("nsStringBundle.mMonitor"),
mMonitor(0),
mAttemptedLoad(PR_FALSE),
mLoaded(PR_FALSE)
{
@ -111,6 +112,10 @@ 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);
@ -148,7 +153,7 @@ nsStringBundle::LoadProperties()
nsresult
nsStringBundle::GetStringFromID(PRInt32 aID, nsAString& aResult)
{
MonitorAutoEnter automon(mMonitor);
nsAutoMonitor automon(mMonitor);
nsCAutoString name;
name.AppendInt(aID, 10);
@ -269,7 +274,7 @@ nsStringBundle::GetStringFromName(const PRUnichar *aName, PRUnichar **aResult)
rv = LoadProperties();
if (NS_FAILED(rv)) return rv;
MonitorAutoEnter automon(mMonitor);
nsAutoMonitor 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;
mozilla::Monitor mMonitor;
PRMonitor* mMonitor;
PRPackedBool mAttemptedLoad;
PRPackedBool mLoaded;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -383,15 +383,10 @@ OnPluginDestroy(NPP instance);
void
OnShutdown();
/**
* 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();
};
void
EnterAsyncPluginThreadCallLock();
void
ExitAsyncPluginThreadCallLock();
class NPPStack
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -42,7 +42,6 @@
#define ENABLE_SOCKET_TRACING
#endif
#include "mozilla/Mutex.h"
#include "nsSocketTransportService2.h"
#include "nsString.h"
#include "nsCOMPtr.h"
@ -135,8 +134,6 @@ class nsSocketTransport : public nsASocketHandler
, public nsIDNSListener
, public nsIClassInfo
{
typedef mozilla::Mutex Mutex;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITRANSPORT
@ -257,7 +254,7 @@ private:
// socket input/output objects. these may be accessed on any thread with
// the exception of some specific methods (XXX).
Mutex mLock; // protects members in this section
PRLock *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,8 +43,10 @@
#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"
@ -54,8 +56,6 @@
#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("nsSocketTransportService::mLock")
, mLock(nsAutoLock::NewLock("nsSocketTransportService::mLock"))
, mInitialized(PR_FALSE)
, mShuttingDown(PR_FALSE)
, mActiveCount(0)
@ -93,6 +93,9 @@ nsSocketTransportService::~nsSocketTransportService()
{
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
NS_ASSERTION(!mInitialized, "not shutdown properly");
if (mLock)
nsAutoLock::DestroyLock(mLock);
if (mThreadEvent)
PR_DestroyPollableEvent(mThreadEvent);
@ -106,7 +109,7 @@ nsSocketTransportService::~nsSocketTransportService()
already_AddRefed<nsIThread>
nsSocketTransportService::GetThreadSafely()
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
nsIThread* result = mThread;
NS_IF_ADDREF(result);
return result;
@ -380,6 +383,8 @@ 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;
@ -420,7 +425,7 @@ nsSocketTransportService::Init()
if (NS_FAILED(rv)) return rv;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
// Install our mThread, protecting against concurrent readers
thread.swap(mThread);
}
@ -451,7 +456,7 @@ nsSocketTransportService::Shutdown()
return NS_ERROR_UNEXPECTED;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
// signal the socket thread to shutdown
mShuttingDown = PR_TRUE;
@ -464,7 +469,7 @@ nsSocketTransportService::Shutdown()
// join with thread
mThread->Shutdown();
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
// Drop our reference to mThread and make sure that any concurrent
// readers are excluded
mThread = nsnull;
@ -523,7 +528,7 @@ nsSocketTransportService::SetAutodialEnabled(PRBool value)
NS_IMETHODIMP
nsSocketTransportService::OnDispatchedEvent(nsIThreadInternal *thread)
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (mThreadEvent)
PR_SetPollableEvent(mThreadEvent);
return NS_OK;
@ -580,7 +585,7 @@ nsSocketTransportService::Run()
// now that our event queue is empty, check to see if we should exit
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (mShuttingDown)
break;
}
@ -715,7 +720,7 @@ nsSocketTransportService::DoPollIteration(PRBool wait)
// new pollable event. If that fails, we fall back
// on "busy wait".
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
PR_DestroyPollableEvent(mThreadEvent);
mThreadEvent = PR_NewPollableEvent();
}

View File

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

View File

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

View File

@ -34,16 +34,14 @@
*
* ***** 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;
@ -59,7 +57,7 @@ public:
PRBool coalesceAll)
: mSink(sink)
, mTarget(target)
, mLock("nsTransportEventSinkProxy.mLock")
, mLock(nsAutoLock::NewLock("nsTransportEventSinkProxy::mLock"))
, mLastEvent(nsnull)
, mCoalesceAll(coalesceAll)
{
@ -68,6 +66,9 @@ 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);
@ -75,7 +76,7 @@ public:
nsITransportEventSink *mSink;
nsCOMPtr<nsIEventTarget> mTarget;
Mutex mLock;
PRLock *mLock;
nsTransportStatusEvent *mLastEvent;
PRBool mCoalesceAll;
};
@ -102,7 +103,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!
{
MutexAutoLock lock(mProxy->mLock);
nsAutoLock lock(mProxy->mLock);
if (mProxy->mLastEvent == this)
mProxy->mLastEvent = nsnull;
}
@ -132,7 +133,7 @@ nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
nsresult rv = NS_OK;
nsRefPtr<nsTransportStatusEvent> event;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
// try to coalesce events! ;-)
if (mLastEvent && (mCoalesceAll || mLastEvent->mStatus == status)) {
@ -153,7 +154,7 @@ nsTransportEventSinkProxy::OnTransportStatus(nsITransport *transport,
if (NS_FAILED(rv)) {
NS_WARNING("unable to post transport status event");
MutexAutoLock lock(mLock); // cleanup.. don't reference anymore!
nsAutoLock lock(mLock); // cleanup.. don't reference anymore!
mLastEvent = nsnull;
}
}

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(nsHttpActivityDistributor)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpActivityDistributor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpDigestAuth)
#endif // !NECKO_PROTOCOL_http

View File

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

View File

@ -80,8 +80,6 @@
#include "mozilla/net/NeckoCommon.h"
#endif
using namespace mozilla;
/******************************************************************************
* nsCacheProfilePrefObserver
*****************************************************************************/
@ -277,11 +275,12 @@ public:
}
NS_IMETHOD Run()
{
nsCacheServiceAutoLock autoLock;
mozilla::MonitorAutoEnter
autoMonitor(nsCacheService::gService->mMonitor);
#ifdef PR_LOGGING
CACHE_LOG_DEBUG(("nsBlockOnCacheThreadEvent [%p]\n", this));
#endif
nsCacheService::gService->mCondVar.Notify();
autoMonitor.Notify();
return NS_OK;
}
};
@ -810,9 +809,12 @@ nsCacheService::DispatchToCacheIOThread(nsIRunnable* event)
nsresult
nsCacheService::SyncWithCacheIOThread()
{
gService->mLock.AssertCurrentThreadOwns();
NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(),
"not holding cache-lock");
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
@ -823,8 +825,10 @@ nsCacheService::SyncWithCacheIOThread()
return NS_ERROR_UNEXPECTED;
}
Unlock();
// wait until notified, then return
rv = gService->mCondVar.Wait();
rv = autoMonitor.Wait();
Lock();
return rv;
}
@ -981,8 +985,8 @@ nsCacheService * nsCacheService::gService = nsnull;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService)
nsCacheService::nsCacheService()
: mLock("nsCacheService.mLock"),
mCondVar(mLock, "nsCacheService.mCondVar"),
: mLock(nsnull),
mMonitor("block-on-cache-monitor"),
mInitialized(PR_FALSE),
mEnableMemoryDevice(PR_TRUE),
mEnableDiskDevice(PR_TRUE),
@ -1003,6 +1007,13 @@ 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()
@ -1010,6 +1021,7 @@ nsCacheService::~nsCacheService()
if (mInitialized) // Shutdown hasn't been called yet.
(void) Shutdown();
PR_DestroyLock(mLock);
gService = nsnull;
}
@ -1029,6 +1041,9 @@ nsCacheService::Init()
}
#endif
if (mLock == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
CACHE_LOG_INIT();
nsresult rv = NS_NewThread(getter_AddRefs(mCacheIOThread));
@ -2196,18 +2211,25 @@ nsCacheService::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize)
void
nsCacheService::Lock()
{
gService->mLock.Lock();
PR_Lock(gService->mLock);
#if defined(DEBUG)
gService->mLockedThread = PR_GetCurrentThread();
#endif
}
void
nsCacheService::Unlock()
{
gService->mLock.AssertCurrentThreadOwns();
NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(), "oops");
nsTArray<nsISupports*> doomed;
doomed.SwapElements(gService->mDoomedObjects);
gService->mLock.Unlock();
#if defined(DEBUG)
gService->mLockedThread = nsnull;
#endif
PR_Unlock(gService->mLock);
for (PRUint32 i = 0; i < doomed.Length(); ++i)
doomed[i]->Release();
@ -2217,7 +2239,7 @@ void
nsCacheService::ReleaseObject_Locked(nsISupports * obj,
nsIEventTarget * target)
{
gService->mLock.AssertCurrentThreadOwns();
NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(), "oops");
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/CondVar.h"
#include "mozilla/Mutex.h"
#include "mozilla/Monitor.h"
class nsCacheRequest;
class nsCacheProfilePrefObserver;
@ -172,10 +172,6 @@ public:
nsresult Init();
void Shutdown();
static void AssertOwnsLock()
{ gService->mLock.AssertCurrentThreadOwns(); }
private:
friend class nsCacheServiceAutoLock;
friend class nsOfflineCacheDevice;
@ -258,8 +254,13 @@ private:
nsCacheProfilePrefObserver * mObserver;
mozilla::Mutex mLock;
mozilla::CondVar mCondVar;
PRLock * mLock;
mozilla::Monitor mMonitor;
#if defined(DEBUG)
PRThread * mLockedThread; // The thread holding mLock
#endif
nsCOMPtr<nsIThread> mCacheIOThread;

View File

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

View File

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

View File

@ -40,7 +40,7 @@
#include "nsHostResolver.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "mozilla/Mutex.h"
#include "prlock.h"
class nsDNSService : public nsPIDNSService
, public nsIObserver
@ -61,7 +61,7 @@ private:
nsCOMPtr<nsIIDNService> mIDN;
// mLock protects access to mResolver and mIPv4OnlyDomains
mozilla::Mutex mLock;
PRLock *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,5 +69,4 @@ private:
nsAdoptingCString mIPv4OnlyDomains;
PRBool mDisableIPv6;
PRBool mDisablePrefetch;
PRBool mFirstTime;
};

View File

@ -53,10 +53,12 @@
#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"
@ -66,8 +68,6 @@
#include "mozilla/FunctionTimer.h"
using namespace mozilla;
//----------------------------------------------------------------------------
// Use a persistent thread pool in order to avoid spinning up new threads all the time.
@ -181,10 +181,18 @@ 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;
@ -192,7 +200,7 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
rec->_refc = 1; // addref
NS_LOG_ADDREF(rec, 1, "nsHostRecord", sizeof(nsHostRecord));
rec->addr_info_lock = new Mutex("nsHostRecord.addr_info_lock");
rec->addr_info_lock = lock;
rec->addr_info = nsnull;
rec->addr_info_gencnt = 0;
rec->addr = nsnull;
@ -211,7 +219,10 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
nsHostRecord::~nsHostRecord()
{
delete addr_info_lock;
if (addr_info_lock)
PR_DestroyLock(addr_info_lock);
if (addr_info)
PR_FreeAddrInfo(addr_info);
if (addr)
free(addr);
}
@ -319,8 +330,8 @@ nsHostResolver::nsHostResolver(PRUint32 maxCacheEntries,
PRUint32 maxCacheLifetime)
: mMaxCacheEntries(maxCacheEntries)
, mMaxCacheLifetime(maxCacheLifetime)
, mLock("nsHostResolver.mLock")
, mIdleThreadCV(mLock, "nsHostResolver.mIdleThreadCV")
, mLock(nsnull)
, mIdleThreadCV(nsnull)
, mNumIdleThreads(0)
, mThreadCount(0)
, mActiveAnyThreadCount(0)
@ -340,6 +351,12 @@ nsHostResolver::nsHostResolver(PRUint32 maxCacheEntries,
nsHostResolver::~nsHostResolver()
{
if (mIdleThreadCV)
PR_DestroyCondVar(mIdleThreadCV);
if (mLock)
nsAutoLock::DestroyLock(mLock);
PL_DHashTableFinish(&mDB);
}
@ -348,6 +365,14 @@ 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;
@ -393,7 +418,7 @@ nsHostResolver::Shutdown()
PR_INIT_CLIST(&evictionQ);
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
mShutdown = PR_TRUE;
@ -405,7 +430,7 @@ nsHostResolver::Shutdown()
mPendingCount = 0;
if (mNumIdleThreads)
mIdleThreadCV.NotifyAll();
PR_NotifyAllCondVar(mIdleThreadCV);
// empty host database
PL_DHashTableEnumerate(&mDB, HostDB_RemoveEntry, nsnull);
@ -487,7 +512,7 @@ nsHostResolver::ResolveHost(const char *host,
nsRefPtr<nsHostRecord> result;
nsresult status = NS_OK, rv = NS_OK;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
if (mShutdown)
rv = NS_ERROR_NOT_INITIALIZED;
@ -577,7 +602,7 @@ nsHostResolver::ResolveHost(const char *host,
// Move from low to med.
MoveQueue(he->rec, mMediumQ);
he->rec->flags = flags;
mIdleThreadCV.Notify();
PR_NotifyCondVar(mIdleThreadCV);
}
}
}
@ -597,7 +622,7 @@ nsHostResolver::DetachCallback(const char *host,
{
nsRefPtr<nsHostRecord> rec;
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
nsHostKey key = { host, flags, af };
nsHostDBEnt *he = static_cast<nsHostDBEnt *>
@ -628,7 +653,7 @@ nsHostResolver::ConditionallyCreateThread(nsHostRecord *rec)
{
if (mNumIdleThreads) {
// wake up idle thread to process this lookup
mIdleThreadCV.Notify();
PR_NotifyCondVar(mIdleThreadCV);
}
else if ((mThreadCount < HighThreadThreshold) ||
(IsHighPriority(rec->flags) && mThreadCount < MAX_RESOLVER_THREADS)) {
@ -709,7 +734,7 @@ nsHostResolver::GetHostToLookup(nsHostRecord **result)
PRBool timedOut = PR_FALSE;
PRIntervalTime epoch, now, timeout;
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
timeout = (mNumIdleThreads >= HighThreadThreshold) ? mShortIdleTimeout : mLongIdleTimeout;
epoch = PR_IntervalNow();
@ -749,7 +774,7 @@ nsHostResolver::GetHostToLookup(nsHostRecord **result)
// (3) the thread has been idle for too long
mNumIdleThreads++;
mIdleThreadCV.Wait(timeout);
PR_WaitCondVar(mIdleThreadCV, timeout);
mNumIdleThreads--;
now = PR_IntervalNow();
@ -778,7 +803,7 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
PRCList cbs;
PR_INIT_CLIST(&cbs);
{
MutexAutoLock lock(mLock);
nsAutoLock lock(mLock);
// grab list of callbacks to notify
MoveCList(rec->callbacks, cbs);
@ -786,12 +811,11 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
// update record fields. We might have a rec->addr_info already if a
// previous lookup result expired and we're reresolving it..
PRAddrInfo *old_addr_info;
{
MutexAutoLock lock(*rec->addr_info_lock);
old_addr_info = rec->addr_info;
rec->addr_info = result;
rec->addr_info_gencnt++;
}
PR_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,11 +40,10 @@
#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;
@ -86,8 +85,6 @@ struct nsHostKey
*/
class nsHostRecord : public PRCList, public nsHostKey
{
typedef mozilla::Mutex Mutex;
public:
NS_DECL_REFCOUNTED_THREADSAFE(nsHostRecord)
@ -111,7 +108,7 @@ public:
* the other threads just read it. therefore the resolver worker
* thread doesn't need to lock when reading |addr_info|.
*/
Mutex *addr_info_lock;
PRLock *addr_info_lock;
int addr_info_gencnt; /* generation count of |addr_info| */
PRAddrInfo *addr_info;
PRNetAddr *addr;
@ -174,9 +171,6 @@ public:
*/
class nsHostResolver
{
typedef mozilla::CondVar CondVar;
typedef mozilla::Mutex Mutex;
public:
/**
* host resolver instances are reference counted.
@ -253,8 +247,8 @@ private:
PRUint32 mMaxCacheEntries;
PRUint32 mMaxCacheLifetime;
Mutex mLock;
CondVar mIdleThreadCV;
PRLock *mLock;
PRCondVar *mIdleThreadCV; // non-null if idle thread
PRUint32 mNumIdleThreads;
PRUint32 mThreadCount;
PRUint32 mActiveAnyThreadCount;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,8 +53,6 @@
#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.
@ -77,7 +75,7 @@ nsWifiMonitor::DoScanWithCoreWLAN()
nsCOMArray<nsIWifiListener> currentListeners;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -127,7 +125,7 @@ nsWifiMonitor::DoScanWithCoreWLAN()
// wait for some reasonable amount of time. pref?
LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60));
}
while (mKeepGoing);
@ -212,7 +210,7 @@ nsWifiMonitor::DoScanOld()
nsCOMArray<nsIWifiListener> currentListeners;
{
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
if (!mListeners[i].mHasSentData || accessPointsChanged) {
@ -263,7 +261,7 @@ nsWifiMonitor::DoScanOld()
// wait for some reasonable amount of time. pref?
LOG(("waiting on monitor\n"));
MonitorAutoEnter mon(mMonitor);
nsAutoMonitor mon(mMonitor);
mon.Wait(PR_SecondsToInterval(60));
}
while (mKeepGoing);

View File

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

View File

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

View File

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

View File

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

View File

@ -42,7 +42,6 @@
#ifndef nsSecureBrowserUIImpl_h_
#define nsSecureBrowserUIImpl_h_
#include "mozilla/Monitor.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsString.h"
@ -61,6 +60,7 @@
#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:
mozilla::Monitor mMonitor;
PRMonitor *mMonitor;
nsWeakPtr mWindow;
nsCOMPtr<nsINetUtil> mIOService;

View File

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

View File

@ -36,11 +36,10 @@
* ***** 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)
@ -116,10 +115,10 @@ nsresult nsCertVerificationThread::addJob(nsBaseVerificationJob *aJob)
if (!verification_thread_singleton->mThreadHandle)
return NS_ERROR_OUT_OF_MEMORY;
MutexAutoLock threadLock(verification_thread_singleton->mMutex);
nsAutoLock threadLock(verification_thread_singleton->mMutex);
verification_thread_singleton->mJobQ.Push(aJob);
verification_thread_singleton->mCond.NotifyAll();
PR_NotifyAllCondVar(verification_thread_singleton->mCond);
return NS_OK;
}
@ -131,12 +130,12 @@ void nsCertVerificationThread::Run(void)
nsBaseVerificationJob *job = nsnull;
{
MutexAutoLock threadLock(verification_thread_singleton->mMutex);
nsAutoLock threadLock(verification_thread_singleton->mMutex);
while (!mExitRequested && (0 == verification_thread_singleton->mJobQ.GetSize())) {
// no work to do ? let's wait a moment
mCond.Wait();
PR_WaitCondVar(mCond, PR_INTERVAL_NO_TIMEOUT);
}
if (mExitRequested)
@ -153,7 +152,7 @@ void nsCertVerificationThread::Run(void)
}
{
MutexAutoLock threadLock(verification_thread_singleton->mMutex);
nsAutoLock threadLock(verification_thread_singleton->mMutex);
while (verification_thread_singleton->mJobQ.GetSize()) {
nsCertVerificationJob *job =

View File

@ -48,6 +48,7 @@
#include "nsPromiseFlatString.h"
#include "nsProxiedService.h"
#include "nsStringBuffer.h"
#include "nsAutoLock.h"
#include "nspr.h"
#include "pk11pub.h"
#include "certdb.h"
@ -55,9 +56,6 @@
#include "ssl.h" // For SSL_ClearSessionCache
#include "nsNSSCleaner.h"
using namespace mozilla;
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
NS_IMPL_THREADSAFE_ISUPPORTS2(nsClientAuthRememberService,
@ -65,13 +63,15 @@ 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.
MonitorAutoEnter lock(monitor);
nsAutoMonitor lock(monitor);
RemoveAllFromMemory();
}
@ -119,7 +119,7 @@ nsClientAuthRememberService::Observe(nsISupports *aSubject,
void nsClientAuthRememberService::ClearRememberedDecisions()
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor lock(monitor);
RemoveAllFromMemory();
}
@ -165,7 +165,7 @@ nsClientAuthRememberService::RememberDecision(const nsACString & aHostName,
return rv;
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor lock(monitor);
if (aClientCert) {
nsNSSCertificate pipCert(aClientCert);
char *dbkey = NULL;
@ -211,7 +211,7 @@ nsClientAuthRememberService::HasRememberedDecision(const nsACString & aHostName,
nsClientAuthRemember settings;
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor 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);
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor lock(monitor);
nsClientAuthRememberEntry *entry = mSettingsTable.PutEntry(hostCert.get());
if (!entry) {

View File

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

View File

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

View File

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

View File

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

View File

@ -45,8 +45,6 @@
#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);
@ -83,8 +81,10 @@ public:
const PRUint8* mResultData; // not owned, refers to mLoader
PRUint32 mResultLen;
mozilla::Mutex mLock;
mozilla::CondVar mCondition;
nsresult InitLocks();
PRLock *mLock;
PRCondVar *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()
:mutex("nsNSSCertCache.mutex"), mCertList(nsnull)
:mCertList(nsnull)
{
mutex = nsAutoLock::NewLock("nsNSSCertCache::mutex");
}
nsNSSCertCache::~nsNSSCertCache()
@ -69,6 +69,11 @@ void nsNSSCertCache::destructorSafeDestroyNSSReference()
{
if (isAlreadyShutDown())
return;
if (mutex) {
nsAutoLock::DestroyLock(mutex);
mutex = nsnull;
}
}
NS_IMETHODIMP
@ -83,7 +88,7 @@ nsNSSCertCache::CacheAllCerts()
CERTCertList *newList = PK11_ListCerts(PK11CertListUnique, cxt);
if (newList) {
MutexAutoLock lock(mutex);
nsAutoLock lock(mutex);
mCertList = new nsNSSCertList(newList, PR_TRUE); // adopt
}
@ -98,7 +103,7 @@ nsNSSCertCache::CacheCertList(nsIX509CertList *list)
return NS_ERROR_NOT_AVAILABLE;
{
MutexAutoLock lock(mutex);
nsAutoLock lock(mutex);
mCertList = list;
//NS_ADDREF(mCertList);
}
@ -114,7 +119,7 @@ nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list)
return NS_ERROR_NOT_AVAILABLE;
{
MutexAutoLock lock(mutex);
nsAutoLock lock(mutex);
if (!mCertList) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -132,6 +137,6 @@ void* nsNSSCertCache::GetCachedCerts()
if (isAlreadyShutDown())
return nsnull;
MutexAutoLock lock(mutex);
nsAutoLock lock(mutex);
return mCertList->GetRawCertList();
}

View File

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

View File

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

View File

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

View File

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

View File

@ -74,6 +74,7 @@
#include "nsCRT.h"
#include "nsAutoPtr.h"
#include "nsPrintfCString.h"
#include "nsAutoLock.h"
#include "nsSSLThread.h"
#include "nsNSSShutDown.h"
#include "nsSSLStatus.h"
@ -99,7 +100,6 @@
#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) {
delete mutex;
nsAutoLock::DestroyLock(mutex);
mutex = nsnull;
}
@ -1801,7 +1801,7 @@ nsSSLIOLayerHelpers::rememberTolerantSite(PRFileDesc* ssl_layer_fd,
nsCAutoString key;
getSiteKey(socketInfo, key);
MutexAutoLock lock(*mutex);
nsAutoLock 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;
Mutex *nsSSLIOLayerHelpers::mutex = nsnull;
PRLock *nsSSLIOLayerHelpers::mutex = nsnull;
nsCStringHashSet *nsSSLIOLayerHelpers::mTLSIntolerantSites = nsnull;
nsCStringHashSet *nsSSLIOLayerHelpers::mTLSTolerantSites = nsnull;
nsPSMRememberCertErrorsTable *nsSSLIOLayerHelpers::mHostsWithCertErrors = nsnull;
@ -2275,7 +2275,9 @@ nsresult nsSSLIOLayerHelpers::Init()
nsSSLIOLayerMethods.poll = nsSSLIOLayerPoll;
}
mutex = new Mutex("nsSSLIOLayerHelpers.mutex");
mutex = nsAutoLock::NewLock("nsSSLIOLayerHelpers::mutex");
if (!mutex)
return NS_ERROR_OUT_OF_MEMORY;
mSharedPollableEvent = PR_NewPollableEvent();
@ -2313,7 +2315,7 @@ nsresult nsSSLIOLayerHelpers::Init()
void nsSSLIOLayerHelpers::addIntolerantSite(const nsCString &str)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
// Remember intolerant site only if it is not known as tolerant
if (!mTLSTolerantSites->Contains(str))
nsSSLIOLayerHelpers::mTLSIntolerantSites->Put(str);
@ -2321,19 +2323,19 @@ void nsSSLIOLayerHelpers::addIntolerantSite(const nsCString &str)
void nsSSLIOLayerHelpers::removeIntolerantSite(const nsCString &str)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
nsSSLIOLayerHelpers::mTLSIntolerantSites->Remove(str);
}
PRBool nsSSLIOLayerHelpers::isKnownAsIntolerantSite(const nsCString &str)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
return mTLSIntolerantSites->Contains(str);
}
void nsSSLIOLayerHelpers::setRenegoUnrestrictedSites(const nsCString &str)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
if (mRenegoUnrestrictedSites) {
delete mRenegoUnrestrictedSites;
@ -2358,31 +2360,31 @@ void nsSSLIOLayerHelpers::setRenegoUnrestrictedSites(const nsCString &str)
PRBool nsSSLIOLayerHelpers::isRenegoUnrestrictedSite(const nsCString &str)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
return mRenegoUnrestrictedSites->Contains(str);
}
void nsSSLIOLayerHelpers::setTreatUnsafeNegotiationAsBroken(PRBool broken)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
mTreatUnsafeNegotiationAsBroken = broken;
}
PRBool nsSSLIOLayerHelpers::treatUnsafeNegotiationAsBroken()
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
return mTreatUnsafeNegotiationAsBroken;
}
void nsSSLIOLayerHelpers::setWarnLevelMissingRFC5746(PRInt32 level)
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
mWarnLevelMissingRFC5746 = level;
}
PRInt32 nsSSLIOLayerHelpers::getWarnLevelMissingRFC5746()
{
MutexAutoLock lock(*mutex);
nsAutoLock lock(mutex);
return mWarnLevelMissingRFC5746;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,6 +46,7 @@
#include "nsCRT.h"
#include "nsPromiseFlatString.h"
#include "nsStringBuffer.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h"
#include "nspr.h"
#include "pk11pub.h"
@ -53,22 +54,21 @@
#include "sechash.h"
#include "nsNSSCleaner.h"
using namespace mozilla;
NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsRecentBadCertsService,
nsIRecentBadCertsService)
nsRecentBadCertsService::nsRecentBadCertsService()
:monitor("nsRecentBadCertsService.monitor")
,mNextStorePosition(0)
: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;
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor 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);
{
MonitorAutoEnter lock(monitor);
nsAutoMonitor 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:
mozilla::Monitor monitor;
PRMonitor *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