1
0
mirror of https://github.com/janet-lang/janet synced 2025-06-09 18:14:12 +00:00

Merge pull request #1582 from pyrmont/bugfix.termux-pthread_cancel

Fix absence of pthread_cancel in Android
This commit is contained in:
Calvin Rose 2025-04-09 20:16:57 -05:00 committed by GitHub
commit 5ebe945ffd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
- Make `ffi/write` append to a buffer instead of insert at 0 by default. - Make `ffi/write` append to a buffer instead of insert at 0 by default.
- Add `os/getpid` to get the current process id. - Add `os/getpid` to get the current process id.
- Add `:out` option to `os/spawn` to be able to redirect stderr to stdout with pipes. - Add `:out` option to `os/spawn` to be able to redirect stderr to stdout with pipes.
Add `interrupt?` argument to `ev/deadline` to use VM interruptions.
## 1.38.0 - 2025-03-18 ## 1.38.0 - 2025-03-18
- Add `bundle/replace` - Add `bundle/replace`

View File

@ -652,6 +652,12 @@ static VOID CALLBACK janet_timeout_stop(ULONG_PTR ptr) {
UNREFERENCED_PARAMETER(ptr); UNREFERENCED_PARAMETER(ptr);
ExitThread(0); ExitThread(0);
} }
#elif JANET_ANDROID
static void janet_timeout_stop(int sig_num) {
if(sig_num == SIGUSR1) {
pthread_exit(0);
}
}
#endif #endif
static void janet_timeout_cb(JanetEVGenericMessage msg) { static void janet_timeout_cb(JanetEVGenericMessage msg) {
@ -673,6 +679,14 @@ static DWORD WINAPI janet_timeout_body(LPVOID ptr) {
} }
#else #else
static void *janet_timeout_body(void *ptr) { static void *janet_timeout_body(void *ptr) {
#ifdef JANET_ANDROID
struct sigaction action;
memset(&action, 0, sizeof(action));
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
action.sa_handler = &janet_timeout_stop;
sigaction(SIGUSR1, &action, NULL);
#endif
JanetThreadedTimeout tto = *(JanetThreadedTimeout *)ptr; JanetThreadedTimeout tto = *(JanetThreadedTimeout *)ptr;
janet_free(ptr); janet_free(ptr);
struct timespec ts; struct timespec ts;
@ -1489,8 +1503,12 @@ JanetFiber *janet_loop1(void) {
QueueUserAPC(janet_timeout_stop, to.worker, 0); QueueUserAPC(janet_timeout_stop, to.worker, 0);
WaitForSingleObject(to.worker, INFINITE); WaitForSingleObject(to.worker, INFINITE);
CloseHandle(to.worker); CloseHandle(to.worker);
#else
#ifdef JANET_ANDROID
pthread_kill(to.worker, SIGUSR1);
#else #else
pthread_cancel(to.worker); pthread_cancel(to.worker);
#endif
void *res; void *res;
pthread_join(to.worker, &res); pthread_join(to.worker, &res);
#endif #endif
@ -3188,6 +3206,9 @@ JANET_CORE_FN(cfun_ev_deadline,
to.is_error = 0; to.is_error = 0;
to.sched_id = to.fiber->sched_id; to.sched_id = to.fiber->sched_id;
if (use_interrupt) { if (use_interrupt) {
#ifdef JANET_ANDROID
janet_sandbox_assert(JANET_SANDBOX_SIGNAL);
#endif
JanetThreadedTimeout *tto = janet_malloc(sizeof(JanetThreadedTimeout)); JanetThreadedTimeout *tto = janet_malloc(sizeof(JanetThreadedTimeout));
if (NULL == tto) { if (NULL == tto) {
JANET_OUT_OF_MEMORY; JANET_OUT_OF_MEMORY;

View File

@ -67,6 +67,11 @@ extern "C" {
#define JANET_LINUX 1 #define JANET_LINUX 1
#endif #endif
/* Check for Android */
#ifdef __ANDROID__
#define JANET_ANDROID 1
#endif
/* Check for Cygwin */ /* Check for Cygwin */
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
#define JANET_CYGWIN 1 #define JANET_CYGWIN 1