mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +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:
@@ -180,6 +180,14 @@ void Thread::yield_without_holding_big_lock()
|
||||
process().big_lock().lock();
|
||||
}
|
||||
|
||||
void Thread::donate_and_yield_without_holding_big_lock(Thread* beneficiary, const char* reason)
|
||||
{
|
||||
bool did_unlock = process().big_lock().unlock_if_locked();
|
||||
Scheduler::donate_to(beneficiary, reason);
|
||||
if (did_unlock)
|
||||
process().big_lock().lock();
|
||||
}
|
||||
|
||||
u64 Thread::sleep(u32 ticks)
|
||||
{
|
||||
ASSERT(state() == Thread::Running);
|
||||
|
||||
Reference in New Issue
Block a user