Merge branch 'java-director-thread-name'
* java-director-thread-name: Add changes entry for setting Java thread name Increased Java thread name size. Java directors - more generic thread name setting Use prctl method to get thread names, which is available on all NDK versions Actually, pthread_getname_np is only available in recent versions of Android (API level >= 26). Set thread name when attaching to Android JVM in SWIG Java director
This commit is contained in:
commit
d835c69d65
4 changed files with 94 additions and 4 deletions
|
|
@ -7,6 +7,11 @@
|
|||
%module(directors="1") director_thread
|
||||
#endif
|
||||
|
||||
%begin %{
|
||||
#define SWIG_JAVA_USE_THREAD_NAME
|
||||
//#define DEBUG_DIRECTOR_THREAD_NAME
|
||||
%}
|
||||
|
||||
%{
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
|
@ -89,10 +94,23 @@ extern "C" {
|
|||
fprintf(stderr, "pthread_create failed in run()\n");
|
||||
assert(0);
|
||||
}
|
||||
int setname = pthread_setname_np(thread, "MyThreadName");
|
||||
if (setname != 0) {
|
||||
fprintf(stderr, "pthread_setname_np failed in run()\n");
|
||||
assert(0);
|
||||
}
|
||||
%#endif
|
||||
MilliSecondSleep(500);
|
||||
}
|
||||
|
||||
|
||||
static bool namedThread() {
|
||||
%#ifdef _WIN32
|
||||
return false;
|
||||
%#else
|
||||
return true;
|
||||
%#endif
|
||||
}
|
||||
|
||||
virtual void do_foo() {
|
||||
val += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ class director_thread_Derived extends Foo {
|
|||
}
|
||||
|
||||
public void do_foo() {
|
||||
// Not all operating systems can name threads, so only test on those that can
|
||||
if (Foo.namedThread()) {
|
||||
String threadName = Thread.currentThread().getName();
|
||||
if (!threadName.equals("MyThreadName"))
|
||||
throw new RuntimeException("Unexpected thread name: " + threadName);
|
||||
}
|
||||
setVal(getVal() - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue