Bug 1350432 - Add MutexAutoLock::AssertOwns (r=froydnj)

MozReview-Commit-ID: KQGaHRFDxo4
This commit is contained in:
Bill McCloskey 2017-08-21 15:17:24 -07:00
Родитель 9cd553af84
Коммит 2270017046
1 изменённых файлов: 31 добавлений и 0 удалений

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

@ -171,6 +171,37 @@ public:
mLock->Unlock();
}
// Assert that aLock is the mutex passed to the constructor and that the
// current thread owns the mutex. In coding patterns such as:
//
// void LockedMethod(const MutexAutoLock& aProofOfLock)
// {
// aProofOfLock.AssertOwns(mMutex);
// ...
// }
//
// Without this assertion, it could be that mMutex is not actually
// locked. It's possible to have code like:
//
// MutexAutoLock lock(someMutex);
// ...
// MutexAutoUnlock unlock(someMutex);
// ...
// LockedMethod(lock);
//
// and in such a case, simply asserting that the mutex pointers match is not
// sufficient; mutex ownership must be asserted as well.
//
// Note that if you are going to use the coding pattern presented above, you
// should use this method in preference to using AssertCurrentThreadOwns on
// the mutex you expected to be held, since this method provides stronger
// guarantees.
void AssertOwns(const T& aLock) const
{
MOZ_ASSERT(&aLock == mLock);
mLock->AssertCurrentThreadOwns();
}
private:
BaseAutoLock();
BaseAutoLock(BaseAutoLock&);