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

Kernel: Use the Function class for deferred_call_queue()

This avoids allocations for deferred_call_queue().
This commit is contained in:
Gunnar Beutner 2021-05-20 01:30:36 +02:00 committed by Andreas Kling
parent 7557f2db90
commit cac7a8ced9
2 changed files with 25 additions and 55 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Atomic.h>
#include <AK/Badge.h>
#include <AK/Concepts.h>
#include <AK/Function.h>
#include <AK/Noncopyable.h>
#include <AK/Vector.h>
@ -608,19 +609,21 @@ struct ProcessorMessageEntry {
};
struct DeferredCallEntry {
using HandlerFunction = Function<void()>;
DeferredCallEntry* next;
union {
struct {
void (*handler)();
} callback;
struct {
void* data;
void (*handler)(void*);
void (*free)(void*);
} callback_with_data;
};
bool have_data;
alignas(HandlerFunction) u8 handler_storage[sizeof(HandlerFunction)];
bool was_allocated;
HandlerFunction& handler_value()
{
return *bit_cast<HandlerFunction*>(&handler_storage);
}
void invoke_handler()
{
handler_value()();
}
};
class Processor;
@ -975,21 +978,7 @@ public:
static void smp_broadcast_flush_tlb(const PageDirectory*, VirtualAddress, size_t);
static u32 smp_wake_n_idle_processors(u32 wake_count);
template<typename Callback>
static void deferred_call_queue(Callback callback)
{
auto* data = new Callback(move(callback));
deferred_call_queue(
[](void* data) {
(*reinterpret_cast<Callback*>(data))();
},
data,
[](void* data) {
delete reinterpret_cast<Callback*>(data);
});
}
static void deferred_call_queue(void (*callback)());
static void deferred_call_queue(void (*callback)(void*), void* data, void (*free_data)(void*));
static void deferred_call_queue(Function<void()> callback);
ALWAYS_INLINE bool has_feature(CPUFeature f) const
{