-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pthread missing functions in Android
- Loading branch information
1 parent
b5eb3a4
commit d80b914
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "iperf_config.h" | ||
|
||
#if defined(HAVE_PTHREAD) | ||
|
||
#include <pthread.h> | ||
|
||
#if defined(__ANDROID__) | ||
|
||
/* Adding missing `pthread` related definitions in Android. | ||
*/ | ||
|
||
#define PTHREAD_CANCEL_ASYNCHRONOUS 0 | ||
#define PTHREAD_CANCEL_ENABLE NULL | ||
|
||
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) |