From 2a0c6ecba9203948b89e60496df8729be7b2ed4b Mon Sep 17 00:00:00 2001 From: NORALDM Date: Wed, 7 Jan 2026 09:52:54 +0000 Subject: [PATCH] Remove dependency on obsolete bthread.h on Termux Use pthread_exit and a signal handler to emulate pthread_cancel in async mode. --- src/thread.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/thread.c b/src/thread.c index 431af440a..a939dec08 100644 --- a/src/thread.c +++ b/src/thread.c @@ -2,9 +2,6 @@ #include "cli.h" #include -#ifdef __TERMUX__ -#include -#endif #include #ifndef _WIN32 @@ -20,17 +17,36 @@ double cli_speed_time = 1.0; volatile int cli__reset = 1; static int unloaded = 0; +#ifdef __TERMUX__ +static void thread_signal_handler(int signum) { + pthread_exit(0); +} +#endif + void* clic_thread_func(void *arg) { #ifndef _WIN32 sigset_t set; sigfillset(&set); + +#ifdef __TERMUX__ + sigdelset(&set, SIGUSR1); +#endif + int ret = pthread_sigmask(SIG_SETMASK, &set, NULL); /* We chicken out if the signals cannot be blocked. */ if (ret) return NULL; #endif +#ifndef __TERMUX__ int old; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); +#else + struct sigaction actions = { 0 }; + sigfillset(&actions.sa_mask); + actions.sa_flags = 0; + actions.sa_handler = thread_signal_handler; + sigaction(SIGUSR1, &actions, NULL); +#endif while (1) { /* TODO: handle signals */ @@ -100,7 +116,11 @@ int cli__kill_thread(void) { /* This should not happen, but be extra careful */ if (tick_thread) { +#ifndef __TERMUX__ ret = pthread_cancel(tick_thread); +#else + ret = pthread_kill(tick_thread, SIGUSR1); +#endif if (ret) { /* If we could not cancel, then accept the memory leak. We do not try to free the R object, because the tick