Add pthread_setname_np in Thread_POSIX. User can enable this with -DPOCO_POSIX_DEBUGGER_THREAD_NAMES.

This commit is contained in:
Mike Naquin 2012-11-15 10:25:14 -06:00
parent dbc847eb62
commit 5cd3d194ef

View File

@ -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
{