forked from mirrors/gecko-dev
Bug 1618165 - Provide BaseAutoLock and BaseAutoUnlock deduction guides for Mutex references. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D64359 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
5f8fe948be
commit
69b996524d
6 changed files with 30 additions and 19 deletions
|
|
@ -107,8 +107,8 @@ class CrossProcessMutex {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoLock<CrossProcessMutex&> CrossProcessMutexAutoLock;
|
typedef detail::BaseAutoLock<CrossProcessMutex&> CrossProcessMutexAutoLock;
|
||||||
typedef BaseAutoUnlock<CrossProcessMutex&> CrossProcessMutexAutoUnlock;
|
typedef detail::BaseAutoUnlock<CrossProcessMutex&> CrossProcessMutexAutoUnlock;
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ void SharedRef::Clear() {
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
typedef BaseAutoLock<detail::SharedRef&> SharedRefAutoLock;
|
typedef mozilla::detail::BaseAutoLock<detail::SharedRef&> SharedRefAutoLock;
|
||||||
typedef BaseAutoUnlock<detail::SharedRef&> SharedRefAutoUnlock;
|
typedef mozilla::detail::BaseAutoUnlock<detail::SharedRef&> SharedRefAutoUnlock;
|
||||||
|
|
||||||
WeakReferenceSupport::WeakReferenceSupport(Flags aFlags)
|
WeakReferenceSupport::WeakReferenceSupport(Flags aFlags)
|
||||||
: mRefCnt(0), mFlags(aFlags) {
|
: mRefCnt(0), mFlags(aFlags) {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ StaticMutex MacCrashReporterLock::sInnerMutex;
|
||||||
bool MacCrashReporterLock::sIsLocked;
|
bool MacCrashReporterLock::sIsLocked;
|
||||||
|
|
||||||
// Use MacCrashReporterLock for locking
|
// Use MacCrashReporterLock for locking
|
||||||
typedef mozilla::BaseAutoLock<MacCrashReporterLock&> CrashReporterAutoLock;
|
typedef mozilla::detail::BaseAutoLock<MacCrashReporterLock&>
|
||||||
|
CrashReporterAutoLock;
|
||||||
typedef MacCrashReporterLock CrashReporterLockType;
|
typedef MacCrashReporterLock CrashReporterLockType;
|
||||||
#else /* !XP_MACOSX */
|
#else /* !XP_MACOSX */
|
||||||
// Use StaticMutex for locking
|
// Use StaticMutex for locking
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,8 @@ class MOZ_STACK_CLASS AnyStaticMutex {
|
||||||
StaticMutex* mStaticMutex;
|
StaticMutex* mStaticMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoLock<AnyStaticMutex> StaticMutexAutoLock;
|
typedef detail::BaseAutoLock<AnyStaticMutex> StaticMutexAutoLock;
|
||||||
typedef BaseAutoUnlock<AnyStaticMutex> StaticMutexAutoUnlock;
|
typedef detail::BaseAutoUnlock<AnyStaticMutex> StaticMutexAutoUnlock;
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@ class SafeMutex {
|
||||||
mozilla::Atomic<PRThread*, mozilla::Relaxed> mOwnerThread;
|
mozilla::Atomic<PRThread*, mozilla::Relaxed> mOwnerThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef mozilla::BaseAutoLock<SafeMutex&> SafeMutexAutoLock;
|
typedef mozilla::detail::BaseAutoLock<SafeMutex&> SafeMutexAutoLock;
|
||||||
typedef mozilla::BaseAutoUnlock<SafeMutex&> SafeMutexAutoUnlock;
|
typedef mozilla::detail::BaseAutoUnlock<SafeMutex&> SafeMutexAutoUnlock;
|
||||||
|
|
||||||
class nsComponentManagerImpl final : public nsIComponentManager,
|
class nsComponentManagerImpl final : public nsIComponentManager,
|
||||||
public nsIServiceManager,
|
public nsIServiceManager,
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ class Mutex : public OffTheBooksMutex {
|
||||||
Mutex& operator=(const Mutex&);
|
Mutex& operator=(const Mutex&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class MOZ_RAII BaseAutoUnlock;
|
class MOZ_RAII BaseAutoUnlock;
|
||||||
|
|
||||||
|
|
@ -165,7 +166,7 @@ class MOZ_RAII BaseAutoLock {
|
||||||
// Assert that aLock is the mutex passed to the constructor and that the
|
// Assert that aLock is the mutex passed to the constructor and that the
|
||||||
// current thread owns the mutex. In coding patterns such as:
|
// current thread owns the mutex. In coding patterns such as:
|
||||||
//
|
//
|
||||||
// void LockedMethod(const MutexAutoLock& aProofOfLock)
|
// void LockedMethod(const BaseAutoLock<T>& aProofOfLock)
|
||||||
// {
|
// {
|
||||||
// aProofOfLock.AssertOwns(mMutex);
|
// aProofOfLock.AssertOwns(mMutex);
|
||||||
// ...
|
// ...
|
||||||
|
|
@ -174,9 +175,9 @@ class MOZ_RAII BaseAutoLock {
|
||||||
// Without this assertion, it could be that mMutex is not actually
|
// Without this assertion, it could be that mMutex is not actually
|
||||||
// locked. It's possible to have code like:
|
// locked. It's possible to have code like:
|
||||||
//
|
//
|
||||||
// MutexAutoLock lock(someMutex);
|
// BaseAutoLock lock(someMutex);
|
||||||
// ...
|
// ...
|
||||||
// MutexAutoUnlock unlock(someMutex);
|
// BaseAutoUnlock unlock(someMutex);
|
||||||
// ...
|
// ...
|
||||||
// LockedMethod(lock);
|
// LockedMethod(lock);
|
||||||
//
|
//
|
||||||
|
|
@ -187,8 +188,8 @@ class MOZ_RAII BaseAutoLock {
|
||||||
// should use this method in preference to using AssertCurrentThreadOwns on
|
// should use this method in preference to using AssertCurrentThreadOwns on
|
||||||
// the mutex you expected to be held, since this method provides stronger
|
// the mutex you expected to be held, since this method provides stronger
|
||||||
// guarantees.
|
// guarantees.
|
||||||
void AssertOwns(const T& aLock) const {
|
void AssertOwns(const T& aMutex) const {
|
||||||
MOZ_ASSERT(&aLock == &mLock);
|
MOZ_ASSERT(&aMutex == &aMutex);
|
||||||
mLock.AssertCurrentThreadOwns();
|
mLock.AssertCurrentThreadOwns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,11 +205,16 @@ class MOZ_RAII BaseAutoLock {
|
||||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoLock<Mutex&> MutexAutoLock;
|
template <typename MutexType>
|
||||||
typedef BaseAutoLock<OffTheBooksMutex&> OffTheBooksMutexAutoLock;
|
BaseAutoLock(MutexType&)->BaseAutoLock<MutexType&>;
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
typedef detail::BaseAutoLock<Mutex&> MutexAutoLock;
|
||||||
|
typedef detail::BaseAutoLock<OffTheBooksMutex&> OffTheBooksMutexAutoLock;
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
/**
|
/**
|
||||||
* MutexAutoUnlock
|
* BaseAutoUnlock
|
||||||
* Releases the Mutex when it enters scope, and re-acquires it when it leaves
|
* Releases the Mutex when it enters scope, and re-acquires it when it leaves
|
||||||
* scope.
|
* scope.
|
||||||
*
|
*
|
||||||
|
|
@ -243,8 +249,12 @@ class MOZ_RAII BaseAutoUnlock {
|
||||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BaseAutoUnlock<Mutex&> MutexAutoUnlock;
|
template <typename MutexType>
|
||||||
typedef BaseAutoUnlock<OffTheBooksMutex&> OffTheBooksMutexAutoUnlock;
|
BaseAutoUnlock(MutexType&)->BaseAutoUnlock<MutexType&>;
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
typedef detail::BaseAutoUnlock<Mutex&> MutexAutoUnlock;
|
||||||
|
typedef detail::BaseAutoUnlock<OffTheBooksMutex&> OffTheBooksMutexAutoUnlock;
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue