From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- js/src/threading/LockGuard.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'js/src/threading/LockGuard.h') 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 +template class MOZ_RAII UnlockGuard; template class MOZ_RAII LockGuard { - friend class UnlockGuard; + friend class UnlockGuard>; 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 +// RAII class to temporarily unlock a LockGuard. +template class MOZ_RAII UnlockGuard { - Mutex& lock; + GuardT& guard; public: - explicit UnlockGuard(LockGuard& 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; }; -- cgit v1.2.3