M src/core/ev.c => src/core/ev.c +10 -2
@@ 603,11 603,19 @@ void janet_addtimeout(double sec) {
}
void janet_ev_inc_refcount(void) {
- janet_vm.extra_listeners++;
+#ifdef JANET_WINDOWS
+ InterlockedIncrement(&janet_vm.extra_listeners);
+#else
+ __atomic_add_fetch(&janet_vm.extra_listeners, 1, __ATOMIC_RELAXED);
+#endif
}
void janet_ev_dec_refcount(void) {
- janet_vm.extra_listeners--;
+#ifdef JANET_WINDOWS
+ InterlockedDecrement(&janet_vm.extra_listeners);
+#else
+ __atomic_add_fetch(&janet_vm.extra_listeners, -1, __ATOMIC_RELAXED);
+#endif
}
/* Channels */
M src/core/state.h => src/core/state.h +1 -1
@@ 157,7 157,7 @@ struct JanetVM {
JanetListenerState **listeners;
size_t listener_count;
size_t listener_cap;
- size_t extra_listeners;
+ volatile size_t extra_listeners; /* used in signal handler, must be volatile */
JanetTable threaded_abstracts; /* All abstract types that can be shared between threads (used in this thread) */
JanetTable active_tasks; /* All possibly live task fibers - used just for tracking */
JanetTable signal_handlers;