From 590df5d245e8da3ea433fc32f48f069729100851 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Mon, 28 Feb 2011 11:47:46 -0800 Subject: get the number of CPUs on FreeBSD and OS X via sysctl() From a patch from asmodai@in-nomine.org and dmitry@codingrobots.com. --- src/ninja.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 #include +#if defined(__APPLE__) || defined(__FreeBSD__) +#include +#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: -- cgit v0.12