Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use pthread_setname_np.
This makes SetCurrentThreadName actually work (name shows up in
debugger) on non-Windows.
  • Loading branch information
comex committed Aug 29, 2013
1 parent e685d19 commit 2de2e77
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions Source/Core/Common/Src/Thread.cpp
Expand Up @@ -46,7 +46,7 @@ void SleepCurrentThread(int ms)
{
Sleep(ms);
}

void SwitchCurrentThread()
{
SwitchToThread();
Expand Down Expand Up @@ -109,42 +109,25 @@ void SetCurrentThreadAffinity(u32 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)
{
usleep(1000 * ms);
}

void SwitchCurrentThread()
{
usleep(1000 * 1);
}

static void FreeThreadName(void* threadname)
{
free(threadname);
}

static void ThreadnameKeyAlloc()
{
pthread_key_create(&threadname_key, FreeThreadName);
}

void SetCurrentThreadName(const char* szThreadName)
{
pthread_once(&threadname_key_once, ThreadnameKeyAlloc);

void* threadname;
if ((threadname = pthread_getspecific(threadname_key)) != NULL)
free(threadname);

pthread_setspecific(threadname_key, strdup(szThreadName));

INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
#ifdef __APPLE__
pthread_setname_np(szThreadName);
#else
pthread_setname_np(pthread_self(), szThreadName);
#endif
}

#endif

} // namespace Common

0 comments on commit 2de2e77

Please sign in to comment.