Skip to content

Commit

Permalink
Skip pthread_setcancelstate on android
Browse files Browse the repository at this point in the history
Android doesn't support cancelling threads, so theres
no reason to set the cancel state

Signed-off-by: Sean Breckenridge <[email protected]>
  • Loading branch information
seanbreckenridge committed Sep 19, 2023
1 parent 3107d57 commit 049f40d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Skip calls to pthread_cancelstate on android, as its not available (#52)

- Fix compatibility with systems that do not define `PIPE_BUF`. Use
`_POSIX_PIPE_BUF` as a fallback. (#49)

Expand Down
9 changes: 9 additions & 0 deletions src/spawn_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,15 @@ CAMLprim value spawn_unix(value v_env,
For instance:
http://git.musl-libc.org/cgit/musl/tree/src/process/posix_spawn.c
On android, pthread_cancel is not implemented, it is typically
patched out or in certain cases reimplemented with atomic_flags
https://github.com/search?q=org%3Atermux+pthread_setcancelstate+language%3ADiff&type=code&l=Diff
*/

#if !defined(__ANDROID__)
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
#endif
sigfillset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, &saved_procmask);

Expand Down Expand Up @@ -542,7 +549,9 @@ CAMLprim value spawn_unix(value v_env,

close(result_pipe[0]);
pthread_sigmask(SIG_SETMASK, &saved_procmask, NULL);
#if !defined(__ANDROID__)
pthread_setcancelstate(cancel_state, NULL);
#endif

caml_leave_blocking_section();

Expand Down

0 comments on commit 049f40d

Please sign in to comment.