diff --git a/src/kern/sched.zig b/src/kern/sched.zig index e7414eb..96eb1ef 100644 --- a/src/kern/sched.zig +++ b/src/kern/sched.zig @@ -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 diff --git a/src/kern/thread.zig b/src/kern/thread.zig index b167410..05bd620 100644 --- a/src/kern/thread.zig +++ b/src/kern/thread.zig @@ -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;