ladybird/Kernel/WaitQueue.h
Andreas Kling 41376d4662 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().
2020-01-12 19:04:16 +01:00

19 lines
370 B
C++

#pragma once
#include <AK/Atomic.h>
#include <AK/SinglyLinkedList.h>
#include <Kernel/Thread.h>
class WaitQueue {
public:
WaitQueue();
~WaitQueue();
void enqueue(Thread&);
void wake_one(Atomic<bool>* lock = nullptr);
void wake_all();
private:
typedef IntrusiveList<Thread, &Thread::m_wait_queue_node> ThreadList;
ThreadList m_threads;
};