зеркало из https://github.com/mozilla/pjs.git
Fire assertions when guard objects are used as temporaries. (Bug 531460) r=cjones
This commit is contained in:
Родитель
74f53c2869
Коммит
eca80ee500
|
@ -173,13 +173,18 @@ namespace mozilla {
|
|||
* }
|
||||
*/
|
||||
template <class T>
|
||||
class AutoRestore
|
||||
class NS_STACK_CLASS AutoRestore
|
||||
{
|
||||
private:
|
||||
T& mLocation;
|
||||
T mValue;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
public:
|
||||
AutoRestore(T& aValue) : mLocation(aValue), mValue(aValue) {}
|
||||
AutoRestore(T& aValue MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mLocation(aValue), mValue(aValue)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
~AutoRestore() { mLocation = mValue; }
|
||||
};
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "prlock.h"
|
||||
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/BlockingResourceBase.h"
|
||||
|
||||
//
|
||||
|
@ -173,9 +174,10 @@ public:
|
|||
* @param aLock A valid mozilla::Mutex* returned by
|
||||
* mozilla::Mutex::NewMutex.
|
||||
**/
|
||||
MutexAutoLock(mozilla::Mutex& aLock) :
|
||||
MutexAutoLock(mozilla::Mutex& aLock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
|
||||
mLock(&aLock)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
NS_ASSERTION(mLock, "null mutex");
|
||||
mLock->Lock();
|
||||
}
|
||||
|
@ -192,6 +194,7 @@ private:
|
|||
static void operator delete(void*);
|
||||
|
||||
mozilla::Mutex* mLock;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
|
||||
|
@ -205,9 +208,10 @@ private:
|
|||
class NS_COM_GLUE NS_STACK_CLASS MutexAutoUnlock
|
||||
{
|
||||
public:
|
||||
MutexAutoUnlock(mozilla::Mutex& aLock) :
|
||||
MutexAutoUnlock(mozilla::Mutex& aLock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
|
||||
mLock(&aLock)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
NS_ASSERTION(mLock, "null lock");
|
||||
mLock->Unlock();
|
||||
}
|
||||
|
@ -225,6 +229,7 @@ private:
|
|||
static void operator delete(void*);
|
||||
|
||||
mozilla::Mutex* mLock;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -109,13 +109,14 @@
|
|||
#include "nscore.h"
|
||||
#include "prlock.h"
|
||||
#include "prlog.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
|
||||
/**
|
||||
* nsAutoLockBase
|
||||
* This is the base class for the stack-based locking objects.
|
||||
* Clients of derived classes need not play with this superclass.
|
||||
**/
|
||||
class NS_COM_GLUE nsAutoLockBase {
|
||||
class NS_COM_GLUE NS_STACK_CLASS nsAutoLockBase {
|
||||
friend class nsAutoUnlockBase;
|
||||
|
||||
protected:
|
||||
|
@ -146,7 +147,7 @@ protected:
|
|||
* This is the base class for stack-based unlocking objects.
|
||||
* It unlocks locking objects based on nsAutoLockBase.
|
||||
**/
|
||||
class NS_COM_GLUE nsAutoUnlockBase {
|
||||
class NS_COM_GLUE NS_STACK_CLASS nsAutoUnlockBase {
|
||||
protected:
|
||||
nsAutoUnlockBase() {}
|
||||
|
||||
|
@ -165,10 +166,11 @@ protected:
|
|||
* nsAutoLock
|
||||
* Stack-based locking object for PRLock.
|
||||
**/
|
||||
class NS_COM_GLUE nsAutoLock : public nsAutoLockBase {
|
||||
class NS_COM_GLUE NS_STACK_CLASS nsAutoLock : public nsAutoLockBase {
|
||||
private:
|
||||
PRLock* mLock;
|
||||
PRBool mLocked;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// construct or assign an nsAutoLock object incorrectly.
|
||||
|
@ -208,10 +210,11 @@ public:
|
|||
* @param aLock A valid PRLock* returned from the NSPR's
|
||||
* PR_NewLock() function.
|
||||
**/
|
||||
nsAutoLock(PRLock* aLock)
|
||||
nsAutoLock(PRLock* aLock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: nsAutoLockBase(aLock, eAutoLock),
|
||||
mLock(aLock),
|
||||
mLocked(PR_TRUE) {
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
PR_ASSERT(mLock);
|
||||
|
||||
// This will assert deep in the bowels of NSPR if you attempt
|
||||
|
@ -250,16 +253,18 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class nsAutoUnlock : private nsAutoUnlockBase
|
||||
class NS_STACK_CLASS nsAutoUnlock : private nsAutoUnlockBase
|
||||
{
|
||||
private:
|
||||
PRLock *mLock;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
public:
|
||||
nsAutoUnlock(PRLock *lock) :
|
||||
nsAutoUnlock(PRLock *lock MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
|
||||
nsAutoUnlockBase(lock),
|
||||
mLock(lock)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
|
||||
|
@ -272,7 +277,7 @@ public:
|
|||
#include "nsError.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
class NS_COM_GLUE nsAutoMonitor : public nsAutoLockBase {
|
||||
class NS_COM_GLUE NS_STACK_CLASS nsAutoMonitor : public nsAutoLockBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -295,10 +300,11 @@ public:
|
|||
* @param mon A valid PRMonitor* returned from
|
||||
* nsAutoMonitor::NewMonitor().
|
||||
**/
|
||||
nsAutoMonitor(PRMonitor* mon)
|
||||
nsAutoMonitor(PRMonitor* mon MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: nsAutoLockBase((void*)mon, eAutoMonitor),
|
||||
mMonitor(mon), mLockCount(0)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
NS_ASSERTION(mMonitor, "null monitor");
|
||||
if (mMonitor) {
|
||||
PR_EnterMonitor(mMonitor);
|
||||
|
@ -361,6 +367,7 @@ public:
|
|||
private:
|
||||
PRMonitor* mMonitor;
|
||||
PRInt32 mLockCount;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// construct or assign an nsAutoLock object incorrectly.
|
||||
|
@ -386,12 +393,13 @@ private:
|
|||
#include "prcmon.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class NS_COM_GLUE nsAutoCMonitor : public nsAutoLockBase {
|
||||
class NS_COM_GLUE NS_STACK_CLASS nsAutoCMonitor : public nsAutoLockBase {
|
||||
public:
|
||||
nsAutoCMonitor(void* lockObject)
|
||||
nsAutoCMonitor(void* lockObject MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: nsAutoLockBase(lockObject, eAutoCMonitor),
|
||||
mLockObject(lockObject), mLockCount(0)
|
||||
{
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
NS_ASSERTION(lockObject, "null lock object");
|
||||
PR_CEnterMonitor(mLockObject);
|
||||
mLockCount = 1;
|
||||
|
@ -428,6 +436,7 @@ public:
|
|||
private:
|
||||
void* mLockObject;
|
||||
PRInt32 mLockCount;
|
||||
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
// Not meant to be implemented. This makes it a compiler error to
|
||||
// construct or assign an nsAutoLock object incorrectly.
|
||||
|
|
Загрузка…
Ссылка в новой задаче