mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
Reduce number of passes in the scheduler by 2.
This commit is contained in:
parent
39d2fcbbee
commit
440029c9d1
Notes:
sideshowbarker
2024-07-19 18:32:12 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/440029c9d17
2 changed files with 23 additions and 16 deletions
|
@ -857,20 +857,24 @@ void Process::doHouseKeeping()
|
|||
void Process::for_each(Function<bool(Process&)> callback)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
for (auto* process = g_processes->head(); process; process = process->next()) {
|
||||
for (auto* process = g_processes->head(); process;) {
|
||||
auto* next_process = process->next();
|
||||
if (!callback(*process))
|
||||
break;
|
||||
process = next_process;
|
||||
}
|
||||
}
|
||||
|
||||
void Process::for_each_in_pgrp(pid_t pgid, Function<bool(Process&)> callback)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
for (auto* process = g_processes->head(); process; process = process->next()) {
|
||||
for (auto* process = g_processes->head(); process;) {
|
||||
auto* next_process = process->next();
|
||||
if (process->pgid() == pgid) {
|
||||
if (!callback(*process))
|
||||
break;
|
||||
}
|
||||
process = next_process;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "Process.h"
|
||||
#include "system.h"
|
||||
|
||||
//#define LOG_EVERY_CONTEXT_SWITCH
|
||||
//#define SCHEDULER_DEBUG
|
||||
|
||||
static const dword time_slice = 5; // *10 = 50ms
|
||||
|
@ -48,22 +49,20 @@ bool Scheduler::pick_next()
|
|||
process.unblock();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Forgive dead orphans.
|
||||
// FIXME: Does this really make sense?
|
||||
Process::for_each_in_state(Process::Dead, [] (auto& process) {
|
||||
if (!Process::from_pid(process.ppid()))
|
||||
process.set_state(Process::Forgiven);
|
||||
return true;
|
||||
});
|
||||
// Forgive dead orphans.
|
||||
if (process.state() == Process::Dead) {
|
||||
if (!Process::from_pid(process.ppid()))
|
||||
process.set_state(Process::Forgiven);
|
||||
}
|
||||
|
||||
// Release the forgiven.
|
||||
Process::for_each_in_state(Process::Forgiven, [] (auto& process) {
|
||||
g_processes->remove(&process);
|
||||
g_dead_processes->append(&process);
|
||||
return true;
|
||||
});
|
||||
|
||||
// Clean up forgiven processes.
|
||||
// FIXME: Do we really need this to be a separate pass over the process list?
|
||||
Process::for_each_in_state(Process::Forgiven, [] (auto& process) {
|
||||
g_processes->remove(&process);
|
||||
g_dead_processes->append(&process);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -178,6 +177,10 @@ bool Scheduler::context_switch(Process& process)
|
|||
// mark it as runnable for the next round.
|
||||
if (current->state() == Process::Running)
|
||||
current->set_state(Process::Runnable);
|
||||
|
||||
#ifdef LOG_EVERY_CONTEXT_SWITCH
|
||||
dbgprintf("Scheduler: %s(%u) -> %s(%u)\n", current->name().characters(), current->pid(), process.name().characters(), process.pid());
|
||||
#endif
|
||||
}
|
||||
|
||||
current = &process;
|
||||
|
|
Loading…
Reference in a new issue