// Throw jl_interrupt_exception if the master thread is in a signal async region // or if SIGINT happens too often. static void jl_try_deliver_sigint(void) { jl_tls_states_t *ptls = jl_all_task_states[0].ptls; jl_safepoint_enable_sigint(); jl_wake_libuv(); jl_atomic_store_release(&ptls->signal_request, 2); // This also makes sure `sleep` is aborted. pthread_kill(jl_all_task_states[0].system_id, SIGUSR2); }
JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) { jl_ptls_t ptls = jl_get_ptls_states(); /* ensure thread tid is awake if necessary */ if (ptls->tid != tid && !_threadedregion && tid != -1) { uv_mutex_lock(&sleep_lock); uv_cond_broadcast(&sleep_alarm); // TODO: make this uv_cond_signal / just wake up correct thread uv_mutex_unlock(&sleep_lock); } if (_threadedregion && jl_uv_mutex.owner != jl_thread_self()) jl_wake_libuv(); else uv_stop(jl_global_event_loop()); }
static void jl_try_throw_sigint(void) { jl_ptls_t ptls = jl_get_ptls_states(); jl_safepoint_enable_sigint(); jl_wake_libuv(); int force = jl_check_force_sigint(); if (force || (!ptls->defer_signal && ptls->io_wait)) { jl_safepoint_consume_sigint(); if (force) jl_safe_printf("WARNING: Force throwing a SIGINT\n"); // Force a throw jl_clear_force_sigint(); jl_throw(jl_interrupt_exception); } }
// Try to throw the exception in the master thread. static void jl_try_deliver_sigint(void) { jl_ptls_t ptls2 = jl_all_tls_states[0]; jl_safepoint_enable_sigint(); jl_wake_libuv(); if ((DWORD)-1 == SuspendThread(hMainThread)) { // error jl_safe_printf("error: SuspendThread failed\n"); return; } int force = jl_check_force_sigint(); if (force || (!ptls2->defer_signal && ptls2->io_wait)) { jl_safepoint_consume_sigint(); if (force) jl_safe_printf("WARNING: Force throwing a SIGINT\n"); // Force a throw jl_clear_force_sigint(); CONTEXT ctxThread; memset(&ctxThread, 0, sizeof(CONTEXT)); ctxThread.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; if (!GetThreadContext(hMainThread, &ctxThread)) { // error jl_safe_printf("error: GetThreadContext failed\n"); return; } jl_throw_in_ctx(jl_interrupt_exception, &ctxThread, 1); ctxThread.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; if (!SetThreadContext(hMainThread, &ctxThread)) { jl_safe_printf("error: SetThreadContext failed\n"); // error return; } } if ((DWORD)-1 == ResumeThread(hMainThread)) { jl_safe_printf("error: ResumeThread failed\n"); // error return; } }