1
0
mirror of https://github.com/janet-lang/janet synced 2025-06-07 00:54:12 +00:00

Fix absence of pthread_cancel in Android

This commit is contained in:
Michael Camilleri 2025-04-09 10:00:14 +09:00
parent 90a33bc88a
commit 5705b2f6c7
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572
2 changed files with 26 additions and 0 deletions

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