mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-27 13:58:20 +00:00
ke: clean up wait after continuation
This commit is contained in:
+4
-9
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user