mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Deadlock detection hacks.
This commit is contained in:
parent
a00bee9700
commit
154f675bda
@ -32,6 +32,7 @@ XPIDLSRCS = \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsAutoLock.cpp \
|
||||
nsEventQueue.cpp \
|
||||
nsEventQueueService.cpp \
|
||||
nsThread.cpp \
|
||||
|
@ -46,6 +46,7 @@ LINCS = \
|
||||
LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsAutoLock.obj \
|
||||
.\$(OBJDIR)\nsEventQueue.obj \
|
||||
.\$(OBJDIR)\nsEventQueueService.obj \
|
||||
.\$(OBJDIR)\nsThread.obj \
|
||||
|
@ -73,11 +73,29 @@
|
||||
#include "prlock.h"
|
||||
#include "prlog.h"
|
||||
|
||||
class NS_COM nsAutoLockBase {
|
||||
protected:
|
||||
nsAutoLockBase() {}
|
||||
enum nsAutoLockType {eAutoLock, eAutoMonitor, eAutoCMonitor};
|
||||
|
||||
#ifdef DEBUG
|
||||
nsAutoLockBase(void* addr, nsAutoLockType type);
|
||||
~nsAutoLockBase();
|
||||
|
||||
void* mAddr;
|
||||
nsAutoLockBase* mDown;
|
||||
enum nsAutoLockType mType;
|
||||
#else
|
||||
nsAutoLockBase(void* addr, nsAutoLockType type) {}
|
||||
~nsAutoLockBase() {}
|
||||
#endif
|
||||
};
|
||||
|
||||
// If you ever decide that you need to add a non-inline method to this
|
||||
// class, be sure to change the class declaration to "class NS_COM
|
||||
// nsAutoLock".
|
||||
|
||||
class nsAutoLock {
|
||||
class NS_COM nsAutoLock : public nsAutoLockBase {
|
||||
private:
|
||||
PRLock* mLock;
|
||||
|
||||
@ -99,7 +117,9 @@ private:
|
||||
static void operator delete(void* /*memory*/) {}
|
||||
|
||||
public:
|
||||
nsAutoLock(PRLock* aLock) : mLock(aLock) {
|
||||
nsAutoLock(PRLock* aLock)
|
||||
: nsAutoLockBase(aLock, eAutoLock),
|
||||
mLock(aLock) {
|
||||
PR_ASSERT(mLock);
|
||||
|
||||
// This will assert deep in the bowels of NSPR if you attempt
|
||||
@ -130,21 +150,28 @@ public:
|
||||
#include "prcmon.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsAutoMonitor {
|
||||
class NS_COM nsAutoMonitor : public nsAutoLockBase {
|
||||
public:
|
||||
static PRMonitor* NewMonitor(const char* name);
|
||||
static void DestroyMonitor(PRMonitor* mon);
|
||||
|
||||
nsAutoMonitor(PRMonitor* mon)
|
||||
: mMonitor(mon)
|
||||
: nsAutoLockBase((void*)mon, eAutoMonitor),
|
||||
mMonitor(mon)
|
||||
{
|
||||
NS_ASSERTION(mMonitor, "null lock object");
|
||||
NS_ASSERTION(mMonitor, "null monitor");
|
||||
PR_EnterMonitor(mMonitor);
|
||||
}
|
||||
|
||||
~nsAutoMonitor() {
|
||||
PRStatus status;
|
||||
status = PR_ExitMonitor(mMonitor);
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_CExitMonitor failed");
|
||||
// inline Exit to avoid imposing any penalty on Exit non-users
|
||||
PRStatus status = PR_ExitMonitor(mMonitor);
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed");
|
||||
}
|
||||
|
||||
void Enter();
|
||||
void Exit();
|
||||
|
||||
nsresult Wait(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT) {
|
||||
return PR_Wait(mMonitor, interval) == PR_SUCCESS
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
@ -189,21 +216,25 @@ private:
|
||||
#include "prcmon.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsAutoCMonitor {
|
||||
class NS_COM nsAutoCMonitor : public nsAutoLockBase {
|
||||
public:
|
||||
nsAutoCMonitor(void* lockObject)
|
||||
: mLockObject(lockObject)
|
||||
: nsAutoLockBase(lockObject, eAutoCMonitor),
|
||||
mLockObject(lockObject)
|
||||
{
|
||||
NS_ASSERTION(lockObject, "null lock object");
|
||||
PR_CEnterMonitor(mLockObject);
|
||||
}
|
||||
|
||||
~nsAutoCMonitor() {
|
||||
PRStatus status;
|
||||
status = PR_CExitMonitor(mLockObject);
|
||||
// inline Exit to avoid imposing any penalty on Exit non-users
|
||||
PRStatus status = PR_CExitMonitor(mLockObject);
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_CExitMonitor failed");
|
||||
}
|
||||
|
||||
void Enter();
|
||||
void Exit();
|
||||
|
||||
nsresult Wait(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT) {
|
||||
return PR_CWait(mLockObject, interval) == PR_SUCCESS
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
@ -241,4 +272,3 @@ private:
|
||||
};
|
||||
|
||||
#endif // nsAutoLock_h__
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user