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

Side by Side Diff: base/sys_info_linux.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/sys_info_internal.h ('k') | base/sys_info_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/sys_info_internal.h"
13 14
14 namespace { 15 namespace {
15 16
16 int64 AmountOfMemory(int pages_name) { 17 int64 AmountOfMemory(int pages_name) {
17 long pages = sysconf(pages_name); 18 long pages = sysconf(pages_name);
18 long page_size = sysconf(_SC_PAGESIZE); 19 long page_size = sysconf(_SC_PAGESIZE);
19 if (pages == -1 || page_size == -1) { 20 if (pages == -1 || page_size == -1) {
20 NOTREACHED(); 21 NOTREACHED();
21 return 0; 22 return 0;
22 } 23 }
(...skipping 17 matching lines...) Expand all
40 limit = 0; 41 limit = 0;
41 } 42 }
42 if (limit < 0 || 43 if (limit < 0 ||
43 static_cast<uint64>(limit) > std::numeric_limits<size_t>::max()) { 44 static_cast<uint64>(limit) > std::numeric_limits<size_t>::max()) {
44 limit = 0; 45 limit = 0;
45 } 46 }
46 DCHECK(limit > 0); 47 DCHECK(limit > 0);
47 return static_cast<size_t>(limit); 48 return static_cast<size_t>(limit);
48 } 49 }
49 50
50 template<typename T, T (*F)(void)> 51 base::LazyInstance<
51 class LazySysInfoValue { 52 base::internal::LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
52 public:
53 LazySysInfoValue()
54 : value_(F()) { }
55
56 ~LazySysInfoValue() { }
57
58 T value() { return value_; }
59
60 private:
61 const T value_;
62
63 DISALLOW_COPY_AND_ASSIGN(LazySysInfoValue);
64 };
65
66 base::LazyInstance<LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
67 g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER; 53 g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER;
68 base::LazyInstance<LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky 54 base::LazyInstance<
55 base::internal::LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky
69 g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER; 56 g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER;
70 57
71 } // namespace 58 } // namespace
72 59
73 namespace base { 60 namespace base {
74 61
75 // static 62 // static
76 int64 SysInfo::AmountOfAvailablePhysicalMemory() { 63 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
77 return AmountOfMemory(_SC_AVPHYS_PAGES); 64 return AmountOfMemory(_SC_AVPHYS_PAGES);
78 } 65 }
(...skipping 25 matching lines...) Expand all
104 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { 91 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) {
105 size_t pos = line.find(": "); 92 size_t pos = line.find(": ");
106 return line.substr(pos + 2); 93 return line.substr(pos + 2);
107 } 94 }
108 } 95 }
109 } 96 }
110 return std::string(); 97 return std::string();
111 } 98 }
112 99
113 } // namespace base 100 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_internal.h ('k') | base/sys_info_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698