Skip to content

Commit

Permalink
Merge pull request #1687 from tqfx/patch-1
Browse files Browse the repository at this point in the history
Fix clang compilation failure on Android
  • Loading branch information
swlars authored May 24, 2024
2 parents 93c60bf + 6f1e96f commit 6254d11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions src/iperf_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@
* as Android NDK does not support `pthread_cancel()`.
*/

#include <string.h>
#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));
memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_flags = 0;
actions.sa_handler = iperf_thread_exit_handler;

rc = sigaction(SIGUSR1, &actions, NULL);
return rc;
}

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;
}

#endif // defined(HAVE_PTHREAD) && defined(__ANDROID__)
4 changes: 2 additions & 2 deletions src/iperf_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*/

#define PTHREAD_CANCEL_ASYNCHRONOUS 0
#define PTHREAD_CANCEL_ENABLE NULL
#define PTHREAD_CANCEL_ENABLE 0

int pthread_setcanceltype(int type, int *oldtype);
int pthread_setcancelstate(int state, int *oldstate);
int pthread_cancel(pthread_t thread_id);

#endif // defined(__ANDROID__)

#endif // defined(HAVE_PTHREAD)
#endif // defined(HAVE_PTHREAD)

0 comments on commit 6254d11

Please sign in to comment.