Skip to content

Commit bd96918

Browse files
authored
[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.
1 parent 7a4b392 commit bd96918

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

llvm/lib/Support/Unix/Threading.inc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
#include <unistd.h> // For syscall()
6363
#endif
6464

65+
#if defined(__CYGWIN__)
66+
#include <sys/cpuset.h>
67+
#endif
68+
6569
#if defined(__HAIKU__)
6670
#include <OS.h> // For B_OS_NAME_LENGTH
6771
#endif
@@ -165,6 +169,8 @@ static constexpr uint32_t get_max_thread_name_length_impl() {
165169
return 16;
166170
#elif defined(__OpenBSD__)
167171
return 24;
172+
#elif defined(__CYGWIN__)
173+
return 16;
168174
#else
169175
return 0;
170176
#endif
@@ -241,7 +247,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
241247
}
242248
free(kp);
243249
return;
244-
#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
250+
#elif (defined(__linux__) || defined(__CYGWIN__)) && HAVE_PTHREAD_GETNAME_NP
245251
constexpr uint32_t len = get_max_thread_name_length_impl();
246252
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
247253
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
@@ -263,7 +269,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
263269
}
264270

265271
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
266-
#if defined(__linux__) && defined(SCHED_IDLE)
272+
#if (defined(__linux__) || defined(__CYGWIN__)) && defined(SCHED_IDLE)
267273
// Some *really* old glibcs are missing SCHED_IDLE.
268274
// http://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html
269275
// http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
@@ -316,7 +322,7 @@ static int computeHostNumHardwareThreads() {
316322
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
317323
&mask) == 0)
318324
return CPU_COUNT(&mask);
319-
#elif defined(__linux__)
325+
#elif (defined(__linux__) || defined(__CYGWIN__))
320326
cpu_set_t Set;
321327
CPU_ZERO(&Set);
322328
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
@@ -338,7 +344,8 @@ llvm::BitVector llvm::get_thread_affinity_mask() {
338344

339345
unsigned llvm::get_cpus() { return 1; }
340346

341-
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
347+
#if (defined(__linux__) || defined(__CYGWIN__)) && \
348+
(defined(__i386__) || defined(__x86_64__))
342349
// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
343350
// using the number of unique physical/core id pairs. The following
344351
// implementation reads the /proc/cpuinfo format on an x86_64 system.

0 commit comments

Comments
 (0)