diff options
author | Benedikt Meurer <bmeurer@google.com> | 2013-09-01 09:12:23 (GMT) |
---|---|---|
committer | Benedikt Meurer <bmeurer@google.com> | 2013-09-01 09:12:23 (GMT) |
commit | 4a72182c6c65d44f894da68a72fb797b34c8d9ec (patch) | |
tree | bed5d08b90fb4d60624539c4898040be5d6e084d /src | |
parent | b6865ff7580c1afa93b787cbbce4453a30f4251a (diff) | |
download | Ninja-4a72182c6c65d44f894da68a72fb797b34c8d9ec.zip Ninja-4a72182c6c65d44f894da68a72fb797b34c8d9ec.tar.gz Ninja-4a72182c6c65d44f894da68a72fb797b34c8d9ec.tar.bz2 |
Simplify implementation of GetProcessorCount().
The current implementation is unnecessarily complex, because:
- The BSD derived systems implement sysconf(_SC_NPROCESSORS_ONLN)
in terms of sysctl({CTL_HW,HW_NCPU}).
- get_nprocs() is a GNU extension, and glibc implements
sysconf(_SC_NPROCESSORS_ONLN) in terms of get_nprocs().
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cc | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/src/util.cc b/src/util.cc index b9c2c0d..6ba3c6c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -300,35 +300,15 @@ string StripAnsiEscapeCodes(const string& in) { return stripped; } -#if defined(linux) || defined(__GLIBC__) -int GetProcessorCount() { - return get_nprocs(); -} -#elif defined(__APPLE__) || defined(__FreeBSD__) -int GetProcessorCount() { - int processors; - 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) { - return 0; - } - return processors; -} -#elif defined(_WIN32) int GetProcessorCount() { +#ifdef _WIN32 SYSTEM_INFO info; GetSystemInfo(&info); return info.dwNumberOfProcessors; -} #else -// This is what get_nprocs() should be doing in the Linux implementation -// above, but in a more standard way. -int GetProcessorCount() { return sysconf(_SC_NPROCESSORS_ONLN); -} #endif +} #if defined(_WIN32) || defined(__CYGWIN__) double GetLoadAverage() { |