From ee77d05ab55ee7b95b0de33ad84d0b824db82af4 Mon Sep 17 00:00:00 2001 From: Mike Naquin Date: Mon, 20 May 2013 12:38:51 -0500 Subject: [PATCH] Remove the need for a debug build or debugger when setting Win32 thread names. --- Foundation/src/Thread_WIN32.cpp | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Foundation/src/Thread_WIN32.cpp b/Foundation/src/Thread_WIN32.cpp index fb227610f..7bcb907a5 100644 --- a/Foundation/src/Thread_WIN32.cpp +++ b/Foundation/src/Thread_WIN32.cpp @@ -40,7 +40,7 @@ #include -#if defined(_DEBUG) && defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) +#if defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) namespace @@ -63,22 +63,19 @@ namespace void setThreadName(DWORD dwThreadID, const char* threadName) { - if (IsDebuggerPresent()) - { - THREADNAME_INFO info; - info.dwType = 0x1000; - info.szName = threadName; - info.dwThreadID = dwThreadID; - info.dwFlags = 0; - - __try - { - RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); - } - __except (EXCEPTION_CONTINUE_EXECUTION) - { - } - } + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = threadName; + info.dwThreadID = dwThreadID; + info.dwFlags = 0; + + __try + { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); + } + __except (EXCEPTION_CONTINUE_EXECUTION) + { + } } } @@ -237,7 +234,7 @@ unsigned __stdcall ThreadImpl::runnableEntry(void* pThread) #endif { _currentThreadHolder.set(reinterpret_cast(pThread)); -#if defined(_DEBUG) && defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) +#if defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) setThreadName(-1, reinterpret_cast(pThread)->getName().c_str()); #endif try @@ -267,7 +264,7 @@ unsigned __stdcall ThreadImpl::callableEntry(void* pThread) #endif { _currentThreadHolder.set(reinterpret_cast(pThread)); -#if defined(_DEBUG) && defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) +#if defined(POCO_WIN32_DEBUGGER_THREAD_NAMES) setThreadName(-1, reinterpret_cast(pThread)->getName().c_str()); #endif try