Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clang compilation failure on Android #1687

Merged
merged 1 commit into from
May 24, 2024
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
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>
tqfx marked this conversation as resolved.
Show resolved Hide resolved
#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) {
tqfx marked this conversation as resolved.
Show resolved Hide resolved
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
tqfx marked this conversation as resolved.
Show resolved Hide resolved
#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)
Loading