From aca6c0c031f014312d289e1782efe9d6eefa00da Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 24 Feb 2022 20:01:33 +0200 Subject: [PATCH] Kernel: Add Process::try_for_each_thread() for fallible iteration This API will allow users to short circuit iteration and properly propagate errors. --- Kernel/Process.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Kernel/Process.h b/Kernel/Process.h index 1043901d34..affd3d9a2e 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -237,6 +237,7 @@ public: IterationDecision for_each_thread(Callback); template Callback> IterationDecision for_each_thread(Callback callback) const; + ErrorOr try_for_each_thread(Function(Thread const&)>) const; // Non-breakable iteration functions template Callback> @@ -939,6 +940,15 @@ inline IterationDecision Process::for_each_thread(Callback callback) const return IterationDecision::Continue; } +inline ErrorOr Process::try_for_each_thread(Function(Thread const&)> callback) const +{ + return thread_list().with([&](auto& thread_list) -> ErrorOr { + for (auto& thread : thread_list) + TRY(callback(thread)); + return {}; + }); +} + template Callback> inline IterationDecision Process::for_each_thread(Callback callback) {