Merge pull request #199 from syvex/ThreadNames

Debug build and debugger shouldn't be required for OS thread names
This commit is contained in:
Aleksandar Fabijanic 2013-06-04 19:00:12 -07:00
commit ca16b76f9f
2 changed files with 21 additions and 28 deletions

View File

@ -36,7 +36,6 @@
#include "Poco/Thread_POSIX.h"
#include "Poco/Thread.h"
#include "Poco/Debugger.h"
#include "Poco/Exception.h"
#include "Poco/ErrorHandler.h"
#include "Poco/Timespan.h"
@ -77,21 +76,18 @@ namespace
#endif
#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
#if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
namespace
{
void setThreadName(pthread_t thread, const char* threadName)
{
if (Poco::Debugger::isAvailable())
{
# if (POCO_OS == POCO_OS_MAC_OS_X)
pthread_setname_np(threadName); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
pthread_setname_np(threadName); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
# else
pthread_setname_np(thread, threadName);
pthread_setname_np(thread, threadName);
# endif
}
}
}
@ -405,7 +401,7 @@ void* ThreadImpl::runnableEntry(void* pThread)
#endif
ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
#if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;
@ -446,7 +442,7 @@ void* ThreadImpl::callableEntry(void* pThread)
#endif
ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
#if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;

View File

@ -40,7 +40,7 @@
#include <process.h>
#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<ThreadImpl*>(pThread));
#if defined(_DEBUG) && defined(POCO_WIN32_DEBUGGER_THREAD_NAMES)
#if defined(POCO_WIN32_DEBUGGER_THREAD_NAMES)
setThreadName(-1, reinterpret_cast<Thread*>(pThread)->getName().c_str());
#endif
try
@ -267,7 +264,7 @@ unsigned __stdcall ThreadImpl::callableEntry(void* pThread)
#endif
{
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
#if defined(_DEBUG) && defined(POCO_WIN32_DEBUGGER_THREAD_NAMES)
#if defined(POCO_WIN32_DEBUGGER_THREAD_NAMES)
setThreadName(-1, reinterpret_cast<Thread*>(pThread)->getName().c_str());
#endif
try