ladybird/Kernel/WaitQueue.h
Andreas Kling f067730f6b Kernel: Add a WaitQueue for Thread queueing/waking and use it for Lock
The kernel's Lock class now uses a proper wait queue internally instead
of just having everyone wake up regularly to try to acquire the lock.

We also keep the donation mechanism, so that whenever someone tries to
take the lock and fails, that thread donates the remainder of its
timeslice to the current lock holder.

After unlocking a Lock, the unlocking thread calls WaitQueue::wake_one,
which unblocks the next thread in queue.
2019-12-01 12:07:43 +01:00

18 lines
248 B
C++

#pragma once
#include <AK/SinglyLinkedList.h>
class Thread;
class WaitQueue {
public:
WaitQueue();
~WaitQueue();
void enqueue(Thread&);
void wake_one();
void wake_all();
private:
SinglyLinkedList<Thread*> m_threads;
};