Newer
Older
honey-os / src / kernel / service / events.c
@biosfood biosfood on 16 Jan 2023 969 bytes add await syscall
#include <service.h>
#include <util.h>

ListElement *kernelEvents;

Event *loadInitrdEvent, *crashEvent;

Event *createKernelEvent(char *name) {
    Event *event = malloc(sizeof(ServiceFunction));
    event->subscriptions = NULL;
    event->name = name;
    listAdd(&kernelEvents, event);
    return event;
}

extern ListElement *callsToProcess;

void fireEvent(Event *event, uint32_t data) {
    foreach (event->subscriptions, ServiceFunction *, function,
             { scheduleFunction(function, NULL, data); })
        ;
    for (ListElement *current = event->waitingSyscalls; current;) {
        Syscall *call = current->data;
        call->returnValue = data;
        listAdd(&callsToProcess, call);
        ListElement *old = current;
        current = current->next;
        free(old);
    }
    event->waitingSyscalls = NULL;
}

void installKernelEvents() {
    loadInitrdEvent = createKernelEvent("loadInitrd");
    crashEvent = createKernelEvent("crash");
}