summaryrefslogtreecommitdiffstats
path: root/base/sys_info_linux.cc
diff options
context:
space:
mode:
authordglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 03:05:49 +0000
committerdglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-01 03:05:49 +0000
commite2fc774084c2ffdc32b95fbe28ac19b5339dbb9f (patch)
tree976f1c4fee708567acc8c1b2962305ee2709d89e /base/sys_info_linux.cc
parenta01f6615a7cb6421b128904576b753230c31f1ae (diff)
downloadchromium_src-e2fc774084c2ffdc32b95fbe28ac19b5339dbb9f.zip
chromium_src-e2fc774084c2ffdc32b95fbe28ac19b5339dbb9f.tar.gz
chromium_src-e2fc774084c2ffdc32b95fbe28ac19b5339dbb9f.tar.bz2
Revert 232274 "Reland "Enable SysInfo::AmountOfPhysicalMemory to..."
Broke all linux dbg layout tests (again): http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20%28dbg%29/builds/14495 > Reland "Enable SysInfo::AmountOfPhysicalMemory to be called from within the Linux Sandbox" > > Trigger caching of SysInfo::AmountOfPhysicalMemory in PreSandboxInit() to enable > it to be called by the renderer process after the sandbox is sealed. > > BUG=312241 > > Review URL: https://codereview.chromium.org/52403002 TBR=rmcilroy@chromium.org Review URL: https://codereview.chromium.org/54923005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_linux.cc')
-rw-r--r--base/sys_info_linux.cc70
1 files changed, 23 insertions, 47 deletions
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index fe242b0..acc4771 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -7,7 +7,6 @@
#include <limits>
#include "base/file_util.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -23,64 +22,41 @@ int64 AmountOfMemory(int pages_name) {
return static_cast<int64>(pages) * page_size;
}
-size_t MaxSharedMemorySize() {
- std::string contents;
- base::ReadFileToString(base::FilePath("/proc/sys/kernel/shmmax"), &contents);
- DCHECK(!contents.empty());
- if (!contents.empty() && contents[contents.length() - 1] == '\n') {
- contents.erase(contents.length() - 1);
- }
-
- int64 limit;
- if (!base::StringToInt64(contents, &limit)) {
- limit = 0;
- }
- if (limit < 0 ||
- static_cast<uint64>(limit) > std::numeric_limits<size_t>::max()) {
- limit = 0;
- }
- DCHECK(limit > 0);
- return static_cast<size_t>(limit);
-}
-
-class LazySysInfo {
- public:
- LazySysInfo()
- : kPhysicalMemory_(AmountOfMemory(_SC_PHYS_PAGES)),
- kMaxSharedMemorySize_(MaxSharedMemorySize()) { }
-
- ~LazySysInfo() { }
-
- int64 physical_memory() { return kPhysicalMemory_; }
- size_t max_shared_memory_size() { return kMaxSharedMemorySize_; }
-
- private:
- const int64 kPhysicalMemory_;
- const size_t kMaxSharedMemorySize_;
-
- DISALLOW_COPY_AND_ASSIGN(LazySysInfo);
-};
-
-base::LazyInstance<LazySysInfo>::Leaky
- g_lazy_sys_info = LAZY_INSTANCE_INITIALIZER;
-
} // namespace
namespace base {
// static
-int64 SysInfo::AmountOfAvailablePhysicalMemory() {
- return AmountOfMemory(_SC_AVPHYS_PAGES);
+int64 SysInfo::AmountOfPhysicalMemory() {
+ return AmountOfMemory(_SC_PHYS_PAGES);
}
// static
-int64 SysInfo::AmountOfPhysicalMemory() {
- return g_lazy_sys_info.Get().physical_memory();
+int64 SysInfo::AmountOfAvailablePhysicalMemory() {
+ return AmountOfMemory(_SC_AVPHYS_PAGES);
}
// static
size_t SysInfo::MaxSharedMemorySize() {
- return g_lazy_sys_info.Get().max_shared_memory_size();
+ static int64 limit;
+ static bool limit_valid = false;
+ if (!limit_valid) {
+ std::string contents;
+ ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
+ DCHECK(!contents.empty());
+ if (!contents.empty() && contents[contents.length() - 1] == '\n') {
+ contents.erase(contents.length() - 1);
+ }
+ if (base::StringToInt64(contents, &limit)) {
+ DCHECK(limit >= 0);
+ DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
+ limit_valid = true;
+ } else {
+ NOTREACHED();
+ return 0;
+ }
+ }
+ return static_cast<size_t>(limit);
}
// static