mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Make Locker remember whether the lock is held
This allows temporarily unlocking a lock or re-locking it, and it will only unlock if it is still being held. Fixes #4352
This commit is contained in:
parent
29102051d9
commit
a51fbb13e8
Notes:
sideshowbarker
2024-07-18 23:52:01 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/a51fbb13e8a Pull-request: https://github.com/SerenityOS/serenity/pull/4953
1 changed files with 18 additions and 3 deletions
|
@ -110,12 +110,27 @@ public:
|
|||
{
|
||||
m_lock.lock(mode);
|
||||
}
|
||||
ALWAYS_INLINE ~Locker() { unlock(); }
|
||||
ALWAYS_INLINE void unlock() { m_lock.unlock(); }
|
||||
ALWAYS_INLINE void lock(Lock::Mode mode = Lock::Mode::Exclusive) { m_lock.lock(mode); }
|
||||
ALWAYS_INLINE ~Locker()
|
||||
{
|
||||
if (m_locked)
|
||||
unlock();
|
||||
}
|
||||
ALWAYS_INLINE void unlock()
|
||||
{
|
||||
ASSERT(m_locked);
|
||||
m_locked = false;
|
||||
m_lock.unlock();
|
||||
}
|
||||
ALWAYS_INLINE void lock(Lock::Mode mode = Lock::Mode::Exclusive)
|
||||
{
|
||||
ASSERT(!m_locked);
|
||||
m_locked = true;
|
||||
m_lock.lock(mode);
|
||||
}
|
||||
|
||||
private:
|
||||
Lock& m_lock;
|
||||
bool m_locked { true };
|
||||
};
|
||||
|
||||
#ifdef LOCK_DEBUG
|
||||
|
|
Loading…
Reference in a new issue