1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 17:00:27 +00:00

Address #876 Don't allow scheduling a fiber once it has been canceled already.

We were effectively cancelling the cancellation.
This commit is contained in:
Calvin Rose 2021-11-18 20:06:29 -06:00
parent af946f398e
commit 6f7e81067c
4 changed files with 7 additions and 3 deletions

View File

@ -464,7 +464,9 @@ const JanetAbstractType janet_stream_type = {
/* Register a fiber to resume with value */ /* Register a fiber to resume with value */
void janet_schedule_signal(JanetFiber *fiber, Janet value, JanetSignal sig) { void janet_schedule_signal(JanetFiber *fiber, Janet value, JanetSignal sig) {
if (fiber->flags & JANET_FIBER_FLAG_CANCELED) return;
JanetTask t = { fiber, value, sig, ++fiber->sched_id }; JanetTask t = { fiber, value, sig, ++fiber->sched_id };
if (sig == JANET_SIGNAL_ERROR) fiber->flags |= JANET_FIBER_FLAG_CANCELED;
janet_q_push(&janet_vm.spawn, &t, sizeof(t)); janet_q_push(&janet_vm.spawn, &t, sizeof(t));
} }
@ -1226,6 +1228,7 @@ JanetFiber *janet_loop1(void) {
while (janet_vm.spawn.head != janet_vm.spawn.tail) { while (janet_vm.spawn.head != janet_vm.spawn.tail) {
JanetTask task = {NULL, janet_wrap_nil(), JANET_SIGNAL_OK, 0}; JanetTask task = {NULL, janet_wrap_nil(), JANET_SIGNAL_OK, 0};
janet_q_pop(&janet_vm.spawn, &task, sizeof(task)); janet_q_pop(&janet_vm.spawn, &task, sizeof(task));
task.fiber->flags &= ~JANET_FIBER_FLAG_CANCELED;
if (task.expected_sched_id != task.fiber->sched_id) continue; if (task.expected_sched_id != task.fiber->sched_id) continue;
Janet res; Janet res;
JanetSignal sig = janet_continue_signal(task.fiber, task.value, &res, task.sig); JanetSignal sig = janet_continue_signal(task.fiber, task.value, &res, task.sig);

View File

@ -48,6 +48,7 @@
#define JANET_FIBER_STATUS_MASK 0x3F0000 #define JANET_FIBER_STATUS_MASK 0x3F0000
#define JANET_FIBER_RESUME_SIGNAL 0x400000 #define JANET_FIBER_RESUME_SIGNAL 0x400000
#define JANET_FIBER_FLAG_CANCELED 0x400000
#define JANET_FIBER_STATUS_OFFSET 16 #define JANET_FIBER_STATUS_OFFSET 16
#define JANET_FIBER_BREAKPOINT 0x1000000 #define JANET_FIBER_BREAKPOINT 0x1000000

View File

@ -689,12 +689,12 @@ static int janet_proc_get(void *p, Janet key, Janet *out) {
*out = (NULL == proc->err) ? janet_wrap_nil() : janet_wrap_abstract(proc->err); *out = (NULL == proc->err) ? janet_wrap_nil() : janet_wrap_abstract(proc->err);
return 1; return 1;
} }
#ifndef JANET_WINDOWS #ifndef JANET_WINDOWS
if (janet_keyeq(key, "pid")) { if (janet_keyeq(key, "pid")) {
*out = janet_wrap_number(proc->pid); *out = janet_wrap_number(proc->pid);
return 1; return 1;
} }
#endif #endif
if ((-1 != proc->return_code) && janet_keyeq(key, "return-code")) { if ((-1 != proc->return_code) && janet_keyeq(key, "return-code")) {
*out = janet_wrap_integer(proc->return_code); *out = janet_wrap_integer(proc->return_code);
return 1; return 1;