From 20c3fccf0d043402b4324d24c9eaa60107fb4f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Sat, 2 May 2026 12:16:00 -0400 Subject: [PATCH] feat(ke): add generic event --- src/kern/event.zig | 32 ++++++++++++++++++++++++++++++++ src/kern/root.zig | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/kern/event.zig diff --git a/src/kern/event.zig b/src/kern/event.zig new file mode 100644 index 0000000..31e2f84 --- /dev/null +++ b/src/kern/event.zig @@ -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); + } +}; diff --git a/src/kern/root.zig b/src/kern/root.zig index ffb7128..1396022 100644 --- a/src/kern/root.zig +++ b/src/kern/root.zig @@ -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;