diff --git a/os-posix.c b/os-posix.c index 4c2a7f0..35486b8 100644 --- a/os-posix.c +++ b/os-posix.c @@ -83,3 +83,13 @@ since it has not been updated to support POSIX.1-2008: #endif } } + +long +osnproc(void) +{ +#ifdef _SC_NPROCESSORS_ONLN + return sysconf(_SC_NPROCESSORS_ONLN); +#else + return 1; +#endif +} diff --git a/os.h b/os.h index 91cae05..3715987 100644 --- a/os.h +++ b/os.h @@ -7,3 +7,5 @@ void oschdir(const char *); int osmkdirs(struct string *, _Bool); /* queries the mtime of a file in nanoseconds since the UNIX epoch */ int64_t osmtime(const char *); +/* queries the number of online processors */ +long osnproc(void); diff --git a/samu.c b/samu.c index 05f5597..0c389bc 100644 --- a/samu.c +++ b/samu.c @@ -200,8 +200,7 @@ main(int argc, char *argv[]) } ARGEND argdone: if (!buildopts.maxjobs) { -#ifdef _SC_NPROCESSORS_ONLN - long nproc = sysconf(_SC_NPROCESSORS_ONLN); + long nproc = osnproc(); switch (nproc) { case -1: case 0: case 1: buildopts.maxjobs = 2; @@ -213,9 +212,6 @@ main(int argc, char *argv[]) buildopts.maxjobs = nproc + 2; break; } -#else - buildopts.maxjobs = 2; -#endif } buildopts.statusfmt = getenv("NINJA_STATUS");