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 <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/resource.h> | 10 #include <sys/resource.h> |
11 #include <sys/utsname.h> | 11 #include <sys/utsname.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "base/basictypes.h" | |
15 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
16 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
19 #include "base/sys_info_internal.h" | 18 #include "base/sys_info_internal.h" |
20 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
21 | 20 |
22 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
23 #include <sys/vfs.h> | 22 #include <sys/vfs.h> |
24 #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. |
(...skipping 25 matching lines...) Expand all Loading... |
50 } | 49 } |
51 | 50 |
52 return static_cast<int>(res); | 51 return static_cast<int>(res); |
53 } | 52 } |
54 | 53 |
55 base::LazyInstance< | 54 base::LazyInstance< |
56 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky | 55 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky |
57 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER; | 56 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER; |
58 #endif | 57 #endif |
59 | 58 |
60 int64 AmountOfVirtualMemory() { | 59 int64_t AmountOfVirtualMemory() { |
61 struct rlimit limit; | 60 struct rlimit limit; |
62 int result = getrlimit(RLIMIT_DATA, &limit); | 61 int result = getrlimit(RLIMIT_DATA, &limit); |
63 if (result != 0) { | 62 if (result != 0) { |
64 NOTREACHED(); | 63 NOTREACHED(); |
65 return 0; | 64 return 0; |
66 } | 65 } |
67 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; | 66 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; |
68 } | 67 } |
69 | 68 |
70 base::LazyInstance< | 69 base::LazyInstance< |
71 base::internal::LazySysInfoValue<int64, AmountOfVirtualMemory> >::Leaky | 70 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky |
72 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; | 71 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; |
73 | 72 |
74 } // namespace | 73 } // namespace |
75 | 74 |
76 namespace base { | 75 namespace base { |
77 | 76 |
78 #if !defined(OS_OPENBSD) | 77 #if !defined(OS_OPENBSD) |
79 int SysInfo::NumberOfProcessors() { | 78 int SysInfo::NumberOfProcessors() { |
80 return g_lazy_number_of_processors.Get().value(); | 79 return g_lazy_number_of_processors.Get().value(); |
81 } | 80 } |
82 #endif | 81 #endif |
83 | 82 |
84 // static | 83 // static |
85 int64 SysInfo::AmountOfVirtualMemory() { | 84 int64_t SysInfo::AmountOfVirtualMemory() { |
86 return g_lazy_virtual_memory.Get().value(); | 85 return g_lazy_virtual_memory.Get().value(); |
87 } | 86 } |
88 | 87 |
89 // static | 88 // static |
90 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 89 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
91 base::ThreadRestrictions::AssertIOAllowed(); | 90 base::ThreadRestrictions::AssertIOAllowed(); |
92 | 91 |
93 struct statvfs stats; | 92 struct statvfs stats; |
94 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 93 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
95 return -1; | 94 return -1; |
96 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; | 95 return static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; |
97 } | 96 } |
98 | 97 |
99 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 98 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
100 // static | 99 // static |
101 std::string SysInfo::OperatingSystemName() { | 100 std::string SysInfo::OperatingSystemName() { |
102 struct utsname info; | 101 struct utsname info; |
103 if (uname(&info) < 0) { | 102 if (uname(&info) < 0) { |
104 NOTREACHED(); | 103 NOTREACHED(); |
105 return std::string(); | 104 return std::string(); |
106 } | 105 } |
(...skipping 28 matching lines...) Expand all Loading... |
135 } | 134 } |
136 return arch; | 135 return arch; |
137 } | 136 } |
138 | 137 |
139 // static | 138 // static |
140 size_t SysInfo::VMAllocationGranularity() { | 139 size_t SysInfo::VMAllocationGranularity() { |
141 return getpagesize(); | 140 return getpagesize(); |
142 } | 141 } |
143 | 142 |
144 } // namespace base | 143 } // namespace base |
OLD | NEW |