1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +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:
Andreas Kling 2019-08-07 20:43:54 +02:00
parent 2e416b1b87
commit 1f9b8f0e7c
3 changed files with 49 additions and 59 deletions

View file

@ -8,11 +8,13 @@
class Process;
class Thread;
struct RegisterDump;
struct SchedulerData;
extern Thread* current;
extern Thread* g_last_fpu_thread;
extern Thread* g_finalizer;
extern u64 g_uptime;
extern SchedulerData* g_scheduler_data;
class Scheduler {
public:
@ -30,28 +32,14 @@ public:
static void beep();
template<typename Callback>
static inline IterationDecision for_each_runnable(Callback callback)
{
return for_each_runnable_func([callback](Thread& thread) {
return callback(thread);
});
}
static inline IterationDecision for_each_runnable(Callback);
template<typename Callback>
static inline IterationDecision for_each_nonrunnable(Callback callback)
{
return for_each_nonrunnable_func([callback](Thread& thread) {
return callback(thread);
});
}
static inline IterationDecision for_each_nonrunnable(Callback);
static void init_thread(Thread& thread);
static void update_state_for_thread(Thread& thread);
private:
static void prepare_for_iret_to_new_process();
static IterationDecision for_each_runnable_func(Function<IterationDecision(Thread&)>&& callback);
static IterationDecision for_each_nonrunnable_func(Function<IterationDecision(Thread&)>&& callback);
};