mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-10 17:27:30 -10:00
The Android JNI glue in frontend/drivers/platform_unix.c held the per-thread JNIEnv* in a raw pthread_key_t, created with pthread_key_create(..., jni_thread_destruct) so the JVM is detached when a thread exits, and updated with pthread_setspecific(). rthreads already wraps TLS (sthread_tls_*), but sthread_tls_create() passes a NULL destructor, so it could not preserve the detach-on-exit behaviour. Add sthread_tls_create_with_dtor(), which forwards a pthread_key_create() destructor on pthread backends (Win32 TlsAlloc has no destructor callback and ignores it -- documented; current users are POSIX). Route the driver through it plus sthread_tls_set(), change thread_key to sthread_tls_t, and drop <pthread.h> for <rthreads/rthreads.h>. The destructor (jni_thread_destruct) is preserved, so JVM detach on thread teardown is unchanged. platform_unix.c no longer makes direct pthread calls. No functional change on Android.