1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 10:07:43 +00:00

Kernel: Allow WorkQueue items allocation failures propagation

In most cases it's safe to abort the requested operation and go forward,
however, in some places it's not clear yet how to handle these failures,
therefore, we use the MUST() wrapper to force a kernel panic for now.
This commit is contained in:
Liav A 2022-03-06 22:07:04 +02:00 committed by Linus Groh
parent 02566d8091
commit 1462211ccf
9 changed files with 75 additions and 19 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Error.h>
#include <AK/IntrusiveList.h>
#include <Kernel/Forward.h>
#include <Kernel/Locking/SpinlockProtected.h>
@ -23,23 +24,29 @@ class WorkQueue {
public:
static void initialize();
void queue(void (*function)(void*), void* data = nullptr, void (*free_data)(void*) = nullptr)
ErrorOr<void> try_queue(void (*function)(void*), void* data = nullptr, void (*free_data)(void*) = nullptr)
{
auto* item = new WorkItem; // TODO: use a pool
auto item = new (nothrow) WorkItem; // TODO: use a pool
if (!item)
return Error::from_errno(ENOMEM);
item->function = [function, data, free_data] {
function(data);
if (free_data)
free_data(data);
};
do_queue(item);
return {};
}
template<typename Function>
void queue(Function function)
ErrorOr<void> try_queue(Function function)
{
auto* item = new WorkItem; // TODO: use a pool
auto item = new (nothrow) WorkItem; // TODO: use a pool
if (!item)
return Error::from_errno(ENOMEM);
item->function = Function(function);
do_queue(item);
return {};
}
private: