Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 } | 21 } |
| 22 return static_cast<int64>(pages) * page_size; | 22 return static_cast<int64>(pages) * page_size; |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 int64 SysInfo::AmountOfPhysicalMemory() { | 30 int64 SysInfo::AmountOfPhysicalMemory() { |
| 31 return AmountOfMemory(_SC_PHYS_PAGES); | 31 static int64 physical_memory; |
| 32 static bool physical_memory_valid = false; | |
| 33 if (!physical_memory_valid) { | |
|
jar (doing other things)
2013/10/18 19:24:14
I'm hopeful this is done on only one thread... as
jln (very slow on Chromium)
2013/10/18 21:08:42
Should we just use LazyInstance these things? It's
jar (doing other things)
2013/10/18 22:19:30
+1. If in doubt about multi-threading, I'd rather
| |
| 34 physical_memory = AmountOfMemory(_SC_PHYS_PAGES); | |
| 35 physical_memory_valid = true; | |
| 36 } | |
| 37 return physical_memory; | |
| 32 } | 38 } |
| 33 | 39 |
| 34 // static | 40 // static |
| 35 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 41 int64 SysInfo::AmountOfAvailablePhysicalMemory() { |
| 36 return AmountOfMemory(_SC_AVPHYS_PAGES); | 42 return AmountOfMemory(_SC_AVPHYS_PAGES); |
| 37 } | 43 } |
| 38 | 44 |
| 39 // static | 45 // static |
| 40 size_t SysInfo::MaxSharedMemorySize() { | 46 size_t SysInfo::MaxSharedMemorySize() { |
| 41 static int64 limit; | 47 static int64 limit; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { | 82 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { |
| 77 size_t pos = line.find(": "); | 83 size_t pos = line.find(": "); |
| 78 return line.substr(pos + 2); | 84 return line.substr(pos + 2); |
| 79 } | 85 } |
| 80 } | 86 } |
| 81 } | 87 } |
| 82 return std::string(); | 88 return std::string(); |
| 83 } | 89 } |
| 84 | 90 |
| 85 } // namespace base | 91 } // namespace base |
| OLD | NEW |