Kernel: Implement thread priority queues

Rather than walking all Thread instances and putting them into
a vector to be sorted by priority, queue them into priority sorted
linked lists as soon as they become ready to be executed.
This commit is contained in:
Tom 2021-01-22 16:56:08 -07:00 committed by Andreas Kling
parent c531084873
commit 03a9ee79fa
Notes: sideshowbarker 2024-07-18 22:48:42 +09:00
5 changed files with 124 additions and 58 deletions

View file

@ -131,6 +131,10 @@ Thread::~Thread()
// the middle of being destroyed.
ScopedSpinLock lock(g_scheduler_lock);
g_scheduler_data->thread_list_for_state(m_state).remove(*this);
// We shouldn't be queued
ASSERT(m_runnable_priority < 0);
ASSERT(!m_runnable_list_node.is_in_list());
}
}
@ -904,7 +908,9 @@ void Thread::set_state(State new_state, u8 stop_signal)
ASSERT(g_scheduler_data->has_thread(*this));
}
if (previous_state == Stopped) {
if (previous_state == Runnable) {
Scheduler::dequeue_runnable_thread(*this);
} else if (previous_state == Stopped) {
m_stop_state = State::Invalid;
auto& process = this->process();
if (process.set_stopped(false) == true) {
@ -920,6 +926,7 @@ void Thread::set_state(State new_state, u8 stop_signal)
}
if (m_state == Runnable) {
Scheduler::queue_runnable_thread(*this);
Processor::smp_wake_n_idle_processors(1);
} else if (m_state == Stopped) {
// We don't want to restore to Running state, only Runnable!