summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-02-28 19:47:46 (GMT)
committerEvan Martin <martine@danga.com>2011-02-28 19:47:46 (GMT)
commit590df5d245e8da3ea433fc32f48f069729100851 (patch)
treeb8971e0354a028970b8f2f2a3a95108911e1f820 /src
parenta5a707d19e8f6c97724eaa0b8f755cca3b25d6fa (diff)
downloadNinja-590df5d245e8da3ea433fc32f48f069729100851.zip
Ninja-590df5d245e8da3ea433fc32f48f069729100851.tar.gz
Ninja-590df5d245e8da3ea433fc32f48f069729100851.tar.bz2
get the number of CPUs on FreeBSD and OS X via sysctl()
From a patch from asmodai@in-nomine.org and dmitry@codingrobots.com.
Diffstat (limited to 'src')
-rw-r--r--src/ninja.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index eb7e41c..122d4fd 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -22,6 +22,10 @@
#include <sys/stat.h>
#include <sys/types.h>
+#if defined(__APPLE__) || defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
+
#include "build.h"
#include "build_log.h"
#include "parsers.h"
@@ -64,6 +68,7 @@ void usage(const BuildConfig& config) {
int GuessParallelism() {
int processors = 0;
+#if defined(linux)
const char kProcessorPrefix[] = "processor\t";
char buf[16 << 10];
FILE* f = fopen("/proc/cpuinfo", "r");
@@ -74,6 +79,15 @@ int GuessParallelism() {
++processors;
}
fclose(f);
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+ size_t processors_size = sizeof(processors);
+ int name[] = {CTL_HW, HW_NCPU};
+ if (sysctl(name, sizeof(name) / sizeof(int),
+ &processors, &processors_size,
+ NULL, 0) < 0) {
+ processors = 1;
+ }
+#endif
switch (processors) {
case 0: