GH #1022: clean-up setThreadName

This commit is contained in:
Guenter Obiltschnig 2015-11-10 09:27:15 +01:00
parent ba946fc592
commit 825e99578a

View File

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