diff --git a/Cargo.toml b/Cargo.toml index 1f3f8e8..38f8b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ repository = "https://github.com/seanmonstar/num_cpus" [dependencies] -libc = "*" +libc = "0.1.7" diff --git a/src/lib.rs b/src/lib.rs index 7a57a0e..1d897aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,11 +57,17 @@ fn get_num_cpus() -> usize { cpus as usize } -#[cfg(target_os= "linux")] +#[cfg( + any( + target_os = "linux", + target_os = "nacl", + target_os = "macos", + target_os = "ios" + ) +)] fn get_num_cpus() -> usize { - //to-do: replace with libc::_SC_NPROCESSORS_ONLN once available unsafe { - libc::sysconf(84) as usize + libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize } } @@ -73,27 +79,6 @@ fn get_num_cpus() -> usize { } } -#[cfg(target_os = "nacl")] -fn get_num_cpus() -> usize { - //to-do: replace with libc::_SC_NPROCESSORS_ONLN once available - unsafe { - libc::sysconf(1) as usize - } -} - -#[cfg( - any( - target_os = "macos", - target_os = "ios" - ) -)] -fn get_num_cpus() -> usize { - //to-do: replace with libc::_SC_NPROCESSORS_ONLN once available - unsafe { - libc::sysconf(58) as usize - } -} - #[test] fn lower_bound() { assert!(get() > 0);