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

Side by Side Diff: runtime/vm/cpuinfo_macos.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months 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
« no previous file with comments | « runtime/vm/cpuinfo_linux.cc ('k') | runtime/vm/cpuinfo_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(HOST_OS_MACOS) 6 #if defined(HOST_OS_MACOS)
7 7
8 #include "vm/cpuinfo.h" 8 #include "vm/cpuinfo.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <sys/sysctl.h> // NOLINT
11 #include <sys/types.h> // NOLINT 12 #include <sys/types.h> // NOLINT
12 #include <sys/sysctl.h> // NOLINT
13 13
14 #include "platform/assert.h" 14 #include "platform/assert.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault; 18 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
19 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; 19 const char* CpuInfo::fields_[kCpuInfoMax] = {0};
20 20
21 void CpuInfo::InitOnce() { 21 void CpuInfo::InitOnce() {
22 method_ = kCpuInfoSystem; 22 method_ = kCpuInfoSystem;
23 23
24 fields_[kCpuInfoProcessor] = "machdep.cpu.vendor"; 24 fields_[kCpuInfoProcessor] = "machdep.cpu.vendor";
25 fields_[kCpuInfoModel] = "machdep.cpu.brand_string"; 25 fields_[kCpuInfoModel] = "machdep.cpu.brand_string";
26 fields_[kCpuInfoHardware] = "machdep.cpu.brand_string"; 26 fields_[kCpuInfoHardware] = "machdep.cpu.brand_string";
27 fields_[kCpuInfoFeatures] = "machdep.cpu.features"; 27 fields_[kCpuInfoFeatures] = "machdep.cpu.features";
28 fields_[kCpuInfoArchitecture] = NULL; 28 fields_[kCpuInfoArchitecture] = NULL;
29 } 29 }
30 30
31
32 void CpuInfo::Cleanup() {} 31 void CpuInfo::Cleanup() {}
33 32
34
35 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { 33 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
36 ASSERT(method_ != kCpuInfoDefault); 34 ASSERT(method_ != kCpuInfoDefault);
37 ASSERT(search_string != NULL); 35 ASSERT(search_string != NULL);
38 const char* field = FieldName(idx); 36 const char* field = FieldName(idx);
39 char dest[1024]; 37 char dest[1024];
40 size_t dest_len = 1024; 38 size_t dest_len = 1024;
41 39
42 ASSERT(HasField(field)); 40 ASSERT(HasField(field));
43 if (sysctlbyname(field, dest, &dest_len, NULL, 0) != 0) { 41 if (sysctlbyname(field, dest, &dest_len, NULL, 0) != 0) {
44 UNREACHABLE(); 42 UNREACHABLE();
45 return false; 43 return false;
46 } 44 }
47 45
48 return (strcasestr(dest, search_string) != NULL); 46 return (strcasestr(dest, search_string) != NULL);
49 } 47 }
50 48
51
52 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { 49 const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
53 ASSERT(method_ != kCpuInfoDefault); 50 ASSERT(method_ != kCpuInfoDefault);
54 const char* field = FieldName(idx); 51 const char* field = FieldName(idx);
55 ASSERT(field != NULL); 52 ASSERT(field != NULL);
56 size_t result_len; 53 size_t result_len;
57 54
58 ASSERT(HasField(field)); 55 ASSERT(HasField(field));
59 if (sysctlbyname(field, NULL, &result_len, NULL, 0) != 0) { 56 if (sysctlbyname(field, NULL, &result_len, NULL, 0) != 0) {
60 UNREACHABLE(); 57 UNREACHABLE();
61 return 0; 58 return 0;
62 } 59 }
63 60
64 char* result = reinterpret_cast<char*>(malloc(result_len)); 61 char* result = reinterpret_cast<char*>(malloc(result_len));
65 if (sysctlbyname(field, result, &result_len, NULL, 0) != 0) { 62 if (sysctlbyname(field, result, &result_len, NULL, 0) != 0) {
66 UNREACHABLE(); 63 UNREACHABLE();
67 return 0; 64 return 0;
68 } 65 }
69 66
70 return result; 67 return result;
71 } 68 }
72 69
73
74 bool CpuInfo::HasField(const char* field) { 70 bool CpuInfo::HasField(const char* field) {
75 ASSERT(method_ != kCpuInfoDefault); 71 ASSERT(method_ != kCpuInfoDefault);
76 ASSERT(field != NULL); 72 ASSERT(field != NULL);
77 int ret = sysctlbyname(field, NULL, NULL, NULL, 0); 73 int ret = sysctlbyname(field, NULL, NULL, NULL, 0);
78 return (ret == 0); 74 return (ret == 0);
79 } 75 }
80 76
81 } // namespace dart 77 } // namespace dart
82 78
83 #endif // defined(HOST_OS_MACOS) 79 #endif // defined(HOST_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/cpuinfo_linux.cc ('k') | runtime/vm/cpuinfo_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698