[llvm] bd96918 - [LLVM][Support][Cygwin] Add threading support for Cygwin host (#145314)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 07:18:31 PDT 2025
Author: Tomohiro Kashiwada
Date: 2025-06-24T17:18:28+03:00
New Revision: bd96918f01cfd7642a20a4a5bb0e7d10ad7f2360
URL: https://github.com/llvm/llvm-project/commit/bd96918f01cfd7642a20a4a5bb0e7d10ad7f2360
DIFF: https://github.com/llvm/llvm-project/commit/bd96918f01cfd7642a20a4a5bb0e7d10ad7f2360.diff
LOG: [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.
Added:
Modified:
llvm/lib/Support/Unix/Threading.inc
Removed:
################################################################################
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 562971aae32fd..7854d6d229152 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
@@ -165,6 +169,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
@@ -241,7 +247,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))
@@ -263,7 +269,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
@@ -316,7 +322,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;
CPU_ZERO(&Set);
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
@@ -338,7 +344,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.
More information about the llvm-commits
mailing list