From 5cd3d194ef999f3c37c747a93519ac3765465d77 Mon Sep 17 00:00:00 2001 From: Mike Naquin Date: Thu, 15 Nov 2012 10:25:14 -0600 Subject: [PATCH] Add pthread_setname_np in Thread_POSIX. User can enable this with -DPOCO_POSIX_DEBUGGER_THREAD_NAMES. --- Foundation/src/Thread_POSIX.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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 {