mirror of
https://github.com/janet-lang/janet
synced 2025-02-02 10:19:10 +00:00
Address #820 - ev/cancel to work on already scheduled fibers.
This commit is contained in:
parent
504411eade
commit
924fe97fc3
@ -18,8 +18,14 @@
|
||||
|
||||
@rem Set compile and link options here
|
||||
@setlocal
|
||||
|
||||
@rem Example use asan
|
||||
@rem set JANET_COMPILE=cl /nologo /Isrc\include /Isrc\conf /c /O2 /W3 /D_CRT_SECURE_NO_WARNINGS /MD /fsanitize=address /Zi
|
||||
@rem set JANET_LINK=link /nologo clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib
|
||||
|
||||
@set JANET_COMPILE=cl /nologo /Isrc\include /Isrc\conf /c /O2 /W3 /D_CRT_SECURE_NO_WARNINGS /MD
|
||||
@set JANET_LINK=link /nologo
|
||||
|
||||
@set JANET_LINK_STATIC=lib /nologo
|
||||
|
||||
@rem Add janet build tag
|
||||
|
@ -75,6 +75,7 @@ typedef struct {
|
||||
JanetFiber *fiber;
|
||||
Janet value;
|
||||
JanetSignal sig;
|
||||
uint32_t expected_sched_id; /* If the fiber has been rescheduled this loop, don't run first scheduling. */
|
||||
} JanetTask;
|
||||
|
||||
/* Wrap return value by pairing it with the callback used to handle it
|
||||
@ -447,10 +448,7 @@ const JanetAbstractType janet_stream_type = {
|
||||
|
||||
/* Register a fiber to resume with value */
|
||||
void janet_schedule_signal(JanetFiber *fiber, Janet value, JanetSignal sig) {
|
||||
if (fiber->flags & JANET_FIBER_FLAG_SCHEDULED) return;
|
||||
fiber->flags |= JANET_FIBER_FLAG_SCHEDULED;
|
||||
fiber->sched_id++;
|
||||
JanetTask t = { fiber, value, sig };
|
||||
JanetTask t = { fiber, value, sig, ++fiber->sched_id };
|
||||
janet_q_push(&janet_vm.spawn, &t, sizeof(t));
|
||||
}
|
||||
|
||||
@ -1206,9 +1204,9 @@ JanetFiber *janet_loop1(void) {
|
||||
|
||||
/* Run scheduled fibers */
|
||||
while (janet_vm.spawn.head != janet_vm.spawn.tail) {
|
||||
JanetTask task = {NULL, janet_wrap_nil(), JANET_SIGNAL_OK};
|
||||
JanetTask task = {NULL, janet_wrap_nil(), JANET_SIGNAL_OK, 0};
|
||||
janet_q_pop(&janet_vm.spawn, &task, sizeof(task));
|
||||
task.fiber->flags &= ~JANET_FIBER_FLAG_SCHEDULED;
|
||||
if (task.expected_sched_id != task.fiber->sched_id) continue;
|
||||
Janet res;
|
||||
JanetSignal sig = janet_continue_signal(task.fiber, task.value, &res, task.sig);
|
||||
void *sv = task.fiber->supervisor_channel;
|
||||
@ -2903,7 +2901,7 @@ JANET_CORE_FN(cfun_ev_deadline,
|
||||
|
||||
JANET_CORE_FN(cfun_ev_cancel,
|
||||
"(ev/cancel fiber err)",
|
||||
"Cancel a suspended fiber in the event loop. Differs from cancel in that it returns the canceled fiber immediately") {
|
||||
"Cancel a suspended fiber in the event loop. Differs from cancel in that it returns the canceled fiber immediately.") {
|
||||
janet_fixarity(argc, 2);
|
||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||
Janet err = argv[1];
|
||||
|
@ -47,7 +47,6 @@
|
||||
#define JANET_FIBER_MASK_USER 0x3FF0
|
||||
|
||||
#define JANET_FIBER_STATUS_MASK 0x3F0000
|
||||
#define JANET_FIBER_FLAG_SCHEDULED 0x800000
|
||||
#define JANET_FIBER_RESUME_SIGNAL 0x400000
|
||||
#define JANET_FIBER_STATUS_OFFSET 16
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user