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:
Justin Lebar 2013-05-24 13:10:47 -04:00
Родитель c002d5a3a3
Коммит 8d14a63fba
2 изменённых файлов: 45 добавлений и 23 удалений

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

@ -218,9 +218,9 @@ BlockingResourceBase::PrintCycle(const DDT::ResourceAcquisitionArray* aCycle,
//
// Debug implementation of Mutex
// Debug implementation of (OffTheBooks)Mutex
void
Mutex::Lock()
OffTheBooksMutex::Lock()
{
CallStack callContext = CallStack();
@ -230,7 +230,7 @@ Mutex::Lock()
}
void
Mutex::Unlock()
OffTheBooksMutex::Unlock()
{
Release(); // protected by mLock
PRStatus status = PR_Unlock(mLock);

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

@ -20,48 +20,44 @@
// locked and unlocked
// - MutexAutoUnlock, complementary sibling to MutexAutoLock
//
// Using MutexAutoLock/MutexAutoUnlock is MUCH preferred to making bare
// calls to Mutex.Lock and Unlock.
// - OffTheBooksMutex, a non-recursive mutex that doesn't do leak checking
// - 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 {
/**
* 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 : BlockingResourceBase
* OffTheBooksMutex is identical to Mutex, except that OffTheBooksMutex doesn't
* include leak checking. Sometimes you want to intentionally "leak" a mutex
* until shutdown; in these cases, OffTheBooksMutex is for you.
*/
class NS_COM_GLUE OffTheBooksMutex : BlockingResourceBase
{
public:
/**
* Mutex
* @param name A name which can reference this lock
* @returns If failure, nullptr
* If success, a valid Mutex* which must be destroyed
* by Mutex::DestroyMutex()
**/
Mutex(const char* name) :
OffTheBooksMutex(const char* name) :
BlockingResourceBase(name, eMutex)
{
MOZ_COUNT_CTOR(Mutex);
mLock = PR_NewLock();
if (!mLock)
NS_RUNTIMEABORT("Can't allocate mozilla::Mutex");
}
/**
* ~Mutex
**/
~Mutex()
~OffTheBooksMutex()
{
NS_ASSERTION(mLock,
"improperly constructed Lock or double free");
// NSPR does consistency checks for us
PR_DestroyLock(mLock);
mLock = 0;
MOZ_COUNT_DTOR(Mutex);
}
#ifndef DEBUG
@ -116,15 +112,39 @@ public:
#endif // ifndef DEBUG
private:
Mutex();
Mutex(const Mutex&);
Mutex& operator=(const Mutex&);
OffTheBooksMutex();
OffTheBooksMutex(const OffTheBooksMutex&);
OffTheBooksMutex& operator=(const OffTheBooksMutex&);
PRLock* mLock;
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
@ -169,6 +189,7 @@ private:
};
typedef BaseAutoLock<Mutex> MutexAutoLock;
typedef BaseAutoLock<OffTheBooksMutex> OffTheBooksMutexAutoLock;
/**
* MutexAutoUnlock
@ -206,6 +227,7 @@ private:
};
typedef BaseAutoUnlock<Mutex> MutexAutoUnlock;
typedef BaseAutoUnlock<OffTheBooksMutex> OffTheBooksMutexAutoUnlock;
} // namespace mozilla