From 120b41c8cae9530811254c9e2ad3e26784d03977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Fri, 3 Jul 2026 10:27:29 -0400 Subject: [PATCH] ex: add enqueue_in to workqueue --- src/ex/root.zig | 1 + src/ex/workqueue.zig | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/ex/root.zig b/src/ex/root.zig index a5327eb..85d9932 100644 --- a/src/ex/root.zig +++ b/src/ex/root.zig @@ -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 { diff --git a/src/ex/workqueue.zig b/src/ex/workqueue.zig index 64b7aa1..192f11f 100644 --- a/src/ex/workqueue.zig +++ b/src/ex/workqueue.zig @@ -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.