mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
Kernel: Don't create Function objects in the scheduling code
Each Function is a heap allocation, so let's make an effort to avoid doing that during scheduling. Because of header dependencies, I had to put the runnables iteration helpers in Thread.h, which is a bit meh but at least this cuts out all the kmalloc() traffic in pick_next().
This commit is contained in:
parent
2e416b1b87
commit
1f9b8f0e7c
3 changed files with 49 additions and 59 deletions
|
@ -6,21 +6,7 @@
|
|||
#include <Kernel/RTC.h>
|
||||
#include <Kernel/Scheduler.h>
|
||||
|
||||
struct SchedulerData {
|
||||
typedef IntrusiveList<Thread, &Thread::m_runnable_list_node> ThreadList;
|
||||
|
||||
ThreadList m_runnable_threads;
|
||||
ThreadList m_nonrunnable_threads;
|
||||
|
||||
ThreadList& thread_list_for_state(Thread::State state)
|
||||
{
|
||||
if (Thread::is_runnable_state(state))
|
||||
return m_runnable_threads;
|
||||
return m_nonrunnable_threads;
|
||||
}
|
||||
};
|
||||
|
||||
static SchedulerData* g_scheduler_data;
|
||||
SchedulerData* g_scheduler_data;
|
||||
|
||||
void Scheduler::init_thread(Thread& thread)
|
||||
{
|
||||
|
@ -37,34 +23,6 @@ void Scheduler::update_state_for_thread(Thread& thread)
|
|||
list.append(thread);
|
||||
}
|
||||
|
||||
IterationDecision Scheduler::for_each_runnable_func(Function<IterationDecision(Thread&)>&& callback)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
auto& tl = g_scheduler_data->m_runnable_threads;
|
||||
for (auto it = tl.begin(); it != tl.end();) {
|
||||
auto thread = *it;
|
||||
it = ++it;
|
||||
if (callback(*thread) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
IterationDecision Scheduler::for_each_nonrunnable_func(Function<IterationDecision(Thread&)>&& callback)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
auto& tl = g_scheduler_data->m_nonrunnable_threads;
|
||||
for (auto it = tl.begin(); it != tl.end();) {
|
||||
auto thread = *it;
|
||||
it = ++it;
|
||||
if (callback(*thread) == IterationDecision::Break)
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
//#define LOG_EVERY_CONTEXT_SWITCH
|
||||
//#define SCHEDULER_DEBUG
|
||||
//#define SCHEDULER_RUNNABLE_DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue