diff options
author | Makoto Kato <m_kato@ga2.so-net.ne.jp> | 2017-12-18 10:56:50 +0100 |
---|---|---|
committer | Makoto Kato <m_kato@ga2.so-net.ne.jp> | 2017-12-18 10:56:50 +0100 |
commit | 1b095ad076a53f8078fbfa14ce9a11583699631d (patch) | |
tree | 959db896d2b795f0693eab3fa806d98c26945bec | |
parent | 351a2a25af2977770100954a99308d513380a983 (diff) | |
download | nspr-hg-1b095ad076a53f8078fbfa14ce9a11583699631d.tar.gz |
Bug 1362976 - Use SetThreadDescription in _PR_MD_SET_CURRENT_THREAD_NAME. portions by David Major, r=mayhemerNSPR_4_18_BETA4
-rw-r--r-- | pr/src/md/windows/ntthread.c | 23 | ||||
-rw-r--r-- | pr/src/md/windows/w95thred.c | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/pr/src/md/windows/ntthread.c b/pr/src/md/windows/ntthread.c index fead1236..1fdf0e93 100644 --- a/pr/src/md/windows/ntthread.c +++ b/pr/src/md/windows/ntthread.c @@ -27,6 +27,9 @@ PRUint32 _nt_idleCount; extern __declspec(thread) PRThread *_pr_io_restarted_io; extern DWORD _pr_io_restartedIOIndex; +typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR); +static SETTHREADDESCRIPTION sSetThreadDescription = NULL; + /* Must check the restarted_io *before* decrementing no_sched to 0 */ #define POST_SWITCH_WORK() \ PR_BEGIN_MACRO \ @@ -79,6 +82,8 @@ _nt_handle_restarted_io(PRThread *restarted_io) void _PR_MD_EARLY_INIT() { + HMODULE hModule; + _MD_NEW_LOCK( &_nt_idleLock ); _nt_idleCount = 0; PR_INIT_CLIST(&_nt_idleList); @@ -98,6 +103,15 @@ _PR_MD_EARLY_INIT() _pr_intsOffIndex = TlsAlloc(); _pr_io_restartedIOIndex = TlsAlloc(); } + + // SetThreadDescription is Windows 10 build 1607+ + hModule = GetModuleHandleW(L"kernel32.dll"); + if (hModule) { + sSetThreadDescription = + (SETTHREADDESCRIPTION) GetProcAddress( + hModule, + "SetThreadDescription"); + } } void _PR_MD_CLEANUP_BEFORE_EXIT(void) @@ -293,7 +307,16 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { #ifdef _MSC_VER THREADNAME_INFO info; +#endif + + if (sSetThreadDescription) { + WCHAR wideName[MAX_PATH]; + if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) { + sSetThreadDescription(GetCurrentThread(), wideName); + } + } +#ifdef _MSC_VER if (!IsDebuggerPresent()) return; diff --git a/pr/src/md/windows/w95thred.c b/pr/src/md/windows/w95thred.c index 06d01512..a365411f 100644 --- a/pr/src/md/windows/w95thred.c +++ b/pr/src/md/windows/w95thred.c @@ -1,3 +1,4 @@ + /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -27,9 +28,14 @@ DWORD _pr_currentCPUIndex; int _pr_intsOff = 0; _PRInterruptTable _pr_interruptTable[] = { { 0 } }; +typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR); +static SETTHREADDESCRIPTION sSetThreadDescription = NULL; + void _PR_MD_EARLY_INIT() { + HMODULE hModule; + #ifndef _PR_USE_STATIC_TLS _pr_currentThreadIndex = TlsAlloc(); _pr_lastThreadIndex = TlsAlloc(); @@ -39,6 +45,15 @@ _PR_MD_EARLY_INIT() #if defined(_WIN64) && defined(WIN95) _fd_waiting_for_overlapped_done_lock = PR_NewLock(); #endif + + // SetThreadDescription is Windows 10 build 1607+ + hModule = GetModuleHandleW(L"kernel32.dll"); + if (hModule) { + sSetThreadDescription = + (SETTHREADDESCRIPTION) GetProcAddress( + hModule, + "SetThreadDescription"); + } } void _PR_MD_CLEANUP_BEFORE_EXIT(void) @@ -217,7 +232,16 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { #ifdef _MSC_VER THREADNAME_INFO info; +#endif + + if (sSetThreadDescription) { + WCHAR wideName[MAX_PATH]; + if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) { + sSetThreadDescription(GetCurrentThread(), wideName); + } + } +#ifdef _MSC_VER if (!IsDebuggerPresent()) return; |