ke/wait: add wait_reason

This commit is contained in:
Loïc Grégoire
2026-08-02 00:02:00 -04:00
parent 05c7694776
commit 24372a2b4e
12 changed files with 21 additions and 13 deletions
+6 -3
View File
@@ -105,9 +105,9 @@ const Options = struct {
/// Wait for the provided object to be signaled.
/// This will only return an error if `timeout` is provided and
/// the wait times out.
pub fn wait_one(object: *DispatchHeader, opts: Options) !usize {
pub fn wait_one(object: *DispatchHeader, reason: []const u8, opts: Options) !usize {
var objects = [_]*DispatchHeader{object};
return wait_any(&objects, opts);
return wait_any(&objects, reason, opts);
}
/// Wait for any of the provided objects to be signaled.
@@ -116,7 +116,7 @@ pub fn wait_one(object: *DispatchHeader, opts: Options) !usize {
/// If `timeout` is not provided, it will wait indefinitely.
/// If `waitblocks` is specified, then the wait will use those waitblocks for the operation.
/// Note that if `timeout` is provided, then one additional waitblock must be allocated.
pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
pub fn wait_any(objects: []*DispatchHeader, reason: []const u8, opts: Options) !usize {
const ipl = ke.ipl.raise(.Dispatch);
defer ke.ipl.lower(ipl);
const curtd = ki.sched.percpu.local().current_thread.?;
@@ -206,6 +206,7 @@ pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
}
}
curtd.wait_reason = reason;
// We're good, now actually block.
ki.sched.block_locked(curtd);
} else {
@@ -221,6 +222,8 @@ pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
ke.timer.cancel(timer);
}
curtd.wait_reason = null;
// Find the object that satisfied us.
for (0..total_count) |i| {
const is_timer = has_timeout and i == timer_i;