diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-20 11:14:51 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-20 11:14:51 +0000 |
commit | c15d1e7756cee2b7febad6ab4e550165238ef514 (patch) | |
tree | 4556fb81d66e675088854bdb00b3d58d845f5e9a /base | |
parent | 947e336d09cf625bfe6d14b973aa3411acebe477 (diff) | |
download | chromium_src-c15d1e7756cee2b7febad6ab4e550165238ef514.zip chromium_src-c15d1e7756cee2b7febad6ab4e550165238ef514.tar.gz chromium_src-c15d1e7756cee2b7febad6ab4e550165238ef514.tar.bz2 |
Cache the numberOfProcessors value on posix and expose it to blink
We need to cache the value, so we can request it from blink after
the sandbox was already turned on.
BUG=321060
R=jam@chromium.org,mark@chromium.org,jamesr@chromium.org
Review URL: https://codereview.chromium.org/67373006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/sys_info_internal.h | 34 | ||||
-rw-r--r-- | base/sys_info_linux.cc | 23 | ||||
-rw-r--r-- | base/sys_info_posix.cc | 20 |
4 files changed, 58 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 |