diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-11-08 16:09:05 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-11-08 16:09:05 +0100 |
commit | 992769c9d4610de85e0dd88d53a0008e9bcba090 (patch) | |
tree | a5786a064df0eeefa7267c915bafc287a72aa3ff /Kernel | |
parent | abdf24cb7316994614ecfe50d83d40934dc0f7e5 (diff) | |
download | serenity-992769c9d4610de85e0dd88d53a0008e9bcba090.zip |
Make Process::for_each...() functions inline and allocation-free.
AK::Function is very handy, but costs us an 8-byte allocation.
Let's not have kmalloc() calls in the scheduler hot path.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 46 | ||||
-rw-r--r-- | Kernel/Process.h | 58 | ||||
-rw-r--r-- | Kernel/i386.h | 5 |
3 files changed, 59 insertions, 50 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 7b854decb9..8d360fa021 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -901,52 +901,6 @@ void Process::crash() ASSERT_NOT_REACHED(); } -void Process::for_each(Function<bool(Process&)> callback) -{ - ASSERT_INTERRUPTS_DISABLED(); - 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;) { - auto* next_process = process->next(); - if (process->pgid() == pgid) { - if (!callback(*process)) - break; - } - process = next_process; - } -} - -void Process::for_each_in_state(State state, Function<bool(Process&)> callback) -{ - ASSERT_INTERRUPTS_DISABLED(); - for (auto* process = g_processes->head(); process;) { - auto* next_process = process->next(); - if (process->state() == state) - callback(*process); - process = next_process; - } -} - -void Process::for_each_not_in_state(State state, Function<bool(Process&)> callback) -{ - ASSERT_INTERRUPTS_DISABLED(); - for (auto* process = g_processes->head(); process;) { - auto* next_process = process->next(); - if (process->state() != state) - callback(*process); - process = next_process; - } -} - Process* Process::from_pid(pid_t pid) { ASSERT_INTERRUPTS_DISABLED(); diff --git a/Kernel/Process.h b/Kernel/Process.h index 6c5e8f29de..e6adf5b2eb 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -95,10 +95,10 @@ public: void setWakeupTime(DWORD t) { m_wakeupTime = t; } DWORD wakeupTime() const { return m_wakeupTime; } - static void for_each(Function<bool(Process&)>); - static void for_each_in_pgrp(pid_t, Function<bool(Process&)>); - static void for_each_in_state(State, Function<bool(Process&)>); - static void for_each_not_in_state(State, Function<bool(Process&)>); + template<typename Callback> static void for_each(Callback); + template<typename Callback> static void for_each_in_pgrp(pid_t, Callback); + template<typename Callback> static void for_each_in_state(State, Callback); + template<typename Callback> static void for_each_not_in_state(State, Callback); bool tick() { ++m_ticks; return --m_ticksLeft; } void set_ticks_left(dword t) { m_ticksLeft = t; } @@ -322,3 +322,53 @@ extern void block(Process::State); extern void sleep(DWORD ticks); extern InlineLinkedList<Process>* g_processes; + +template<typename Callback> +inline void Process::for_each(Callback callback) +{ + ASSERT_INTERRUPTS_DISABLED(); + for (auto* process = g_processes->head(); process;) { + auto* next_process = process->next(); + if (!callback(*process)) + break; + process = next_process; + } +} + +template<typename Callback> +inline void Process::for_each_in_pgrp(pid_t pgid, Callback callback) +{ + ASSERT_INTERRUPTS_DISABLED(); + for (auto* process = g_processes->head(); process;) { + auto* next_process = process->next(); + if (process->pgid() == pgid) { + if (!callback(*process)) + break; + } + process = next_process; + } +} + +template<typename Callback> +inline void Process::for_each_in_state(State state, Callback callback) +{ + ASSERT_INTERRUPTS_DISABLED(); + for (auto* process = g_processes->head(); process;) { + auto* next_process = process->next(); + if (process->state() == state) + callback(*process); + process = next_process; + } +} + +template<typename Callback> +inline void Process::for_each_not_in_state(State state, Callback callback) +{ + ASSERT_INTERRUPTS_DISABLED(); + for (auto* process = g_processes->head(); process;) { + auto* next_process = process->next(); + if (process->state() != state) + callback(*process); + process = next_process; + } +} diff --git a/Kernel/i386.h b/Kernel/i386.h index 10ad9ea4ba..0eaae76ce0 100644 --- a/Kernel/i386.h +++ b/Kernel/i386.h @@ -92,6 +92,11 @@ static inline dword cpuFlags() return flags; } +inline bool are_interrupts_enabled() +{ + return cpuFlags() & 0x200; +} + class InterruptDisabler { public: InterruptDisabler() |