зеркало из https://github.com/mozilla/gecko-dev.git
Bug 832609 - Add mozilla::OffTheBooksMutex, which is just like mozilla::Mutex, except it's not leak-checked. r=khuey
--HG-- extra : rebase_source : 2c06334a5db4c8b57c9a3480a83e543dd98a9b20
This commit is contained in:
Родитель
c002d5a3a3
Коммит
8d14a63fba
|
@ -218,9 +218,9 @@ BlockingResourceBase::PrintCycle(const DDT::ResourceAcquisitionArray* aCycle,
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Debug implementation of Mutex
|
// Debug implementation of (OffTheBooks)Mutex
|
||||||
void
|
void
|
||||||
Mutex::Lock()
|
OffTheBooksMutex::Lock()
|
||||||
{
|
{
|
||||||
CallStack callContext = CallStack();
|
CallStack callContext = CallStack();
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ Mutex::Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Mutex::Unlock()
|
OffTheBooksMutex::Unlock()
|
||||||
{
|
{
|
||||||
Release(); // protected by mLock
|
Release(); // protected by mLock
|
||||||
PRStatus status = PR_Unlock(mLock);
|
PRStatus status = PR_Unlock(mLock);
|
||||||
|
|
|
@ -20,48 +20,44 @@
|
||||||
// locked and unlocked
|
// locked and unlocked
|
||||||
// - MutexAutoUnlock, complementary sibling to MutexAutoLock
|
// - MutexAutoUnlock, complementary sibling to MutexAutoLock
|
||||||
//
|
//
|
||||||
// Using MutexAutoLock/MutexAutoUnlock is MUCH preferred to making bare
|
// - OffTheBooksMutex, a non-recursive mutex that doesn't do leak checking
|
||||||
// calls to Mutex.Lock and Unlock.
|
// - OffTheBooksMutexAuto{Lock,Unlock} - Like MutexAuto{Lock,Unlock}, but for
|
||||||
|
// an OffTheBooksMutex.
|
||||||
|
//
|
||||||
|
// Using MutexAutoLock/MutexAutoUnlock etc. is MUCH preferred to making bare
|
||||||
|
// calls to Lock and Unlock.
|
||||||
//
|
//
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutex
|
* OffTheBooksMutex is identical to Mutex, except that OffTheBooksMutex doesn't
|
||||||
* When possible, use MutexAutoLock/MutexAutoUnlock to lock/unlock this
|
* include leak checking. Sometimes you want to intentionally "leak" a mutex
|
||||||
* mutex within a scope, instead of calling Lock/Unlock directly.
|
* until shutdown; in these cases, OffTheBooksMutex is for you.
|
||||||
**/
|
*/
|
||||||
|
class NS_COM_GLUE OffTheBooksMutex : BlockingResourceBase
|
||||||
class NS_COM_GLUE Mutex : BlockingResourceBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Mutex
|
|
||||||
* @param name A name which can reference this lock
|
* @param name A name which can reference this lock
|
||||||
* @returns If failure, nullptr
|
* @returns If failure, nullptr
|
||||||
* If success, a valid Mutex* which must be destroyed
|
* If success, a valid Mutex* which must be destroyed
|
||||||
* by Mutex::DestroyMutex()
|
* by Mutex::DestroyMutex()
|
||||||
**/
|
**/
|
||||||
Mutex(const char* name) :
|
OffTheBooksMutex(const char* name) :
|
||||||
BlockingResourceBase(name, eMutex)
|
BlockingResourceBase(name, eMutex)
|
||||||
{
|
{
|
||||||
MOZ_COUNT_CTOR(Mutex);
|
|
||||||
mLock = PR_NewLock();
|
mLock = PR_NewLock();
|
||||||
if (!mLock)
|
if (!mLock)
|
||||||
NS_RUNTIMEABORT("Can't allocate mozilla::Mutex");
|
NS_RUNTIMEABORT("Can't allocate mozilla::Mutex");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
~OffTheBooksMutex()
|
||||||
* ~Mutex
|
|
||||||
**/
|
|
||||||
~Mutex()
|
|
||||||
{
|
{
|
||||||
NS_ASSERTION(mLock,
|
NS_ASSERTION(mLock,
|
||||||
"improperly constructed Lock or double free");
|
"improperly constructed Lock or double free");
|
||||||
// NSPR does consistency checks for us
|
// NSPR does consistency checks for us
|
||||||
PR_DestroyLock(mLock);
|
PR_DestroyLock(mLock);
|
||||||
mLock = 0;
|
mLock = 0;
|
||||||
MOZ_COUNT_DTOR(Mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
|
@ -116,15 +112,39 @@ public:
|
||||||
#endif // ifndef DEBUG
|
#endif // ifndef DEBUG
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex();
|
OffTheBooksMutex();
|
||||||
Mutex(const Mutex&);
|
OffTheBooksMutex(const OffTheBooksMutex&);
|
||||||
Mutex& operator=(const Mutex&);
|
OffTheBooksMutex& operator=(const OffTheBooksMutex&);
|
||||||
|
|
||||||
PRLock* mLock;
|
PRLock* mLock;
|
||||||
|
|
||||||
friend class CondVar;
|
friend class CondVar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mutex
|
||||||
|
* When possible, use MutexAutoLock/MutexAutoUnlock to lock/unlock this
|
||||||
|
* mutex within a scope, instead of calling Lock/Unlock directly.
|
||||||
|
*/
|
||||||
|
class NS_COM_GLUE Mutex : public OffTheBooksMutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Mutex(const char* name)
|
||||||
|
: OffTheBooksMutex(name)
|
||||||
|
{
|
||||||
|
MOZ_COUNT_CTOR(Mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
~Mutex()
|
||||||
|
{
|
||||||
|
MOZ_COUNT_DTOR(Mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Mutex();
|
||||||
|
Mutex(const Mutex&);
|
||||||
|
Mutex& operator=(const Mutex&);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MutexAutoLock
|
* MutexAutoLock
|
||||||
|
@ -169,6 +189,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoLock<Mutex> MutexAutoLock;
|
typedef BaseAutoLock<Mutex> MutexAutoLock;
|
||||||
|
typedef BaseAutoLock<OffTheBooksMutex> OffTheBooksMutexAutoLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MutexAutoUnlock
|
* MutexAutoUnlock
|
||||||
|
@ -206,6 +227,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoUnlock<Mutex> MutexAutoUnlock;
|
typedef BaseAutoUnlock<Mutex> MutexAutoUnlock;
|
||||||
|
typedef BaseAutoUnlock<OffTheBooksMutex> OffTheBooksMutexAutoUnlock;
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче