mirror of
https://github.com/Relintai/osxcross.git
synced 2025-02-03 22:45:56 +01:00
50 lines
1.2 KiB
Diff
50 lines
1.2 KiB
Diff
|
diff --git cctools/ld64/src/ld/InputFiles.cpp cctools/ld64/src/ld/InputFiles.cpp
|
||
|
index 13207e5..2b6f7bd 100644
|
||
|
--- cctools/ld64/src/ld/InputFiles.cpp
|
||
|
+++ cctools/ld64/src/ld/InputFiles.cpp
|
||
|
@@ -43,6 +43,15 @@
|
||
|
#include <sys/sysctl.h>
|
||
|
#include <libkern/OSAtomic.h>
|
||
|
|
||
|
+// ld64-port
|
||
|
+#ifdef __linux__
|
||
|
+#ifndef __USE_GNU
|
||
|
+#define __USE_GNU
|
||
|
+#endif
|
||
|
+#include <sched.h>
|
||
|
+#endif
|
||
|
+// ld64-port end
|
||
|
+
|
||
|
#include <string>
|
||
|
#include <map>
|
||
|
#include <set>
|
||
|
@@ -913,6 +922,20 @@ InputFiles::InputFiles(Options& opts, const char** archName)
|
||
|
|
||
|
// initialize info for parsing input files on worker threads
|
||
|
unsigned int ncpus;
|
||
|
+#ifdef __linux__ // ld64-port
|
||
|
+ cpu_set_t cs;
|
||
|
+ CPU_ZERO(&cs);
|
||
|
+
|
||
|
+ if (!sched_getaffinity(0, sizeof(cs), &cs)) {
|
||
|
+ ncpus = 0;
|
||
|
+
|
||
|
+ for (int i = 0; i < CPU_SETSIZE; i++)
|
||
|
+ if (CPU_ISSET(i, &cs))
|
||
|
+ ncpus++;
|
||
|
+ } else {
|
||
|
+ ncpus = 1;
|
||
|
+ }
|
||
|
+#else
|
||
|
int mib[2];
|
||
|
size_t len = sizeof(ncpus);
|
||
|
mib[0] = CTL_HW;
|
||
|
@@ -920,6 +943,7 @@ InputFiles::InputFiles(Options& opts, const char** archName)
|
||
|
if (sysctl(mib, 2, &ncpus, &len, NULL, 0) != 0) {
|
||
|
ncpus = 1;
|
||
|
}
|
||
|
+#endif
|
||
|
_availableWorkers = MIN(ncpus, files.size()); // max # workers we permit
|
||
|
_idleWorkers = 0;
|
||
|
|