mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:27:34 +00:00
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.
This commit is contained in:
parent
abdf24cb73
commit
992769c9d4
3 changed files with 59 additions and 50 deletions
|
@ -901,52 +901,6 @@ void Process::crash()
|
||||||
ASSERT_NOT_REACHED();
|
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)
|
Process* Process::from_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
|
|
|
@ -95,10 +95,10 @@ public:
|
||||||
void setWakeupTime(DWORD t) { m_wakeupTime = t; }
|
void setWakeupTime(DWORD t) { m_wakeupTime = t; }
|
||||||
DWORD wakeupTime() const { return m_wakeupTime; }
|
DWORD wakeupTime() const { return m_wakeupTime; }
|
||||||
|
|
||||||
static void for_each(Function<bool(Process&)>);
|
template<typename Callback> static void for_each(Callback);
|
||||||
static void for_each_in_pgrp(pid_t, Function<bool(Process&)>);
|
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
|
||||||
static void for_each_in_state(State, Function<bool(Process&)>);
|
template<typename Callback> static void for_each_in_state(State, Callback);
|
||||||
static void for_each_not_in_state(State, Function<bool(Process&)>);
|
template<typename Callback> static void for_each_not_in_state(State, Callback);
|
||||||
|
|
||||||
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
||||||
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
||||||
|
@ -322,3 +322,53 @@ extern void block(Process::State);
|
||||||
extern void sleep(DWORD ticks);
|
extern void sleep(DWORD ticks);
|
||||||
|
|
||||||
extern InlineLinkedList<Process>* g_processes;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -92,6 +92,11 @@ static inline dword cpuFlags()
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool are_interrupts_enabled()
|
||||||
|
{
|
||||||
|
return cpuFlags() & 0x200;
|
||||||
|
}
|
||||||
|
|
||||||
class InterruptDisabler {
|
class InterruptDisabler {
|
||||||
public:
|
public:
|
||||||
InterruptDisabler()
|
InterruptDisabler()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue