Permalink
Browse files

Add pthread_setname_np in Thread_POSIX. User can enable this with -DP…

…OCO_POSIX_DEBUGGER_THREAD_NAMES.
  • Loading branch information...
1 parent dbc847e commit 5cd3d194ef999f3c37c747a93519ac3765465d77 @syvex committed Nov 15, 2012
Showing with 31 additions and 1 deletion.
  1. +31 −1 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<ThreadImpl*>(pThread);
+#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
+ setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
+#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;
try
{
@@ -410,6 +437,9 @@ void* ThreadImpl::callableEntry(void* pThread)
#endif
ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
+#if defined(_DEBUG) && defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
+ setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
+#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;
try
{

0 comments on commit 5cd3d19

Please sign in to comment.