diff options
Diffstat (limited to 'osdep/win32')
-rw-r--r-- | osdep/win32/include/pthread.h | 3 | ||||
-rw-r--r-- | osdep/win32/pthread.c | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/osdep/win32/include/pthread.h b/osdep/win32/include/pthread.h index 870e9d7d5c..271cae0f0a 100644 --- a/osdep/win32/include/pthread.h +++ b/osdep/win32/include/pthread.h @@ -33,6 +33,7 @@ #define pthread_join m_pthread_join #define pthread_detach m_pthread_detach #define pthread_create m_pthread_create +#define pthread_set_name_np m_pthread_set_name_np #define pthread_once_t INIT_ONCE #define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT @@ -97,4 +98,6 @@ int pthread_detach(pthread_t thread); int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); +void pthread_set_name_np(pthread_t thread, const char *name); + #endif diff --git a/osdep/win32/pthread.c b/osdep/win32/pthread.c index 4f42cc3cd4..57a9d85810 100644 --- a/osdep/win32/pthread.c +++ b/osdep/win32/pthread.c @@ -196,6 +196,29 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, return 0; } +void pthread_set_name_np(pthread_t thread, const char *name) +{ + HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); + if (!kernel32) + return; + HRESULT (WINAPI *pSetThreadDescription)(HANDLE, PCWSTR) = + (void*)GetProcAddress(kernel32, "SetThreadDescription"); + if (!pSetThreadDescription) + return; + + HANDLE th = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, thread.id); + if (!th) + return; + wchar_t wname[80]; + int wc = MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, + sizeof(wname) / sizeof(wchar_t) - 1); + if (wc > 0) { + wname[wc] = L'\0'; + pSetThreadDescription(th, wname); + } + CloseHandle(th); +} + int sem_init(sem_t *sem, int pshared, unsigned int value) { if (pshared) |