File tree Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ libiperf_la_SOURCES = \
33
33
iperf_util.h \
34
34
iperf_time.c \
35
35
iperf_time.h \
36
+ iperf_pthread.c \
37
+ iperf_pthread.h \
36
38
dscp.c \
37
39
net.c \
38
40
net.h \
Original file line number Diff line number Diff line change 61
61
#include <openssl/evp.h>
62
62
#endif // HAVE_SSL
63
63
64
- #ifdef HAVE_PTHREAD
65
- #include <pthread.h>
66
- #endif // HAVE_PTHREAD
64
+ #include "iperf_pthread.h"
67
65
68
66
/*
69
67
* Atomic types highly desired, but if not, we approximate what we need
Original file line number Diff line number Diff line change
1
+ #include "iperf_config.h"
2
+
3
+ #if defined(HAVE_PTHREAD ) && defined(__ANDROID__ )
4
+
5
+ /* Workaround for `pthread_cancel()` in Android, using `pthread_kill()` instead,
6
+ * as Android NDK does not support `pthread_cancel()`.
7
+ */
8
+
9
+ #include <signal.h>
10
+ #include "iperf_pthread.h"
11
+
12
+ int pthread_setcanceltype (int type , int * oldtype ) { return 0 ; }
13
+ int pthread_setcancelstate (int state , int * oldstate ) { return 0 ; }
14
+ int pthread_cancel (pthread_t thread_id ) {
15
+ int status ;
16
+ if ((status = iperf_set_thread_exit_handler ()) == 0 ) {
17
+ status = pthread_kill (thread_id , SIGUSR1 );
18
+ }
19
+ return status ;
20
+ }
21
+
22
+ void iperf_thread_exit_handler (int sig )
23
+ {
24
+ pthread_exit (0 );
25
+ }
26
+
27
+ int iperf_set_thread_exit_handler () {
28
+ int rc ;
29
+ struct sigaction actions ;
30
+
31
+ memset (& actions , 0 , sizeof (actions ));
32
+ sigemptyset (& actions .sa_mask );
33
+ actions .sa_flags = 0 ;
34
+ actions .sa_handler = iperf_thread_exit_handler ;
35
+
36
+ rc = sigaction (SIGUSR1 , & actions , NULL );
37
+ return rc ;
38
+ }
39
+
40
+ #endif // defined(HAVE_PTHREAD) && defined(__ANDROID__)
Original file line number Diff line number Diff line change
1
+ #include "iperf_config.h"
2
+
3
+ #if defined(HAVE_PTHREAD )
4
+
5
+ #include <pthread.h>
6
+
7
+ #if defined(__ANDROID__ )
8
+
9
+ /* Adding missing `pthread` related definitions in Android.
10
+ */
11
+
12
+ #define PTHREAD_CANCEL_ASYNCHRONOUS 0
13
+ #define PTHREAD_CANCEL_ENABLE NULL
14
+
15
+ int pthread_setcanceltype (int type , int * oldtype );
16
+ int pthread_setcancelstate (int state , int * oldstate );
17
+ int pthread_cancel (pthread_t thread_id );
18
+
19
+ #endif // defined(__ANDROID__)
20
+
21
+ #endif // defined(HAVE_PTHREAD)
You can’t perform that action at this time.
0 commit comments