MSYS2-packages/llvm/0014-LLVM-Support-Cygwin-Add-threading-support-for-Cygwin.patch
2025-07-09 17:24:53 -07:00

78 lines
2.9 KiB
Diff

From 9a23be7809bed82dfd0c2142c4c127e641982957 Mon Sep 17 00:00:00 2001
From: Tomohiro Kashiwada <kikairoya@gmail.com>
Date: Tue, 24 Jun 2025 23:18:28 +0900
Subject: [PATCH] [LLVM][Support][Cygwin] Add threading support for Cygwin host
(#145314)
Cygwin environment has pthread functionality but LLVM integration
doesn't care it nor provide fallback.
Using Linux integration for Cygwin works fine.
---
llvm/lib/Support/Unix/Threading.inc | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 15a5b00860..05a6869669 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -62,6 +62,10 @@
#include <unistd.h> // For syscall()
#endif
+#if defined(__CYGWIN__)
+#include <sys/cpuset.h>
+#endif
+
#if defined(__HAIKU__)
#include <OS.h> // For B_OS_NAME_LENGTH
#endif
@@ -163,6 +167,8 @@ static constexpr uint32_t get_max_thread_name_length_impl() {
return 16;
#elif defined(__OpenBSD__)
return 24;
+#elif defined(__CYGWIN__)
+ return 16;
#else
return 0;
#endif
@@ -239,7 +245,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
}
free(kp);
return;
-#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
+#elif (defined(__linux__) || defined(__CYGWIN__)) && HAVE_PTHREAD_GETNAME_NP
constexpr uint32_t len = get_max_thread_name_length_impl();
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
@@ -261,7 +267,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
}
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
-#if defined(__linux__) && defined(SCHED_IDLE)
+#if (defined(__linux__) || defined(__CYGWIN__)) && defined(SCHED_IDLE)
// Some *really* old glibcs are missing SCHED_IDLE.
// http://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html
// http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
@@ -314,7 +320,7 @@ static int computeHostNumHardwareThreads() {
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
&mask) == 0)
return CPU_COUNT(&mask);
-#elif defined(__linux__)
+#elif (defined(__linux__) || defined(__CYGWIN__))
cpu_set_t Set;
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
return CPU_COUNT(&Set);
@@ -335,7 +341,8 @@ llvm::BitVector llvm::get_thread_affinity_mask() {
unsigned llvm::get_cpus() { return 1; }
-#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
+#if (defined(__linux__) || defined(__CYGWIN__)) && \
+ (defined(__i386__) || defined(__x86_64__))
// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
// using the number of unique physical/core id pairs. The following
// implementation reads the /proc/cpuinfo format on an x86_64 system.
--
2.50.1.windows.1