1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:37:43 +00:00

Kernel: Fix Lock racing to the WaitQueue

There was a time window between releasing Lock::m_lock and calling into
the lock's WaitQueue where someone else could take m_lock and bring two
threads into a deadlock situation.

Fix this issue by holding Lock::m_lock until interrupts are disabled by
either Thread::wait_on() or WaitQueue::wake_one().
This commit is contained in:
Andreas Kling 2020-01-12 18:46:41 +01:00
parent 61e6b1fb7c
commit 41376d4662
5 changed files with 13 additions and 10 deletions

View file

@ -15,9 +15,11 @@ void WaitQueue::enqueue(Thread& thread)
m_threads.append(thread);
}
void WaitQueue::wake_one()
void WaitQueue::wake_one(Atomic<bool>* lock)
{
InterruptDisabler disabler;
if (lock)
*lock = false;
if (m_threads.is_empty())
return;
if (auto* thread = m_threads.take_first())