diff --git a/build_win.bat b/build_win.bat index 5980cc46..aae50a6c 100644 --- a/build_win.bat +++ b/build_win.bat @@ -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 @@ -81,7 +87,7 @@ exit /b 1 @echo command prompt. exit /b 0 -@rem Clean build artifacts +@rem Clean build artifacts :CLEAN del *.exe *.lib *.exp rd /s /q build diff --git a/src/core/ev.c b/src/core/ev.c index 7732b14d..c939bceb 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -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]; diff --git a/src/core/fiber.h b/src/core/fiber.h index 5c46f4da..b6dcd1ba 100644 --- a/src/core/fiber.h +++ b/src/core/fiber.h @@ -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