mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
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:
committed by
Andreas Kling
parent
661d1aa8d1
commit
e9898a6031
@@ -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*);
|
||||
|
||||
Reference in New Issue
Block a user