aboutsummaryrefslogtreecommitdiff
path: root/Lib/java
diff options
context:
space:
mode:
authorSam Hasinoff <hasinoff@google.com>2018-10-04 17:59:38 -0700
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2018-10-08 21:24:34 +0100
commit989f4289c16f7d298e9c0f5c63b58248771aaa67 (patch)
tree642450f385831cbaefb38f2e6216b8ffd1d8e453 /Lib/java
parent8dd86344209772d0afdd17580e12d35306310d80 (diff)
downloadswig-989f4289c16f7d298e9c0f5c63b58248771aaa67.tar.gz
Use prctl method to get thread names, which is available on all NDK versions
Diffstat (limited to 'Lib/java')
-rw-r--r--Lib/java/director.swg17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/java/director.swg b/Lib/java/director.swg
index de3eb5603..ba06f9e0a 100644
--- a/Lib/java/director.swg
+++ b/Lib/java/director.swg
@@ -5,13 +5,16 @@
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
+#if defined(__ANDROID__)
+#include <sys/prctl.h>
+#endif
+
#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION)
+#if defined(__ANDROID__)
#include <errno.h>
#include <string.h>
-#include <iostream>
#endif
-#if defined(__ANDROID__)
-#include <pthread.h>
+#include <iostream>
#endif
#include <exception>
@@ -149,17 +152,15 @@ namespace Swig {
args.group = NULL;
args.name = NULL;
#if defined(__ANDROID__)
-#if defined(__ANDROID_API__) && __ANDROID_API__ >= 26
char thread_name[16]; // MAX_TASK_COMM_LEN=16 is hard-coded in the kernel.
- if (pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name)) == 0) {
+ if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) == 0) {
args.name = thread_name;
} else {
-#if defined(DEBUG_DIRECTOR_OWNED)
- std::cout << "JNIEnvWrapper: Couldn't get thread name: " << strerror(errno) << std::endl;
+#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION)
+ std::cerr << "JNIEnvWrapper: Couldn't set thread name: " << strerror(errno) << std::endl;
#endif
}
#endif
-#endif
#if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
// Attach a daemon thread to the JVM. Useful when the JVM should not wait for
// the thread to exit upon shutdown. Only for jdk-1.4 and later.