MCPcopy Create free account
hub / github.com/Icinga/icinga2 / SetThreadName

Method SetThreadName

lib/base/utility.cpp:1311–1350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1309#endif /* _WIN32 */
1310
1311void Utility::SetThreadName(const String& name, bool os)
1312{
1313 m_ThreadName.reset(new String(name));
1314
1315#if defined(HAVE_PTHREAD_SET_NAME_NP) || defined(HAVE_PTHREAD_SETNAME_NP)
1316 unsigned int len;
1317
1318 /* https://github.com/llvm/llvm-project/blob/6412184891526690cff804f87f986b1fa039f011/llvm/lib/Support/Unix/Threading.inc#L157 */
1319# ifdef PTHREAD_MAX_NAMELEN_NP
1320 len = PTHREAD_MAX_NAMELEN_NP;
1321# elif defined(__APPLE__) /* PTHREAD_MAX_NAMELEN_NP */
1322 len = 64;
1323# elif defined(__OpenBSD__) /* __APPLE__ */
1324 len = 24;
1325# else /* __OpenBSD__ */
1326 len = 16;
1327# endif /* PTHREAD_MAX_NAMELEN_NP */
1328
1329 String tname = name.SubStr(0, len - 1);
1330#endif
1331
1332 if (!os)
1333 return;
1334
1335#ifdef _WIN32
1336 WindowsSetThreadName(name.CStr());
1337#endif /* _WIN32 */
1338
1339#ifdef HAVE_PTHREAD_SET_NAME_NP
1340 pthread_set_name_np(pthread_self(), tname.CStr());
1341#elif defined(HAVE_PTHREAD_SETNAME_NP) /* HAVE_PTHREAD_SET_NAME_NP */
1342# ifdef __APPLE__
1343 pthread_setname_np(tname.CStr());
1344# elif defined(__NetBSD__) /* __APPLE__ */
1345 pthread_setname_np(pthread_self(), "%s", const_cast<char *>(tname.CStr()));
1346# else /* __NetBSD__ */
1347 pthread_setname_np(pthread_self(), tname.CStr());
1348# endif /* __APPLE__ */
1349#endif /* HAVE_PTHREAD_SETNAME_NP */
1350}
1351
1352String Utility::GetThreadName()
1353{

Callers

nothing calls this directly

Calls 3

WindowsSetThreadNameFunction · 0.85
SubStrMethod · 0.80
CStrMethod · 0.80

Tested by

no test coverage detected