Skip to content

Commit 2deec16

Browse files
authored
Merge pull request #145 from fornwall/android-main-thread-name
Name spawned threads
2 parents bfd8bfd + eeeb802 commit 2deec16

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

android-activity/src/game_activity/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ pub unsafe extern "C" fn _rust_glue_entry(native_app: *mut ffi::android_app) {
925925
};
926926

927927
unsafe {
928+
// Name thread - this needs to happen here after attaching to a JVM thread,
929+
// since that changes the thread name to something like "Thread-2".
930+
let thread_name = std::ffi::CStr::from_bytes_with_nul(b"android_main\0").unwrap();
931+
libc::pthread_setname_np(libc::pthread_self(), thread_name.as_ptr());
932+
928933
let app = AndroidApp::from_ptr(NonNull::new(native_app).unwrap(), jvm.clone());
929934

930935
// We want to specifically catch any panic from the application's android_main

android-activity/src/native_activity/glue.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ extern "C" fn ANativeActivity_onCreate(
868868
rust_glue.notify_main_thread_running();
869869

870870
unsafe {
871+
// Name thread - this needs to happen here after attaching to a JVM thread,
872+
// since that changes the thread name to something like "Thread-2".
873+
let thread_name = std::ffi::CStr::from_bytes_with_nul(b"android_main\0").unwrap();
874+
libc::pthread_setname_np(libc::pthread_self(), thread_name.as_ptr());
875+
871876
// We want to specifically catch any panic from the application's android_main
872877
// so we can finish + destroy the Activity gracefully via the JVM
873878
catch_unwind(|| {

0 commit comments

Comments
 (0)