[llvm] [llvm][Support] Add support for thread naming for Haiku (PR #107646)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 14:17:23 PDT 2024


https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/107646

>From 3f25d1a50699b2ffa71b54c18a560767bb6d7460 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 1/2] [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..ae9c3ac37c31df 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
 }
 

>From 17e103f8888c333bfb2beb1ef140cfdd4edc3e9c Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sun, 8 Sep 2024 22:17:09 +0100
Subject: [PATCH 2/2] fix build

---
 llvm/lib/Support/Unix/Threading.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index ae9c3ac37c31df..a5fe4fc46f14e1 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -185,11 +185,11 @@ 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
+#elif defined(__HAIKU__)
+  ::rename_thread(::find_thread(nullptr), NameStr.data());
 #endif
 }
 



More information about the llvm-commits mailing list