diff --git a/Foundation/src/Thread_POSIX.cpp b/Foundation/src/Thread_POSIX.cpp index 907d7f4a6..e39b7a7d0 100644 --- a/Foundation/src/Thread_POSIX.cpp +++ b/Foundation/src/Thread_POSIX.cpp @@ -35,6 +35,8 @@ #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" @@ -70,12 +72,34 @@ namespace { } }; - + static SignalBlocker signalBlocker; } #endif +#if defined(_DEBUG) && 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) +# else + pthread_setname_np(thread, threadName); +# endif + } + } +} + + +#endif + + namespace Poco { @@ -372,6 +396,9 @@ void* ThreadImpl::runnableEntry(void* pThread) #endif ThreadImpl* pThreadImpl = reinterpret_cast(pThread); +#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES) + setThreadName(pThreadImpl->_pData->thread, reinterpret_cast(pThread)->getName().c_str()); +#endif AutoPtr pData = pThreadImpl->_pData; try { @@ -410,6 +437,9 @@ void* ThreadImpl::callableEntry(void* pThread) #endif ThreadImpl* pThreadImpl = reinterpret_cast(pThread); +#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES) + setThreadName(pThreadImpl->_pData->thread, reinterpret_cast(pThread)->getName().c_str()); +#endif AutoPtr pData = pThreadImpl->_pData; try {