summaryrefslogtreecommitdiffstats
path: root/js/src/threading/LockGuard.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /js/src/threading/LockGuard.h
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/threading/LockGuard.h')
-rw-r--r--js/src/threading/LockGuard.h25
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;
};