mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 04:17:34 +00:00
Kernel: Use IntrusiveList to make WaitQueue allocation-free :^)
This commit is contained in:
parent
96cfddb3ac
commit
f4978b2be1
4 changed files with 30 additions and 26 deletions
|
@ -776,3 +776,25 @@ const char* to_string(ThreadPriority priority)
|
|||
ASSERT_NOT_REACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Thread::wait_on(WaitQueue& queue, Thread* beneficiary, const char* reason)
|
||||
{
|
||||
bool did_unlock = unlock_process_if_locked();
|
||||
cli();
|
||||
set_state(State::Queued);
|
||||
queue.enqueue(*current);
|
||||
// Yield and wait for the queue to wake us up again.
|
||||
if (beneficiary)
|
||||
Scheduler::donate_to(beneficiary, reason);
|
||||
else
|
||||
Scheduler::yield();
|
||||
// We've unblocked, relock the process if needed and carry on.
|
||||
if (did_unlock)
|
||||
relock_process();
|
||||
}
|
||||
|
||||
void Thread::wake_from_queue()
|
||||
{
|
||||
ASSERT(state() == State::Queued);
|
||||
set_state(State::Runnable);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue