feat(ke): add generic event

This commit is contained in:
Loïc Grégoire
2026-05-02 12:16:00 -04:00
parent c82f9759b4
commit 20c3fccf0d
2 changed files with 33 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
const ke = @import("root").ke;
const ki = ke.private;
/// Generic waitable Event, exported for use everywhere in the kernel.
pub const Event = struct {
hdr: ki.wait.DispatchHeader,
const Self = @This();
pub const Type = enum {
/// Wake only one waiter.
Synchronization,
/// Wake all waiters.
Notification,
};
/// Initialize an event with a specified type.
pub fn init(self: *Self, @"type": Type) void {
self.hdr.init(switch (@"type") {
.Synchronization => .Synchronization,
.Notification => .Notification,
});
}
/// Signal an event, waking its waiter(s).
pub fn signal(self: *Self) void {
const ipl = self.hdr.lock.acquire();
self.hdr.signaled = 1;
ki.wait.satisfy_wait(&self.hdr);
self.hdr.lock.release(ipl);
}
};
+1
View File
@@ -17,6 +17,7 @@ pub const Console = p.log.Console;
pub const CpuLocal = p.cpu.CpuLocal;
pub const ExportedCpuLocal = p.cpu.ExportedCpuLocal;
pub const CpuMask = p.cpu.CpuMask;
pub const Event = p.event.Event;
// === Exported Interfaces ===
pub const panic = p.panic.panic;