OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/system_wrappers/interface/cpu_info.h" | 11 #include "webrtc/system_wrappers/interface/cpu_info.h" |
12 | 12 |
13 #if defined(_WIN32) | 13 #include "webrtc/base/systeminfo.h" |
14 #include <Windows.h> | |
15 #elif defined(WEBRTC_MAC) | |
16 #include <sys/sysctl.h> | |
17 #include <sys/types.h> | |
18 #else // defined(WEBRTC_LINUX) or defined(WEBRTC_ANDROID) | |
19 #include <unistd.h> | |
20 #endif | |
21 | |
22 #include "webrtc/system_wrappers/interface/trace.h" | |
23 | 14 |
24 namespace webrtc { | 15 namespace webrtc { |
25 | 16 |
26 uint32_t CpuInfo::number_of_cores_ = 0; | |
27 | |
28 uint32_t CpuInfo::DetectNumberOfCores() { | 17 uint32_t CpuInfo::DetectNumberOfCores() { |
29 if (!number_of_cores_) { | 18 return static_cast<uint32_t>(rtc::SystemInfo::GetMaxCpus()); |
30 #if defined(_WIN32) | |
31 SYSTEM_INFO si; | |
32 GetSystemInfo(&si); | |
33 number_of_cores_ = static_cast<uint32_t>(si.dwNumberOfProcessors); | |
34 WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, | |
35 "Available number of cores:%d", number_of_cores_); | |
36 | |
37 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) | |
38 number_of_cores_ = static_cast<uint32_t>(sysconf(_SC_NPROCESSORS_ONLN)); | |
39 WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, | |
40 "Available number of cores:%d", number_of_cores_); | |
41 | |
42 #elif defined(WEBRTC_MAC) | |
43 int name[] = {CTL_HW, HW_AVAILCPU}; | |
44 int ncpu; | |
45 size_t size = sizeof(ncpu); | |
46 if (0 == sysctl(name, 2, &ncpu, &size, NULL, 0)) { | |
47 number_of_cores_ = static_cast<uint32_t>(ncpu); | |
48 WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, | |
49 "Available number of cores:%d", number_of_cores_); | |
50 } else { | |
51 WEBRTC_TRACE(kTraceError, kTraceUtility, -1, | |
52 "Failed to get number of cores"); | |
53 number_of_cores_ = 1; | |
54 } | |
55 #else | |
56 WEBRTC_TRACE(kTraceWarning, kTraceUtility, -1, | |
57 "No function to get number of cores"); | |
58 number_of_cores_ = 1; | |
59 #endif | |
60 } | |
61 return number_of_cores_; | |
62 } | 19 } |
63 | 20 |
64 } // namespace webrtc | 21 } // namespace webrtc |
OLD | NEW |