summaryrefslogtreecommitdiff
path: root/Kernel/Arch/x86/Processor.h
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-24 19:38:54 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-27 20:37:57 +0100
commitf4875b996781670f377916af9c5a45ef381c2449 (patch)
treef1e26e51df9051acad898b2ab3679a12076d145f /Kernel/Arch/x86/Processor.h
parent9da8c781336bf773705530646c20969df1dc4b36 (diff)
downloadserenity-f4875b996781670f377916af9c5a45ef381c2449.zip
Kernel: Add Processor::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly propagate errors.
Diffstat (limited to 'Kernel/Arch/x86/Processor.h')
-rw-r--r--Kernel/Arch/x86/Processor.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86/Processor.h
index c2e620d8c2..fa98091d1a 100644
--- a/Kernel/Arch/x86/Processor.h
+++ b/Kernel/Arch/x86/Processor.h
@@ -208,6 +208,17 @@ public:
return IterationDecision::Continue;
}
+ static inline ErrorOr<void> try_for_each(Function<ErrorOr<void>(Processor&)> callback)
+ {
+ auto& procs = processors();
+ size_t count = procs.size();
+ for (size_t i = 0; i < count; i++) {
+ if (procs[i] != nullptr)
+ TRY(callback(*procs[i]));
+ }
+ return {};
+ }
+
ALWAYS_INLINE u8 physical_address_bit_width() const { return m_physical_address_bit_width; }
ALWAYS_INLINE u8 virtual_address_bit_width() const { return m_virtual_address_bit_width; }