summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp46
-rw-r--r--Kernel/Process.h58
-rw-r--r--Kernel/i386.h5
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()