Bug 323195 - XPCAutoUnlock messes with detection of potential deadlocks, patch by Matthew Gertner, r=brendan

This commit is contained in:
martijn.martijn%gmail.com 2006-07-29 14:45:09 +00:00
Родитель 4d0b002ae5
Коммит 584a33c71c
3 изменённых файлов: 47 добавлений и 12 удалений

Просмотреть файл

@ -336,20 +336,10 @@ private:
/************************************************/
class XPCAutoUnlock : public nsAutoLockBase {
class XPCAutoUnlock : public nsAutoUnlockBase {
public:
static XPCLock* NewLock(const char* name)
{return nsAutoMonitor::NewMonitor(name);}
static void DestroyLock(XPCLock* lock)
{nsAutoMonitor::DestroyMonitor(lock);}
XPCAutoUnlock(XPCLock* lock)
#ifdef DEBUG
: nsAutoLockBase(lock ? (void*) lock : (void*) this, eAutoMonitor),
#else
: nsAutoLockBase(lock, eAutoMonitor),
#endif
: nsAutoUnlockBase(lock),
mLock(lock)
{
if(mLock)

Просмотреть файл

@ -349,6 +349,29 @@ void nsAutoLockBase::Hide()
prev->mDown = mDown;
}
nsAutoUnlockBase::nsAutoUnlockBase(void* addr)
{
if (addr)
{
nsAutoLockBase* curr = (nsAutoLockBase*) PR_GetThreadPrivate(LockStackTPI);
while (curr && curr->mAddr != addr)
curr = curr->mDown;
mLock = curr;
}
else
mLock = nsnull;
if (mLock)
mLock->Hide();
}
nsAutoUnlockBase::~nsAutoUnlockBase()
{
if (mLock)
mLock->Show();
}
#endif /* DEBUG */
PRMonitor* nsAutoMonitor::NewMonitor(const char* name)

Просмотреть файл

@ -116,6 +116,8 @@
* Clients of derived classes need not play with this superclass.
**/
class NS_COM nsAutoLockBase {
friend class nsAutoUnlockBase;
protected:
nsAutoLockBase() {}
enum nsAutoLockType {eAutoLock, eAutoMonitor, eAutoCMonitor};
@ -139,6 +141,26 @@ protected:
#endif
};
/**
* nsAutoUnlockBase
* This is the base class for stack-based unlocking objects.
* It unlocks locking objects based on nsAutoLockBase.
**/
class NS_COM nsAutoUnlockBase {
protected:
nsAutoUnlockBase() {}
#ifdef DEBUG
nsAutoUnlockBase(void* addr);
~nsAutoUnlockBase();
nsAutoLockBase* mLock;
#else
nsAutoUnlockBase(void* addr) {}
~nsAutoUnlockBase() {}
#endif
};
/**
* nsAutoLock
* Stack-based locking object for PRLock.