From 88e80c1542bf6a239e39552c122bad962efdd61c Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 21 Feb 2025 03:32:59 +1100 Subject: [PATCH] fix(utils): MCOL-5881 set/getThreadName use FreeBSD API (#3384) Taken from FreeBSD ports, this uses the FreeBSD APIs rather than the Linux specific prctl to change and retreive the thread names. Co-authored-by: Bernard Spil --- utils/common/threadnaming.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/common/threadnaming.cpp b/utils/common/threadnaming.cpp index 3183bc80f..722d17b36 100644 --- a/utils/common/threadnaming.cpp +++ b/utils/common/threadnaming.cpp @@ -22,13 +22,21 @@ namespace utils { void setThreadName(const char* threadName) { +#ifdef __FreeBSD__ + pthread_set_name_np(pthread_self(), threadName); +#else prctl(PR_SET_NAME, threadName, 0, 0, 0); +#endif } std::string getThreadName() { char buf[32]; +#ifdef __FreeBSD__ + pthread_get_name_np(pthread_self(), buf, sizeof(buf)); +#else prctl(PR_GET_NAME, buf, 0, 0, 0); +#endif return std::string(buf); } } // namespace utils