mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-01 15:48:21 +00:00
feat(ke): add generic event
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -17,6 +17,7 @@ pub const Console = p.log.Console;
|
|||||||
pub const CpuLocal = p.cpu.CpuLocal;
|
pub const CpuLocal = p.cpu.CpuLocal;
|
||||||
pub const ExportedCpuLocal = p.cpu.ExportedCpuLocal;
|
pub const ExportedCpuLocal = p.cpu.ExportedCpuLocal;
|
||||||
pub const CpuMask = p.cpu.CpuMask;
|
pub const CpuMask = p.cpu.CpuMask;
|
||||||
|
pub const Event = p.event.Event;
|
||||||
|
|
||||||
// === Exported Interfaces ===
|
// === Exported Interfaces ===
|
||||||
pub const panic = p.panic.panic;
|
pub const panic = p.panic.panic;
|
||||||
|
|||||||
Reference in New Issue
Block a user