~bakpakin/janet

ca4c1e4259318faee1b3d239dcc5eef08cdeea08 — Calvin Rose 1 year, 19 days ago 91712ad sigaction
Try to use atomics inside signal handler for ref count.
2 files changed, 11 insertions(+), 3 deletions(-)

M src/core/ev.c
M src/core/state.h
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;