SDL: Use `pthread_setname_np` also on Android

From e79b0ce2e4660e7621719ca3fce362545c90cbf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bla=C5=BE=20Toma=C5=BEi=C4=8D?= <[EMAIL REDACTED]>
Date: Tue, 24 Dec 2024 08:17:18 +0100
Subject: [PATCH] Use `pthread_setname_np` also on Android

Set thread name on Android the same way as we do on Linux.

Acording to Bionic source code this function is available since 2013 [1] and
hase the same signature.

[1] https://android.googlesource.com/platform/bionic/+/2a1bb4e64677b9abbc17173c79768ed494565047
---
 src/thread/pthread/SDL_systhread.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c
index ccc09875fb154..b736293b8e9c5 100644
--- a/src/thread/pthread/SDL_systhread.c
+++ b/src/thread/pthread/SDL_systhread.c
@@ -41,7 +41,7 @@
 #include "../../core/linux/SDL_dbus.h"
 #endif /* __LINUX__ */
 
-#if (defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)) && defined(HAVE_DLOPEN)
+#if (defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__ANDROID__)) && defined(HAVE_DLOPEN)
 #include <dlfcn.h>
 #ifndef RTLD_DEFAULT
 #define RTLD_DEFAULT NULL
@@ -80,7 +80,7 @@ static void *RunThread(void *data)
 #if (defined(__MACOSX__) || defined(__IPHONEOS__)) && defined(HAVE_DLOPEN)
 static SDL_bool checked_setname = SDL_FALSE;
 static int (*ppthread_setname_np)(const char *) = NULL;
-#elif defined(__LINUX__) && defined(HAVE_DLOPEN)
+#elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_DLOPEN)
 static SDL_bool checked_setname = SDL_FALSE;
 static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
 #endif
@@ -89,17 +89,17 @@ int SDL_SYS_CreateThread(SDL_Thread *thread)
     pthread_attr_t type;
 
     /* do this here before any threads exist, so there's no race condition. */
-    #if (defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
+    #if (defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_DLOPEN)
     if (!checked_setname) {
         void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
         #if defined(__MACOSX__) || defined(__IPHONEOS__)
         ppthread_setname_np = (int(*)(const char*)) fn;
-        #elif defined(__LINUX__)
+        #elif defined(__LINUX__) || defined(__ANDROID__)
         ppthread_setname_np = (int(*)(pthread_t, const char*)) fn;
         #endif
         checked_setname = SDL_TRUE;
     }
-#endif
+    #endif
 
     /* Set the thread attributes */
     if (pthread_attr_init(&type) != 0) {
@@ -128,12 +128,12 @@ void SDL_SYS_SetupThread(const char *name)
 #endif /* !__NACL__ */
 
     if (name) {
-        #if (defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
+#if (defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_DLOPEN)
         SDL_assert(checked_setname);
         if (ppthread_setname_np) {
-            #if defined(__MACOSX__) || defined(__IPHONEOS__)
+#if defined(__MACOSX__) || defined(__IPHONEOS__)
             ppthread_setname_np(name);
-#elif defined(__LINUX__)
+#elif defined(__LINUX__) || defined(__ANDROID__)
             if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
                 char namebuf[16]; /* Limited to 16 char */
                 SDL_strlcpy(namebuf, name, sizeof(namebuf));