1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:37:44 +00:00

Kernel: Refactor thread scheduling a bit, breaking it into multiple lists.

There are now two thread lists, one for runnable threads and one for non-
runnable threads. Thread::set_state() is responsible for moving threads
between the lists.

Each thread also has a back-pointer to the list it's currently in.
This commit is contained in:
Andreas Kling 2019-05-18 18:31:36 +02:00
parent 99dd60611f
commit 8c7d5abdc4
4 changed files with 104 additions and 25 deletions

View file

@ -403,7 +403,15 @@ inline void Process::for_each_thread(Callback callback) const
{
InterruptDisabler disabler;
pid_t my_pid = pid();
for (auto* thread = g_threads->head(); thread;) {
for (auto* thread = g_runnable_threads->head(); thread;) {
auto* next_thread = thread->next();
if (thread->pid() == my_pid) {
if (callback(*thread) == IterationDecision::Abort)
break;
}
thread = next_thread;
}
for (auto* thread = g_nonrunnable_threads->head(); thread;) {
auto* next_thread = thread->next();
if (thread->pid() == my_pid) {
if (callback(*thread) == IterationDecision::Abort)