From e9898a6031addb7b2b3e673399d1fca32997f160 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 19 May 2021 14:42:16 +0200 Subject: [PATCH] Kernel: Use plain Function objects for the WorkQueue The WorkQueue class previously had its own inline storage functionality for function pointers. With the recent changes to the Function class this is no longer necessary. --- Kernel/WorkQueue.cpp | 4 +--- Kernel/WorkQueue.h | 29 +++++++---------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/Kernel/WorkQueue.cpp b/Kernel/WorkQueue.cpp index 4af38f6ea6..589b10e271 100644 --- a/Kernel/WorkQueue.cpp +++ b/Kernel/WorkQueue.cpp @@ -31,9 +31,7 @@ WorkQueue::WorkQueue(const char* name) have_more = !m_items.is_empty(); } if (item) { - item->function(item->data); - if (item->free_data) - item->free_data(item->data); + item->function(); delete item; if (have_more) diff --git a/Kernel/WorkQueue.h b/Kernel/WorkQueue.h index 24bc7a2c93..34db117dd6 100644 --- a/Kernel/WorkQueue.h +++ b/Kernel/WorkQueue.h @@ -25,9 +25,11 @@ public: void queue(void (*function)(void*), void* data = nullptr, void (*free_data)(void*) = nullptr) { auto* item = new WorkItem; // TODO: use a pool - item->function = function; - item->data = data; - item->free_data = free_data; + item->function = [function, data, free_data] { + function(data); + if (free_data) + free_data(data); + }; do_queue(item); } @@ -35,31 +37,14 @@ public: void queue(Function function) { auto* item = new WorkItem; // TODO: use a pool - item->function = [](void* f) { - (*reinterpret_cast(f))(); - }; - if constexpr (sizeof(Function) <= sizeof(item->inline_data)) { - item->data = new (item->inline_data) Function(move(function)); - item->free_data = [](void* f) { - reinterpret_cast(f)->~Function(); - }; - - } else { - item->data = new Function(move(function)); - item->free_data = [](void* f) { - delete reinterpret_cast(f); - }; - } + item->function = Function(function); do_queue(item); } private: struct WorkItem { IntrusiveListNode m_node; - void (*function)(void*); - void* data; - void (*free_data)(void*); - u8 inline_data[4 * sizeof(void*)]; + Function function; }; void do_queue(WorkItem*);