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

Unified Diff: base/sys_info_posix.cc

Issue 67373006: Cache the numberOfProcessors value on posix and expose it to blink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | « base/sys_info_linux.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_posix.cc
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index bbb166255906317053dcc068cc4381acf56c381e..07d08b72bbcb51fd8e550ab79409c55c6dff9af4 100644
--- a/base/sys_info_posix.cc
+++ b/base/sys_info_posix.cc
@@ -12,8 +12,10 @@
#include "base/basictypes.h"
#include "base/file_util.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/sys_info_internal.h"
#include "base/threading/thread_restrictions.h"
#if defined(OS_ANDROID)
@@ -23,10 +25,10 @@
#include <sys/statvfs.h>
#endif
-namespace base {
+namespace {
#if !defined(OS_OPENBSD)
-int SysInfo::NumberOfProcessors() {
+int NumberOfProcessors() {
// It seems that sysconf returns the number of "logical" processors on both
// Mac and Linux. So we get the number of "online logical" processors.
long res = sysconf(_SC_NPROCESSORS_ONLN);
@@ -37,6 +39,20 @@ int SysInfo::NumberOfProcessors() {
return static_cast<int>(res);
}
+
+base::LazyInstance<
+ base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky
+ g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER;
+#endif
+
+} // namespace
+
+namespace base {
+
+#if !defined(OS_OPENBSD)
+int SysInfo::NumberOfProcessors() {
+ return g_lazy_number_of_processors.Get().value();
+}
#endif
// static
« no previous file with comments | « base/sys_info_linux.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698