mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-18 20:24:04 +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)
|
||||
pthread_setname_np(threadName.c_str()); // __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
|
||||
#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::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);
|
||||
std::string truncName(threadName, 0, 7);
|
||||
truncName.append("~");
|
||||
truncName.append(threadName, threadName.size() - 7, 7);
|
||||
pthread_setname_np(thread, truncName.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user