Skip to content

Add CPU_COUNT #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub type msglen_t = ::c_ulong;
pub type nfds_t = ::c_ulong;
pub type nl_item = ::c_int;
pub type idtype_t = ::c_uint;
pub type __cpu_mask = ::c_ulong;

pub enum fpos64_t {} // TODO: fill this out with a struct

Expand Down Expand Up @@ -732,6 +733,16 @@ f! {
0 != (cpuset.bits[idx] & (1 << offset))
}

pub fn CPU_COUNT(cpuset: &cpu_set_t) -> ::c_int {
let mut s: u32 = 0;
let setsize = mem::size_of::<cpu_set_t>();
let cpu_mask_size = mem::size_of::<__cpu_mask>();
for i in cpuset.bits[..(setsize / cpu_mask_size)].iter() {
s += i.count_ones()
};
s as ::c_int
}

pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool {
set1.bits == set2.bits
}
Expand Down