Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ use std::mem::{size_of, zeroed};

pub fn set_thread_affinity(core_ids: &[usize]) -> Result<()> {
let mut set: cpu_set_t = unsafe { zeroed() };
unsafe {
for core_id in core_ids {
CPU_SET(*core_id, &mut set);

for &core_id in core_ids {
if core_id >= CPU_SETSIZE as usize {
return Err(From::from(format!(
"invalid core id {}: must be less than CPU_SETSIZE ({})",
core_id,
CPU_SETSIZE
)));
}

unsafe {
CPU_SET(core_id, &mut set);
}
}

Expand Down