1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

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.
This commit is contained in:
Nicholas Baron 2021-05-16 02:36:52 -07:00 committed by GitHub
parent bbaa463032
commit aa4d41fe2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 311 additions and 127 deletions

View file

@ -2090,12 +2090,11 @@ void Processor::smp_broadcast_message(ProcessorMessage& msg)
VERIFY(msg.refs > 0);
bool need_broadcast = false;
for_each(
[&](Processor& proc) -> IterationDecision {
[&](Processor& proc) {
if (&proc != &cur_proc) {
if (proc.smp_queue_message(msg))
need_broadcast = true;
}
return IterationDecision::Continue;
});
// Now trigger an IPI on all other APs (unless all targets already had messages queued)
@ -2215,9 +2214,8 @@ void Processor::smp_broadcast_halt()
// We don't want to use a message, because this could have been triggered
// by being out of memory and we might not be able to get a message
for_each(
[&](Processor& proc) -> IterationDecision {
[&](Processor& proc) {
proc.m_halt_requested.store(true, AK::MemoryOrder::memory_order_release);
return IterationDecision::Continue;
});
// Now trigger an IPI on all other APs

View file

@ -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; }