mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-24 00:24:38 +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:
@@ -783,10 +783,12 @@ const LogStream& operator<<(const LogStream& stream, const Thread& value)
|
||||
return stream << value.process().name() << "(" << value.pid() << ":" << value.tid() << ")";
|
||||
}
|
||||
|
||||
void Thread::wait_on(WaitQueue& queue, Thread* beneficiary, const char* reason)
|
||||
void Thread::wait_on(WaitQueue& queue, Atomic<bool>* lock, Thread* beneficiary, const char* reason)
|
||||
{
|
||||
bool did_unlock = unlock_process_if_locked();
|
||||
cli();
|
||||
if (lock)
|
||||
*lock = false;
|
||||
set_state(State::Queued);
|
||||
queue.enqueue(*current);
|
||||
// Yield and wait for the queue to wake us up again.
|
||||
|
||||
Reference in New Issue
Block a user