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

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: Fix build 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..a98ee211b6d89fcabff630fee01129658d2533d2 100644
--- a/Source/wtf/NumberOfCores.cpp
+++ b/Source/wtf/NumberOfCores.cpp
@@ -26,17 +26,11 @@
#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)
+#if OS(WIN)
#include "wtf/UnusedParam.h"
#include <windows.h>
+#else
+#include <unistd.h>
#endif
namespace WTF {
@@ -49,20 +43,9 @@ int numberOfProcessorCores()
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);
+#if OS(ANDROID)
+ // FIXME: Can we do better on Android - perhaps calling sysconf() ?
Nico 2013/09/12 19:34:55 luckily we have 20 different implementations of ev
+ s_numberOfCores = defaultIfUnavailable;
#elif OS(WIN)
UNUSED_PARAM(defaultIfUnavailable);
SYSTEM_INFO sysInfo;
@@ -70,7 +53,9 @@ int numberOfProcessorCores()
s_numberOfCores = sysInfo.dwNumberOfProcessors;
#else
- s_numberOfCores = defaultIfUnavailable;
+ 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