system-info 0.1.2

Library to get system information
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! CPU information.

///Returns number of CPU cores on system, as reported by OS.
pub fn count() -> usize {
    #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
    const CONF_NAME: libc::c_int = libc::_SC_NPROCESSORS_CONF;
    #[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
    const CONF_NAME: libc::c_int = libc::_SC_NPROCESSORS_ONLN;

    let cpus = unsafe { libc::sysconf(CONF_NAME) };
    if cpus < 1 {
        1
    } else {
        cpus as usize
    }
}