mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-11 04:33:47 +01:00
GH #1022: clean-up setThreadName
This commit is contained in:
parent
ba946fc592
commit
825e99578a
@ -76,14 +76,12 @@ void setThreadName(pthread_t thread, const std::string& threadName)
|
|||||||
#if (POCO_OS == POCO_OS_MAC_OS_X)
|
#if (POCO_OS == POCO_OS_MAC_OS_X)
|
||||||
pthread_setname_np(threadName.c_str()); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
|
pthread_setname_np(threadName.c_str()); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
|
||||||
#else
|
#else
|
||||||
if (pthread_setname_np(thread, threadName.c_str()))
|
if (pthread_setname_np(thread, threadName.c_str()) != 0 && errno == ERANGE && threadName.size() > 15)
|
||||||
{
|
{
|
||||||
char truncName[16] = {0};
|
std::string truncName(threadName, 0, 7);
|
||||||
std::size_t suffixIndex = threadName.length() - 7;
|
truncName.append("~");
|
||||||
std::memcpy(truncName, &threadName[0], 7);
|
truncName.append(threadName, threadName.size() - 7, 7);
|
||||||
truncName[7] = '~';
|
pthread_setname_np(thread, truncName.c_str());
|
||||||
memcpy(&truncName[8], &threadName[suffixIndex], 7);
|
|
||||||
pthread_setname_np(thread, truncName);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user