[llvm] [llvm][Support] Add support for thread naming for Haiku (PR #107646)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 14:59:29 PDT 2024
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/107646
None
>From f9c111863ad58479c97ab5ea4373f08315d7a56f Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Fri, 6 Sep 2024 22:58:51 +0100
Subject: [PATCH] [llvm][Support] Add support for thread naming for Haiku
---
llvm/lib/Support/Unix/Threading.inc | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 43e18c3a963abf..79947ad1a1c449 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -49,6 +49,10 @@
#include <unistd.h> // For getthrid()
#endif
+#if defined(__HAIKU__)
+#include <OS.h> // For team/thread api
+#endif
+
#if defined(__linux__)
#include <sched.h> // For sched_getaffinity
#include <sys/syscall.h> // For syscall codes
@@ -181,6 +185,8 @@ void llvm::set_thread_name(const Twine &Name) {
const_cast<char *>(NameStr.data()));
#elif defined(__APPLE__)
::pthread_setname_np(NameStr.data());
+#elif defined(__HAIKU__)
+ ::rename_thread(::find_thread(nullptr), NameStr.data());
#else
::pthread_setname_np(::pthread_self(), NameStr.data());
#endif
@@ -244,6 +250,11 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
::pthread_getname_np(::pthread_self(), buf, len);
Name.append(buf, buf + strlen(buf));
+#elif defined(__HAIKU__)
+ thread_info i;
+
+ if (get_thread_info(::find_thread(nullptr), &i) == B_OK)
+ Name.append(i.name, i.name + strlen(i.name));
#endif
}
More information about the llvm-commits
mailing list