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

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

Issue 120723003: Refactors CPU feature detection. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Cleanup Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/globals.h"
6 #if defined(TARGET_OS_MACOS)
7
8 #include "vm/cpuinfo.h"
9
10 #include <errno.h> // NOLINT
11 #include <sys/types.h> // NOLINT
12 #include <sys/sysctl.h> // NOLINT
13
14 #include "platform/assert.h"
15
16 namespace dart {
17
18 char* CpuInfo::data_ = NULL;
19 intptr_t CpuInfo::datalen_ = 0;
20
21 // No-op on MacOS.
22 void CpuInfo::Read() {}
23
24
25 bool CpuInfo::FieldContains(const char* field, const char* search_string) {
26 ASSERT(search_string != NULL);
27 char dest[1024];
28
29 ExtractField(field, dest, 1024);
30
31 return (strcasestr(dest, search_string) != NULL);
32 }
33
34
35 intptr_t CpuInfo::ExtractField(
36 const char* field, char* dest, const intptr_t dest_len) {
37 ASSERT(field != NULL);
38
39 size_t ret_len = dest_len;
40 if (sysctlbyname(field, dest, &ret_len, NULL, 0) != 0) {
41 UNREACHABLE();
42 return 0;
43 }
44
45 return ret_len;
46 }
47
48
49 bool CpuInfo::HasField(const char* field) {
50 ASSERT(field != NULL);
51 int ret = sysctlbyname(field, NULL, NULL, NULL, 0);
52 return (ret != ENOENT);
53 }
54
55
56 intptr_t CpuInfo::GetCpuModel(char* dest, const intptr_t dest_len) {
57 ASSERT(HasField("machdep.cpu.brand_string"));
58 return ExtractField("machdep.cpu.brand_string", dest, dest_len);
59 }
60
61 } // namespace dart
62
63 #endif // defined(TARGET_OS_MACOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698