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

Side by Side Diff: base/sys_info_posix.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_linux.cc ('k') | content/zygote/zygote_main_linux.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 <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/param.h> 9 #include <sys/param.h>
10 #include <sys/utsname.h> 10 #include <sys/utsname.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/lazy_instance.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/sys_info_internal.h"
17 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
18 20
19 #if defined(OS_ANDROID) 21 #if defined(OS_ANDROID)
20 #include <sys/vfs.h> 22 #include <sys/vfs.h>
21 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. 23 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
22 #else 24 #else
23 #include <sys/statvfs.h> 25 #include <sys/statvfs.h>
24 #endif 26 #endif
25 27
26 namespace base { 28 namespace {
27 29
28 #if !defined(OS_OPENBSD) 30 #if !defined(OS_OPENBSD)
29 int SysInfo::NumberOfProcessors() { 31 int NumberOfProcessors() {
30 // It seems that sysconf returns the number of "logical" processors on both 32 // It seems that sysconf returns the number of "logical" processors on both
31 // Mac and Linux. So we get the number of "online logical" processors. 33 // Mac and Linux. So we get the number of "online logical" processors.
32 long res = sysconf(_SC_NPROCESSORS_ONLN); 34 long res = sysconf(_SC_NPROCESSORS_ONLN);
33 if (res == -1) { 35 if (res == -1) {
34 NOTREACHED(); 36 NOTREACHED();
35 return 1; 37 return 1;
36 } 38 }
37 39
38 return static_cast<int>(res); 40 return static_cast<int>(res);
39 } 41 }
42
43 base::LazyInstance<
44 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky
45 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER;
46 #endif
47
48 } // namespace
49
50 namespace base {
51
52 #if !defined(OS_OPENBSD)
53 int SysInfo::NumberOfProcessors() {
54 return g_lazy_number_of_processors.Get().value();
55 }
40 #endif 56 #endif
41 57
42 // static 58 // static
43 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 59 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
44 base::ThreadRestrictions::AssertIOAllowed(); 60 base::ThreadRestrictions::AssertIOAllowed();
45 61
46 struct statvfs stats; 62 struct statvfs stats;
47 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) 63 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
48 return -1; 64 return -1;
49 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; 65 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 104 }
89 return arch; 105 return arch;
90 } 106 }
91 107
92 // static 108 // static
93 size_t SysInfo::VMAllocationGranularity() { 109 size_t SysInfo::VMAllocationGranularity() {
94 return getpagesize(); 110 return getpagesize();
95 } 111 }
96 112
97 } // namespace base 113 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_linux.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698