diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:27:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:27:01 +0000 |
commit | 6f4c2968d9a035183d937cb055aec739c05280b1 (patch) | |
tree | 3e3270402258677b8ceb7f0db4c68e2123371d97 /src/iperf_pthread.c | |
parent | Adding upstream version 3.16. (diff) | |
download | iperf3-upstream.tar.xz iperf3-upstream.zip |
Adding upstream version 3.17.1.upstream/3.17.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/iperf_pthread.c')
-rw-r--r-- | src/iperf_pthread.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/iperf_pthread.c b/src/iperf_pthread.c new file mode 100644 index 0000000..ea4918b --- /dev/null +++ b/src/iperf_pthread.c @@ -0,0 +1,40 @@ +#include "iperf_config.h" + +#if defined(HAVE_PTHREAD) && defined(__ANDROID__) + +/* Workaround for `pthread_cancel()` in Android, using `pthread_kill()` instead, + * as Android NDK does not support `pthread_cancel()`. + */ + +#include <signal.h> +#include "iperf_pthread.h" + +int pthread_setcanceltype(int type, int *oldtype) { return 0; } +int pthread_setcancelstate(int state, int *oldstate) { return 0; } +int pthread_cancel(pthread_t thread_id) { + int status; + if ((status = iperf_set_thread_exit_handler()) == 0) { + status = pthread_kill(thread_id, SIGUSR1); + } + return status; +} + +void iperf_thread_exit_handler(int sig) +{ + pthread_exit(0); +} + +int iperf_set_thread_exit_handler() { + int rc; + struct sigaction actions; + + memset(&actions, 0, sizeof(actions)); + sigemptyset(&actions.sa_mask); + actions.sa_flags = 0; + actions.sa_handler = iperf_thread_exit_handler; + + rc = sigaction(SIGUSR1, &actions, NULL); + return rc; +} + +#endif // defined(HAVE_PTHREAD) && defined(__ANDROID__) |