1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00

Address #1405 - don't try and resume fibers that can't be resumed.

FOr fibers that _can_ be resumed and then get cancelled, the sched_id
will be incremented later prevent the spurious wake ups.
This commit is contained in:
Calvin Rose 2024-02-19 08:37:49 -06:00
parent e66dc14b3a
commit c9897f99c3

View File

@ -1166,6 +1166,7 @@ JANET_CORE_FN(cfun_channel_close,
msg.argj = janet_wrap_nil();
janet_ev_post_event(vm, janet_thread_chan_cb, msg);
} else {
if (janet_fiber_can_resume(writer.fiber)) {
if (writer.mode == JANET_CP_MODE_CHOICE_WRITE) {
janet_schedule(writer.fiber, make_close_result(channel));
} else {
@ -1173,6 +1174,7 @@ JANET_CORE_FN(cfun_channel_close,
}
}
}
}
JanetChannelPending reader;
while (!janet_q_pop(&channel->read_pending, &reader, sizeof(reader))) {
if (reader.thread != &janet_vm) {
@ -1185,6 +1187,7 @@ JANET_CORE_FN(cfun_channel_close,
msg.argj = janet_wrap_nil();
janet_ev_post_event(vm, janet_thread_chan_cb, msg);
} else {
if (janet_fiber_can_resume(reader.fiber)) {
if (reader.mode == JANET_CP_MODE_CHOICE_READ) {
janet_schedule(reader.fiber, make_close_result(channel));
} else {
@ -1193,6 +1196,7 @@ JANET_CORE_FN(cfun_channel_close,
}
}
}
}
janet_chan_unlock(channel);
return argv[0];
}