From d7ca828693f45d2d84257abf9d8ef0b4a92f8507 Mon Sep 17 00:00:00 2001 From: Bernard Spil Date: Tue, 14 Jan 2025 15:45:02 +1100 Subject: [PATCH] MCOL-5881 set/getThreadName use FreeBSD API Taken from FreeBSD ports, this uses the FreeBSD APIs rather than the Linux specific prctl to change and retreive the thread names. --- utils/common/threadnaming.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/common/threadnaming.cpp b/utils/common/threadnaming.cpp index 3183bc80fd..722d17b368 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