Use pthread_setname_np.
This makes SetCurrentThreadName actually work (name shows up in debugger) on non-Windows.
This commit is contained in:
parent
e685d198bd
commit
2de2e774fe
|
@ -46,7 +46,7 @@ void SleepCurrentThread(int ms)
|
||||||
{
|
{
|
||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchCurrentThread()
|
void SwitchCurrentThread()
|
||||||
{
|
{
|
||||||
SwitchToThread();
|
SwitchToThread();
|
||||||
|
@ -109,42 +109,25 @@ void SetCurrentThreadAffinity(u32 mask)
|
||||||
SetThreadAffinity(pthread_self(), mask);
|
SetThreadAffinity(pthread_self(), mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pthread_key_t threadname_key;
|
|
||||||
static pthread_once_t threadname_key_once = PTHREAD_ONCE_INIT;
|
|
||||||
|
|
||||||
void SleepCurrentThread(int ms)
|
void SleepCurrentThread(int ms)
|
||||||
{
|
{
|
||||||
usleep(1000 * ms);
|
usleep(1000 * ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchCurrentThread()
|
void SwitchCurrentThread()
|
||||||
{
|
{
|
||||||
usleep(1000 * 1);
|
usleep(1000 * 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FreeThreadName(void* threadname)
|
|
||||||
{
|
|
||||||
free(threadname);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ThreadnameKeyAlloc()
|
|
||||||
{
|
|
||||||
pthread_key_create(&threadname_key, FreeThreadName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetCurrentThreadName(const char* szThreadName)
|
void SetCurrentThreadName(const char* szThreadName)
|
||||||
{
|
{
|
||||||
pthread_once(&threadname_key_once, ThreadnameKeyAlloc);
|
#ifdef __APPLE__
|
||||||
|
pthread_setname_np(szThreadName);
|
||||||
void* threadname;
|
#else
|
||||||
if ((threadname = pthread_getspecific(threadname_key)) != NULL)
|
pthread_setname_np(pthread_self(), szThreadName);
|
||||||
free(threadname);
|
#endif
|
||||||
|
|
||||||
pthread_setspecific(threadname_key, strdup(szThreadName));
|
|
||||||
|
|
||||||
INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
Loading…
Reference in New Issue