summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gypi1
-rw-r--r--base/sys_info_internal.h34
-rw-r--r--base/sys_info_linux.cc23
-rw-r--r--base/sys_info_posix.cc20
-rw-r--r--content/zygote/zygote_main_linux.cc1
-rw-r--r--webkit/child/webkitplatformsupport_impl.cc4
-rw-r--r--webkit/child/webkitplatformsupport_impl.h1
7 files changed, 64 insertions, 20 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 74d83c0..dc83d21 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -540,6 +540,7 @@
'sys_info_android.cc',
'sys_info_chromeos.cc',
'sys_info_freebsd.cc',
+ 'sys_info_internal.h',
'sys_info_ios.mm',
'sys_info_linux.cc',
'sys_info_mac.cc',
diff --git a/base/sys_info_internal.h b/base/sys_info_internal.h
new file mode 100644
index 0000000..e7674d5
--- /dev/null
+++ b/base/sys_info_internal.h
@@ -0,0 +1,34 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_SYS_INFO_INTERNAL_H_
+#define BASE_SYS_INFO_INTERNAL_H_
+
+#include "base/basictypes.h"
+
+namespace base {
+
+namespace internal {
+
+template<typename T, T (*F)(void)>
+class LazySysInfoValue {
+ public:
+ LazySysInfoValue()
+ : value_(F()) { }
+
+ ~LazySysInfoValue() { }
+
+ T value() { return value_; }
+
+ private:
+ const T value_;
+
+ DISALLOW_COPY_AND_ASSIGN(LazySysInfoValue);
+};
+
+} // namespace internal
+
+} // namespace base
+
+#endif // BASE_SYS_INFO_INTERNAL_H_
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index d7c9f10..6f1e5eb 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -10,6 +10,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
+#include "base/sys_info_internal.h"
namespace {
@@ -47,25 +48,11 @@ size_t MaxSharedMemorySize() {
return static_cast<size_t>(limit);
}
-template<typename T, T (*F)(void)>
-class LazySysInfoValue {
- public:
- LazySysInfoValue()
- : value_(F()) { }
-
- ~LazySysInfoValue() { }
-
- T value() { return value_; }
-
- private:
- const T value_;
-
- DISALLOW_COPY_AND_ASSIGN(LazySysInfoValue);
-};
-
-base::LazyInstance<LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
+base::LazyInstance<
+ base::internal::LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky
+base::LazyInstance<
+ base::internal::LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky
g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER;
} // namespace
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index bbb1662..07d08b7 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
diff --git a/content/zygote/zygote_main_linux.cc b/content/zygote/zygote_main_linux.cc
index 503b348..7a79ab3 100644
--- a/content/zygote/zygote_main_linux.cc
+++ b/content/zygote/zygote_main_linux.cc
@@ -276,6 +276,7 @@ static void PreSandboxInit() {
base::SysInfo::AmountOfPhysicalMemory();
base::SysInfo::MaxSharedMemorySize();
+ base::SysInfo::NumberOfProcessors();
// ICU DateFormat class (used in base/time_format.cc) needs to get the
// Olson timezone ID by accessing the zoneinfo files on disk. After
diff --git a/webkit/child/webkitplatformsupport_impl.cc b/webkit/child/webkitplatformsupport_impl.cc
index 92d7ad6..48c8854 100644
--- a/webkit/child/webkitplatformsupport_impl.cc
+++ b/webkit/child/webkitplatformsupport_impl.cc
@@ -871,6 +871,10 @@ size_t WebKitPlatformSupportImpl::physicalMemoryMB() {
return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
}
+size_t WebKitPlatformSupportImpl::numberOfProcessors() {
+ return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
+}
+
void WebKitPlatformSupportImpl::startHeapProfiling(
const blink::WebString& prefix) {
// FIXME(morrita): Make this built on windows.
diff --git a/webkit/child/webkitplatformsupport_impl.h b/webkit/child/webkitplatformsupport_impl.h
index 54e742e..175bfe3 100644
--- a/webkit/child/webkitplatformsupport_impl.h
+++ b/webkit/child/webkitplatformsupport_impl.h
@@ -50,6 +50,7 @@ class WEBKIT_CHILD_EXPORT WebKitPlatformSupportImpl :
virtual size_t memoryUsageMB();
virtual size_t actualMemoryUsageMB();
virtual size_t physicalMemoryMB();
+ virtual size_t numberOfProcessors();
virtual void startHeapProfiling(const blink::WebString& prefix);
virtual void stopHeapProfiling() OVERRIDE;