mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 22:31:23 +01:00
setThreadName: abbreviate thread name if too long
This commit is contained in:
parent
eda81a5fe2
commit
06ab1e9820
@ -38,6 +38,8 @@
|
||||
#if POCO_OS == POCO_OS_LINUX
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
#include <cstring>
|
||||
|
||||
|
||||
//
|
||||
// Block SIGPIPE in main thread.
|
||||
@ -69,18 +71,26 @@ static SignalBlocker signalBlocker;
|
||||
|
||||
|
||||
namespace {
|
||||
void setThreadName(pthread_t thread, const char* threadName)
|
||||
void setThreadName(pthread_t thread, const std::string& threadName)
|
||||
{
|
||||
# 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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if (POCO_OS == POCO_OS_MAC_OS_X)
|
||||
pthread_setname_np(threadName.c_str()); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
|
||||
#else
|
||||
if (pthread_setname_np(thread, threadName.c_str()))
|
||||
{
|
||||
char truncName[16] = {0};
|
||||
std::size_t suffixIndex = threadName.length() - 7;
|
||||
std::memcpy(truncName, &threadName[0], 7);
|
||||
truncName[7] = '~';
|
||||
memcpy(&truncName[8], &threadName[suffixIndex], 7);
|
||||
pthread_setname_np(thread, truncName);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_POSIX_DEBUGGER_THREAD_NAMES
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -448,7 +458,7 @@ void* ThreadImpl::runnableEntry(void* pThread)
|
||||
|
||||
ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
|
||||
#if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
|
||||
setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
|
||||
setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName());
|
||||
#endif
|
||||
#if POCO_OS == POCO_OS_LINUX
|
||||
pThreadImpl->_pData->tid = static_cast<TIDImpl>( syscall (SYS_gettid) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user