ke: clean up wait after continuation

This commit is contained in:
Loïc Grégoire
2026-10-04 11:37:52 -04:00
parent 8815e5e52c
commit 6701f17fb1
2 changed files with 9 additions and 9 deletions
+4 -9
View File
@@ -1113,16 +1113,13 @@ fn do_switch(cpu: *PerCpu, cur: *ke.Thread, next: *ke.Thread) void {
next.state.store(.Running, .monotonic);
if (handoff) {
const continuation = next.continuation.?;
next.context.stack_top = cur.context.stack_top;
cur.context.stack_top = 0;
next.continuation = null;
cur.switching.store(false, .release);
cur.lock.release_no_ipl();
kep.impl.call_continuation(&next.context, continuation);
ke.thread.call_continuation(next);
}
if (config.warden) {
@@ -1373,15 +1370,13 @@ pub fn yield_locked(continuation: ?ke.Continuation) void {
do_switch(sched_cpu, cur, n);
} else {
// Same thread.
const cont = cur.continuation;
cur.continuation = null;
cur.state.store(.Running, .monotonic);
cur.switching.store(false, .monotonic);
cur.lock.release_no_ipl();
if (cont) |c|
kep.impl.call_continuation(&cur.context, c);
if (cur.continuation != null) {
kep.thread.call_continuation(cur);
}
}
// cur lock dropped
+5
View File
@@ -382,6 +382,11 @@ pub fn call_continuation(ptr: ?*anyopaque) noreturn {
const td: *ke.Thread = @ptrCast(@alignCast(ptr));
std.debug.assert(td.continuation != null);
// Clean things that were set up by the wait (e.g timeout).
_ = kep.wait.post_wait(td) catch {
// Don't care about the status.
};
const cont = td.continuation.?;
td.continuation = null;