diff options
| author | comex <comexk@gmail.com> | 2013-08-29 16:14:08 -0400 |
|---|---|---|
| committer | comex <comexk@gmail.com> | 2013-08-29 16:30:32 -0400 |
| commit | 2de2e774fedff1b757ff3f0c457a0d0d8b862922 (patch) | |
| tree | 5dd5c9903ea2df98c3e5ba03167520e2c660cfba /Source/Core/Common/Src/Thread.cpp | |
| parent | e685d198bd4cc726275079579dadf1d7aa20e987 (diff) | |
Use pthread_setname_np.
This makes SetCurrentThreadName actually work (name shows up in
debugger) on non-Windows.
Diffstat (limited to 'Source/Core/Common/Src/Thread.cpp')
| -rw-r--r-- | Source/Core/Common/Src/Thread.cpp | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index 14eb832240..4040d04e42 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -46,7 +46,7 @@ void SleepCurrentThread(int ms) { Sleep(ms); } - + void SwitchCurrentThread() { SwitchToThread(); @@ -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 |
