Bug 1760357 - Part 1: Fix typo and annotations on ReleasableAutoLock types, r=jesup

Corrects a spelling mistake in the name of the type, and corrects the
annotations on the assertion methods to be more useful.

Differential Revision: https://phabricator.services.mozilla.com/D141532
This commit is contained in:
Nika Layzell 2022-03-22 14:59:40 +00:00
parent 31e465fc89
commit acee005c69
2 changed files with 26 additions and 21 deletions

View File

@ -228,15 +228,16 @@ typedef detail::BaseMonitorAutoUnlock<MonitorSingleWriter>
* The monitor must be unlocked when instances of this class are
* created.
*/
class SCOPED_CAPABILITY MOZ_STACK_CLASS ReleaseableMonitorAutoLock {
class SCOPED_CAPABILITY MOZ_STACK_CLASS ReleasableMonitorAutoLock {
public:
explicit ReleaseableMonitorAutoLock(Monitor& aMonitor) CAPABILITY_ACQUIRE(aMonitor)
explicit ReleasableMonitorAutoLock(Monitor& aMonitor)
CAPABILITY_ACQUIRE(aMonitor)
: mMonitor(&aMonitor) {
mMonitor->Lock();
mLocked = true;
}
~ReleaseableMonitorAutoLock() CAPABILITY_RELEASE() {
~ReleasableMonitorAutoLock() CAPABILITY_RELEASE() {
if (mLocked) {
mMonitor->Unlock();
}
@ -277,7 +278,7 @@ class SCOPED_CAPABILITY MOZ_STACK_CLASS ReleaseableMonitorAutoLock {
mMonitor->Lock();
mLocked = true;
}
void AssertCurrentThreadOwns() const ASSERT_CAPABILITY(mMonitor) {
void AssertCurrentThreadOwns() const ASSERT_CAPABILITY() {
mMonitor->AssertCurrentThreadOwns();
}
@ -285,9 +286,9 @@ class SCOPED_CAPABILITY MOZ_STACK_CLASS ReleaseableMonitorAutoLock {
bool mLocked;
Monitor* mMonitor;
ReleaseableMonitorAutoLock() = delete;
ReleaseableMonitorAutoLock(const ReleaseableMonitorAutoLock&) = delete;
ReleaseableMonitorAutoLock& operator=(const ReleaseableMonitorAutoLock&) =
ReleasableMonitorAutoLock() = delete;
ReleasableMonitorAutoLock(const ReleasableMonitorAutoLock&) = delete;
ReleasableMonitorAutoLock& operator=(const ReleasableMonitorAutoLock&) =
delete;
static void* operator new(size_t) noexcept(true);
};

View File

@ -232,7 +232,9 @@ class MOZ_RAII SCOPED_CAPABILITY BaseAutoLock {
* @param aLock A valid mozilla::Mutex* returned by
* mozilla::Mutex::NewMutex.
**/
explicit BaseAutoLock(T aLock) CAPABILITY_ACQUIRE(aLock) : mLock(aLock) { mLock.Lock(); }
explicit BaseAutoLock(T aLock) CAPABILITY_ACQUIRE(aLock) : mLock(aLock) {
mLock.Lock();
}
~BaseAutoLock(void) CAPABILITY_RELEASE() { mLock.Unlock(); }
@ -297,14 +299,14 @@ typedef detail::BaseAutoLock<OffTheBooksMutex&> OffTheBooksMutexAutoLock;
namespace detail {
/**
* ReleaseableMutexAutoLock
* ReleasableMutexAutoLock
* Acquires the Mutex when it enters scope, and releases it when it leaves
* scope. Allows calling Unlock (and Lock) as an alternative to
* MutexAutoUnlock; this can avoid an extra lock/unlock pair.
*
*/
template <typename T>
class MOZ_RAII SCOPED_CAPABILITY ReleaseableBaseAutoLock {
class MOZ_RAII SCOPED_CAPABILITY ReleasableBaseAutoLock {
public:
/**
* Constructor
@ -314,19 +316,19 @@ class MOZ_RAII SCOPED_CAPABILITY ReleaseableBaseAutoLock {
* @param aLock A valid mozilla::Mutex& returned by
* mozilla::Mutex::NewMutex.
**/
explicit ReleaseableBaseAutoLock(T aLock) CAPABILITY_ACQUIRE(aLock)
: BaseAutoLock<T>(aLock) {
explicit ReleasableBaseAutoLock(T aLock) CAPABILITY_ACQUIRE(aLock)
: mLock(aLock) {
mLock.Lock();
mLocked = true;
}
~ReleaseableBaseAutoLock(void) CAPABILITY_RELEASE() {
if (!mLocked) {
mLock.Unlock();
~ReleasableBaseAutoLock(void) CAPABILITY_RELEASE() {
if (mLocked) {
Unlock();
}
}
void AssertOwns(const T& aMutex) const ASSERT_CAPABILITY(mLock) {
void AssertOwns(const T& aMutex) const ASSERT_CAPABILITY(aMutex) {
MOZ_ASSERT(&aMutex == &mLock);
mLock.AssertCurrentThreadOwns();
}
@ -342,18 +344,20 @@ class MOZ_RAII SCOPED_CAPABILITY ReleaseableBaseAutoLock {
// }
// clang-format on
void Unlock() CAPABILITY_RELEASE() {
MOZ_ASSERT(mLocked);
mLock.Unlock();
mLocked = false;
}
void Lock() CAPABILITY_ACQUIRE() {
MOZ_ASSERT(!mLocked);
mLock.Lock();
mLocked = true;
}
private:
ReleaseableBaseAutoLock() = delete;
ReleaseableBaseAutoLock(ReleaseableBaseAutoLock&) = delete;
ReleaseableBaseAutoLock& operator=(ReleaseableBaseAutoLock&) = delete;
ReleasableBaseAutoLock() = delete;
ReleasableBaseAutoLock(ReleasableBaseAutoLock&) = delete;
ReleasableBaseAutoLock& operator=(ReleasableBaseAutoLock&) = delete;
static void* operator new(size_t) noexcept(true);
bool mLocked;
@ -361,10 +365,10 @@ class MOZ_RAII SCOPED_CAPABILITY ReleaseableBaseAutoLock {
};
template <typename MutexType>
ReleaseableBaseAutoLock(MutexType&) -> ReleaseableBaseAutoLock<MutexType&>;
ReleasableBaseAutoLock(MutexType&) -> ReleasableBaseAutoLock<MutexType&>;
} // namespace detail
typedef detail::ReleaseableBaseAutoLock<Mutex&> ReleaseableMutexAutoLock;
typedef detail::ReleasableBaseAutoLock<Mutex&> ReleasableMutexAutoLock;
namespace detail {
/**