Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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 `interrupt?` argument to `ev/deadline` to use VM interruptions.

## 1.38.0 - 2025-03-18
- Add `bundle/replace`
Expand Down
21 changes: 21 additions & 0 deletions src/core/ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ static VOID CALLBACK janet_timeout_stop(ULONG_PTR ptr) {
UNREFERENCED_PARAMETER(ptr);
ExitThread(0);
}
#elif JANET_ANDROID
static void janet_timeout_stop(int sig_num) {
if(sig_num == SIGUSR1) {
pthread_exit(0);
}
}
#endif

static void janet_timeout_cb(JanetEVGenericMessage msg) {
Expand All @@ -673,6 +679,14 @@ static DWORD WINAPI janet_timeout_body(LPVOID ptr) {
}
#else
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;
janet_free(ptr);
struct timespec ts;
Expand Down Expand Up @@ -1489,8 +1503,12 @@ JanetFiber *janet_loop1(void) {
QueueUserAPC(janet_timeout_stop, to.worker, 0);
WaitForSingleObject(to.worker, INFINITE);
CloseHandle(to.worker);
#else
#ifdef JANET_ANDROID
pthread_kill(to.worker, SIGUSR1);
#else
pthread_cancel(to.worker);
#endif
void *res;
pthread_join(to.worker, &res);
#endif
Expand Down Expand Up @@ -3188,6 +3206,9 @@ JANET_CORE_FN(cfun_ev_deadline,
to.is_error = 0;
to.sched_id = to.fiber->sched_id;
if (use_interrupt) {
#ifdef JANET_ANDROID
janet_sandbox_assert(JANET_SANDBOX_SIGNAL);
#endif
JanetThreadedTimeout *tto = janet_malloc(sizeof(JanetThreadedTimeout));
if (NULL == tto) {
JANET_OUT_OF_MEMORY;
Expand Down
5 changes: 5 additions & 0 deletions src/include/janet.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ extern "C" {
#define JANET_LINUX 1
#endif

/* Check for Android */
#ifdef __ANDROID__
#define JANET_ANDROID 1
#endif

/* Check for Cygwin */
#if defined(__CYGWIN__)
#define JANET_CYGWIN 1
Expand Down