utils: add set_thread_name

With HAVE_PTHREAD_SETNAME_NP
This commit is contained in:
Dirk-Jan C. Binnema
2025-08-24 22:29:59 +03:00
committed by Seth Ladygo
parent 4bda2718ac
commit 5378f321f4
2 changed files with 18 additions and 0 deletions

View File

@ -711,3 +711,11 @@ Mu::fputs_encoded (const std::string& str, FILE *stream)
return (rv == EOF) ? false: true;
}
void
Mu::set_thread_name(const std::string& name)
{
#ifdef HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), name.c_str());
#endif /*HAVE_PTHREAD_SETNAME_NP*/
}

View File

@ -427,6 +427,16 @@ std::string summarize(const std::string& str, size_t max_lines);
*/
std::string quote(const std::string& str);
/**
* Set the name of the current thread
*
* This depends on pthread_setname_np() being available;
* otherwise, does nothing.
*
* @param name thread name
*/
void set_thread_name(const std::string& name);
/**
* Convert any ostreamable<< value to a string