Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1508)

Unified Diff: Source/wtf/NumberOfCores.cpp

Issue 23609031: Make getting the getting number of CPU cores more portable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove OS(ANDROID) branch Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/NumberOfCores.cpp
diff --git a/Source/wtf/NumberOfCores.cpp b/Source/wtf/NumberOfCores.cpp
index cafd9bee0787cf3e6bc875231f9e4ea7d195ff59..ce8a5bca718f396fcf16de2ac0dae03713d0371c 100644
--- a/Source/wtf/NumberOfCores.cpp
+++ b/Source/wtf/NumberOfCores.cpp
@@ -26,51 +26,31 @@
#include "config.h"
#include "NumberOfCores.h"
-#if OS(MACOSX) || OS(OPENBSD) || OS(FREEBSD)
-#include <sys/param.h>
-// sys/types.h must come before sys/sysctl.h because the latter uses
-// data types defined in the former. See sysctl(3) and style(9).
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#elif OS(LINUX)
-#include <unistd.h>
-#elif OS(WIN)
-#include "wtf/UnusedParam.h"
+#if OS(WIN)
#include <windows.h>
+#else
+#include <unistd.h>
#endif
namespace WTF {
int numberOfProcessorCores()
{
- const int defaultIfUnavailable = 1;
static int s_numberOfCores = -1;
if (s_numberOfCores > 0)
return s_numberOfCores;
-#if OS(MACOSX) || OS(OPENBSD) || OS(NETBSD) || OS(FREEBSD)
- unsigned result;
- size_t length = sizeof(result);
- int name[] = {
- CTL_HW,
- HW_NCPU
- };
- int sysctlResult = sysctl(name, sizeof(name) / sizeof(int), &result, &length, 0, 0);
-
- s_numberOfCores = sysctlResult < 0 ? defaultIfUnavailable : result;
-#elif OS(LINUX)
- long sysconfResult = sysconf(_SC_NPROCESSORS_ONLN);
-
- s_numberOfCores = sysconfResult < 0 ? defaultIfUnavailable : static_cast<int>(sysconfResult);
-#elif OS(WIN)
- UNUSED_PARAM(defaultIfUnavailable);
+#if OS(WIN)
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
s_numberOfCores = sysInfo.dwNumberOfProcessors;
#else
- s_numberOfCores = defaultIfUnavailable;
+ const int defaultIfUnavailable = 1;
+ long sysconfResult = sysconf(_SC_NPROCESSORS_ONLN);
+
+ s_numberOfCores = sysconfResult < 0 ? defaultIfUnavailable : static_cast<int>(sysconfResult);
#endif
return s_numberOfCores;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698