mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-30 06:48:22 +00:00
ex: add enqueue_in to workqueue
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user