Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/system_wrappers/source/cpu_info.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 2.0 KB
Line 
1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/system_wrappers/interface/cpu_info.h"
12
13#if defined(_WIN32)
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
24namespace webrtc {
25
26uint32_t CpuInfo::number_of_cores_ = 0;
27
28uint32_t CpuInfo::DetectNumberOfCores() {
29  if (!number_of_cores_) {
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}
63
64}  // namespace webrtc
Note: See TracBrowser for help on using the repository browser.