diff options
Diffstat (limited to '')
-rw-r--r-- | js/src/threading/LockGuard.h | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/js/src/threading/LockGuard.h b/js/src/threading/LockGuard.h index d6d7976648..8a72570225 100644 --- a/js/src/threading/LockGuard.h +++ b/js/src/threading/LockGuard.h @@ -11,31 +11,34 @@ namespace js { -template <typename Mutex> +template <typename GuardT> class MOZ_RAII UnlockGuard; template <typename Mutex> class MOZ_RAII LockGuard { - friend class UnlockGuard<Mutex>; + friend class UnlockGuard<LockGuard<Mutex>>; friend class ConditionVariable; - Mutex& lock; + Mutex& mutex; public: - explicit LockGuard(Mutex& aLock) : lock(aLock) { lock.lock(); } - ~LockGuard() { lock.unlock(); } + explicit LockGuard(Mutex& mutex) : mutex(mutex) { lock(); } + ~LockGuard() { unlock(); } LockGuard(const LockGuard& other) = delete; + + protected: + void lock() { mutex.lock(); } + void unlock() { mutex.unlock(); } }; -template <typename Mutex> +// RAII class to temporarily unlock a LockGuard. +template <typename GuardT> class MOZ_RAII UnlockGuard { - Mutex& lock; + GuardT& guard; public: - explicit UnlockGuard(LockGuard<Mutex>& aGuard) : lock(aGuard.lock) { - lock.unlock(); - } - ~UnlockGuard() { lock.lock(); } + explicit UnlockGuard(GuardT& guard) : guard(guard) { guard.unlock(); } + ~UnlockGuard() { guard.lock(); } UnlockGuard(const UnlockGuard& other) = delete; }; |