Skip to content

Commit 9a23be7

Browse files
kikairoyajeremyd2019
authored andcommitted
[LLVM][Support][Cygwin] Add threading support for Cygwin host (llvm#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 21ea984 commit 9a23be7

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
@@ -163,6 +167,8 @@ static constexpr uint32_t get_max_thread_name_length_impl() {
163167
return 16;
164168
#elif defined(__OpenBSD__)
165169
return 24;
170+
#elif defined(__CYGWIN__)
171+
return 16;
166172
#else
167173
return 0;
168174
#endif
@@ -239,7 +245,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
239245
}
240246
free(kp);
241247
return;
242-
#elif defined(__linux__) && HAVE_PTHREAD_GETNAME_NP
248+
#elif (defined(__linux__) || defined(__CYGWIN__)) && HAVE_PTHREAD_GETNAME_NP
243249
constexpr uint32_t len = get_max_thread_name_length_impl();
244250
char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive.
245251
if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len))
@@ -261,7 +267,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
261267
}
262268

263269
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
264-
#if defined(__linux__) && defined(SCHED_IDLE)
270+
#if (defined(__linux__) || defined(__CYGWIN__)) && defined(SCHED_IDLE)
265271
// Some *really* old glibcs are missing SCHED_IDLE.
266272
// http://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html
267273
// http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
@@ -314,7 +320,7 @@ static int computeHostNumHardwareThreads() {
314320
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
315321
&mask) == 0)
316322
return CPU_COUNT(&mask);
317-
#elif defined(__linux__)
323+
#elif (defined(__linux__) || defined(__CYGWIN__))
318324
cpu_set_t Set;
319325
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
320326
return CPU_COUNT(&Set);
@@ -335,7 +341,8 @@ llvm::BitVector llvm::get_thread_affinity_mask() {
335341

336342
unsigned llvm::get_cpus() { return 1; }
337343

338-
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
344+
#if (defined(__linux__) || defined(__CYGWIN__)) && \
345+
(defined(__i386__) || defined(__x86_64__))
339346
// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
340347
// using the number of unique physical/core id pairs. The following
341348
// implementation reads the /proc/cpuinfo format on an x86_64 system.

0 commit comments

Comments
 (0)