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] 2a1bb4e646
(cherry picked from commit e79b0ce2e4660e7621719ca3fce362545c90cbf7)
This commit is contained in:
committed by
Sam Lantinga
parent
578509c326
commit
e9290eeedf
@@ -40,7 +40,7 @@
|
|||||||
#include "../../core/linux/SDL_dbus.h"
|
#include "../../core/linux/SDL_dbus.h"
|
||||||
#endif // SDL_PLATFORM_LINUX
|
#endif // SDL_PLATFORM_LINUX
|
||||||
|
|
||||||
#if (defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
#if (defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#ifndef RTLD_DEFAULT
|
#ifndef RTLD_DEFAULT
|
||||||
#define RTLD_DEFAULT NULL
|
#define RTLD_DEFAULT NULL
|
||||||
@@ -77,7 +77,7 @@ static void *RunThread(void *data)
|
|||||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
||||||
static bool checked_setname = false;
|
static bool checked_setname = false;
|
||||||
static int (*ppthread_setname_np)(const char *) = NULL;
|
static int (*ppthread_setname_np)(const char *) = NULL;
|
||||||
#elif defined(SDL_PLATFORM_LINUX) && defined(HAVE_DLOPEN)
|
#elif (defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID)) && defined(HAVE_DLOPEN)
|
||||||
static bool checked_setname = false;
|
static bool checked_setname = false;
|
||||||
static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
|
static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
|
||||||
#endif
|
#endif
|
||||||
@@ -88,17 +88,17 @@ bool SDL_SYS_CreateThread(SDL_Thread *thread,
|
|||||||
pthread_attr_t type;
|
pthread_attr_t type;
|
||||||
|
|
||||||
// do this here before any threads exist, so there's no race condition.
|
// do this here before any threads exist, so there's no race condition.
|
||||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX)) && defined(HAVE_DLOPEN)
|
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID)) && defined(HAVE_DLOPEN)
|
||||||
if (!checked_setname) {
|
if (!checked_setname) {
|
||||||
void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
||||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||||
ppthread_setname_np = (int (*)(const char *))fn;
|
ppthread_setname_np = (int (*)(const char *))fn;
|
||||||
#elif defined(SDL_PLATFORM_LINUX)
|
#elif defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID)
|
||||||
ppthread_setname_np = (int (*)(pthread_t, const char *))fn;
|
ppthread_setname_np = (int (*)(pthread_t, const char *))fn;
|
||||||
#endif
|
#endif
|
||||||
checked_setname = true;
|
checked_setname = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set the thread attributes
|
// Set the thread attributes
|
||||||
if (pthread_attr_init(&type) != 0) {
|
if (pthread_attr_init(&type) != 0) {
|
||||||
@@ -127,12 +127,12 @@ void SDL_SYS_SetupThread(const char *name)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX)) && defined(HAVE_DLOPEN)
|
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID)) && defined(HAVE_DLOPEN)
|
||||||
SDL_assert(checked_setname);
|
SDL_assert(checked_setname);
|
||||||
if (ppthread_setname_np) {
|
if (ppthread_setname_np) {
|
||||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||||
ppthread_setname_np(name);
|
ppthread_setname_np(name);
|
||||||
#elif defined(SDL_PLATFORM_LINUX)
|
#elif defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID)
|
||||||
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
|
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||||
char namebuf[16]; // Limited to 16 char
|
char namebuf[16]; // Limited to 16 char
|
||||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||||
|
|||||||
Reference in New Issue
Block a user