mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +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
1 changed files with 18 additions and 3 deletions
|
@ -110,12 +110,27 @@ public:
|
||||||
{
|
{
|
||||||
m_lock.lock(mode);
|
m_lock.lock(mode);
|
||||||
}
|
}
|
||||||
ALWAYS_INLINE ~Locker() { unlock(); }
|
ALWAYS_INLINE ~Locker()
|
||||||
ALWAYS_INLINE void unlock() { m_lock.unlock(); }
|
{
|
||||||
ALWAYS_INLINE void lock(Lock::Mode mode = Lock::Mode::Exclusive) { m_lock.lock(mode); }
|
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:
|
private:
|
||||||
Lock& m_lock;
|
Lock& m_lock;
|
||||||
|
bool m_locked { true };
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LOCK_DEBUG
|
#ifdef LOCK_DEBUG
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue