ex: add enqueue_in to workqueue

This commit is contained in:
Loïc Grégoire
2026-07-03 10:27:29 -04:00
parent 4a03a10d0c
commit 120b41c8ca
2 changed files with 18 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ pub const Console = p.console.Console;
pub const workqueue = struct {
pub const enqueue = p.workqueue.enqueue;
pub const enqueue_in = p.workqueue.enqueue_in;
};
pub const console = struct {
+17
View File
@@ -20,6 +20,8 @@ pub const WorkItem = struct {
link: rtl.List.Entry,
enqueued: std.atomic.Value(bool),
priority: Priority,
dpc: ke.Dpc,
timer: ke.Timer,
pub const Priority = enum {
/// Low priority background work.
@@ -45,7 +47,11 @@ pub const WorkItem = struct {
.link = undefined,
.enqueued = .init(false),
.priority = priority,
.dpc = .init(work_dpc),
.timer = undefined,
};
self.timer.init();
}
};
@@ -116,6 +122,17 @@ fn work_loop(p: ?*anyopaque) void {
}
}
/// Called when a work timer expires.
fn work_dpc(dpc: *ke.Dpc, _: ?*anyopaque) void {
const item: *WorkItem = @fieldParentPtr("dpc", dpc);
enqueue(item);
}
/// Enqueue a work item in `time`.
pub fn enqueue_in(item: *WorkItem, time: r.Nanoseconds) void {
ke.timer.set(&item.timer, time, &item.dpc);
}
/// Enqueue a work item to be executed eventually.
pub fn enqueue(item: *WorkItem) void {
// Ensure CPU stays consistent.