Changeset View
Changeset View
Standalone View
Standalone View
src/util/threadnames.cpp
Show All 29 Lines | |||||
#elif defined(MAC_OSX) | #elif defined(MAC_OSX) | ||||
pthread_setname_np(name); | pthread_setname_np(name); | ||||
#else | #else | ||||
// Prevent warnings for unused parameters... | // Prevent warnings for unused parameters... | ||||
(void)name; | (void)name; | ||||
#endif | #endif | ||||
} | } | ||||
// If we have thread_local, just keep thread ID and name in a thread_local | |||||
// global. | |||||
#if defined(HAVE_THREAD_LOCAL) | |||||
static thread_local std::string g_thread_name; | static thread_local std::string g_thread_name; | ||||
const std::string &util::ThreadGetInternalName() { | const std::string &util::ThreadGetInternalName() { | ||||
return g_thread_name; | return g_thread_name; | ||||
} | } | ||||
//! Set the in-memory internal name for this thread. Does not affect the process | //! Set the in-memory internal name for this thread. Does not affect the process | ||||
//! name. | //! name. | ||||
static void SetInternalName(std::string name) { | static void SetInternalName(std::string name) { | ||||
g_thread_name = std::move(name); | g_thread_name = std::move(name); | ||||
} | } | ||||
// Without thread_local available, don't handle internal name at all. | |||||
#else | |||||
static const std::string empty_string; | |||||
const std::string &util::ThreadGetInternalName() { | |||||
return empty_string; | |||||
} | |||||
static void SetInternalName(std::string name) {} | |||||
#endif // defined(HAVE_THREAD_LOCAL) | |||||
void util::ThreadRename(std::string &&name) { | void util::ThreadRename(std::string &&name) { | ||||
SetThreadName(("b-" + name).c_str()); | SetThreadName(("b-" + name).c_str()); | ||||
SetInternalName(std::move(name)); | SetInternalName(std::move(name)); | ||||
} | } | ||||
void util::ThreadSetInternalName(std::string &&name) { | void util::ThreadSetInternalName(std::string &&name) { | ||||
SetInternalName(std::move(name)); | SetInternalName(std::move(name)); | ||||
} | } |