mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:28:12 +00:00
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.
This commit is contained in:
parent
cada332e95
commit
f067730f6b
8 changed files with 119 additions and 9 deletions
|
@ -82,9 +82,22 @@ bool Thread::JoinBlocker::should_unblock(Thread& joiner, time_t, long)
|
|||
return !joiner.m_joinee;
|
||||
}
|
||||
|
||||
Thread::WaitQueueBlocker::WaitQueueBlocker(WaitQueue& queue)
|
||||
: m_queue(queue)
|
||||
{
|
||||
m_queue.enqueue(*current);
|
||||
}
|
||||
|
||||
bool Thread::WaitQueueBlocker::should_unblock(Thread&, time_t, long)
|
||||
{
|
||||
// Someone else will have to unblock us by calling wake_one() or wake_all() on the queue.
|
||||
return false;
|
||||
}
|
||||
|
||||
Thread::FileDescriptionBlocker::FileDescriptionBlocker(const FileDescription& description)
|
||||
: m_blocked_description(description)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
const FileDescription& Thread::FileDescriptionBlocker::blocked_description() const
|
||||
{
|
||||
|
@ -236,7 +249,8 @@ bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long)
|
|||
|
||||
Thread::SemiPermanentBlocker::SemiPermanentBlocker(Reason reason)
|
||||
: m_reason(reason)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
bool Thread::SemiPermanentBlocker::should_unblock(Thread&, time_t, long)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue