Skip to content

Commit

Permalink
FreeBSD: Use None instead of 0 as a failure indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Apr 21, 2023
1 parent ea8b813 commit 20117a0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,8 @@ fn get_num_cpus() -> usize {
use std::ptr;

#[cfg(target_os = "freebsd")]
{
let cpus = get_cpuset_cpus();
if cpus > 0 {
return cpus;
}
if let Some(cpus) = get_cpuset_cpus() {
return cpus;
}

let mut cpus: libc::c_uint = 0;
Expand All @@ -270,7 +267,7 @@ fn get_num_cpus() -> usize {
}

#[cfg(target_os = "freebsd")]
fn get_cpuset_cpus() -> usize {
fn get_cpuset_cpus() -> Option<usize> {
use std::mem;

let mut set: libc::cpuset_t = unsafe { mem::zeroed() };
Expand All @@ -284,9 +281,9 @@ fn get_cpuset_cpus() -> usize {
)
} == 0
{
unsafe { libc::CPU_COUNT(&set) as usize }
Some(unsafe { libc::CPU_COUNT(&set) as usize })
} else {
0
None
}
}

Expand Down

0 comments on commit 20117a0

Please sign in to comment.