Andreas, I was watching an old video of yours, where you were adding for_each_widget, for_each_widget_of_type<>, etc. In the video, you bemoaned having to turn your nice one-line native loops into for_each calls with two-lined bodies, since you needed to now return IterationDecision::Continue. But since you use a modern compiler, you can use "if constexpr" to get rid of the need for returning an IterationDecision if it can be assumed to always return IterationDecision::Continue (which is likely the common case, so we optimize for that).
Here's an example patch for for_each_in_pgrp() in Kernel/Process.h. There are four places where for_each_in_pgrp() is called: two returning Continue and two returning Break. Those first two can be changed to return nothing, as shown below.
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 7848baa31..4edaf32e7 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -51,6 +51,7 @@
#include <Kernel/VM/Space.h>
#include <LibC/signal_numbers.h>
#include <LibELF/exec_elf.h>
+#include <type_traits>
namespace Kernel {
@@ -693,8 +694,12 @@ inline void Process::for_each_in_pgrp(ProcessGroupID pgid, Callback callback)
for (auto* process = g_processes->head(); process;) {
auto* next_process = process->next();
if (!process->is_dead() && process->pgid() == pgid) {
- if (callback(*process) == IterationDecision::Break)
- break;
+ if constexpr (std::is_void_v<std::invoke_result_t<Callback, decltype(*process)>>) {
+ callback(*process);
+ } else {
+ if (callback(*process) == IterationDecision::Break)
+ break;
+ }
}
process = next_process;
}
diff --git a/Kernel/Syscalls/kill.cpp b/Kernel/Syscalls/kill.cpp
index 48eb07fd2..1a9c86fc8 100644
--- a/Kernel/Syscalls/kill.cpp
+++ b/Kernel/Syscalls/kill.cpp
@@ -67,8 +67,6 @@ KResult Process::do_killpg(ProcessGroupID pgrp, int signal)
any_succeeded = true;
else
error = res;
-
- return IterationDecision::Continue;
});
if (group_was_empty)
diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp
index b4544e09b..a4dd4e994 100644
--- a/Kernel/TTY/TTY.cpp
+++ b/Kernel/TTY/TTY.cpp
@@ -289,7 +289,6 @@ void TTY::generate_signal(int signal)
dbgln_if(TTY_DEBUG, "{}: Send signal {} to {}", tty_name(), signal, process);
// FIXME: Should this error be propagated somehow?
[[maybe_unused]] auto rc = process.send_signal(signal, nullptr);
- return IterationDecision::Continue;
});
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too