summaryrefslogtreecommitdiff
path: root/Kernel/Arch/x86/CPU.h
diff options
context:
space:
mode:
authorNicholas Baron <nicholas.baron.ten@gmail.com>2021-05-16 02:36:52 -0700
committerGitHub <noreply@github.com>2021-05-16 10:36:52 +0100
commitaa4d41fe2c473c3bb78327a1dbe8ec85530259ca (patch)
tree925d408b37ab1f7750a3af37adfb2949fcafa836 /Kernel/Arch/x86/CPU.h
parentbbaa4630323c20e37e2a0ead478987cb5f02fc53 (diff)
downloadserenity-aa4d41fe2c473c3bb78327a1dbe8ec85530259ca.zip
AK+Kernel+LibELF: Remove the need for `IteratorDecision::Continue`
By constraining two implementations, the compiler will select the best fitting one. All this will require is duplicating the implementation and simplifying for the `void` case. This constraining also informs both the caller and compiler by passing the callback parameter types as part of the constraint (e.g.: `IterationFunction<int>`). Some `for_each` functions in LibELF only take functions which return `void`. This is a minimal correctness check, as it removes one way for a function to incompletely do something. There seems to be a possible idiom where inside a lambda, a `return;` is the same as `continue;` in a for-loop.
Diffstat (limited to 'Kernel/Arch/x86/CPU.h')
-rw-r--r--Kernel/Arch/x86/CPU.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/Kernel/Arch/x86/CPU.h b/Kernel/Arch/x86/CPU.h
index 159a64876f..488443a7fc 100644
--- a/Kernel/Arch/x86/CPU.h
+++ b/Kernel/Arch/x86/CPU.h
@@ -8,6 +8,7 @@
#include <AK/Atomic.h>
#include <AK/Badge.h>
+#include <AK/Concepts.h>
#include <AK/Noncopyable.h>
#include <AK/Vector.h>
@@ -733,7 +734,7 @@ public:
static size_t processor_count() { return processors().size(); }
- template<typename Callback>
+ template<IteratorFunction<Processor&> Callback>
static inline IterationDecision for_each(Callback callback)
{
auto& procs = processors();
@@ -745,6 +746,16 @@ public:
return IterationDecision::Continue;
}
+ template<VoidFunction<Processor&> Callback>
+ static inline IterationDecision for_each(Callback callback)
+ {
+ auto& procs = processors();
+ size_t count = procs.size();
+ for (size_t i = 0; i < count; i++)
+ callback(*procs[i]);
+ return IterationDecision::Continue;
+ }
+
ALWAYS_INLINE u8 physical_address_bit_width() const { return m_physical_address_bit_width; }
ALWAYS_INLINE ProcessorInfo& info() { return *m_info; }