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.
This commit is contained in:
Gunnar Beutner 2021-05-19 14:42:16 +02:00 committed by Andreas Kling
commit e9898a6031
Notes: sideshowbarker 2024-07-18 17:46:21 +09:00
2 changed files with 8 additions and 25 deletions

View file

@ -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<Function*>(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<Function*>(f)->~Function();
};
} else {
item->data = new Function(move(function));
item->free_data = [](void* f) {
delete reinterpret_cast<Function*>(f);
};
}
item->function = Function(function);
do_queue(item);
}
private:
struct WorkItem {
IntrusiveListNode<WorkItem> m_node;
void (*function)(void*);
void* data;
void (*free_data)(void*);
u8 inline_data[4 * sizeof(void*)];
Function<void()> function;
};
void do_queue(WorkItem*);