Skip to content

Commit

Permalink
Use libc types for sched FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
Susurrus committed Aug 26, 2017
1 parent 28c5b4a commit a1067a2
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,6 @@ impl CpuSet {
}
}

mod ffi {
use libc::{c_void, c_int};

pub type CloneCb = extern "C" fn(data: *const super::CloneCb) -> c_int;

// We cannot give a proper #[repr(C)] to super::CloneCb
#[allow(improper_ctypes)]
extern "C" {
// create a child process
// doc: http://man7.org/linux/man-pages/man2/clone.2.html
pub fn clone(cb: *const CloneCb,
child_stack: *mut c_void,
flags: c_int,
arg: *mut super::CloneCb,
...)
-> c_int;
}
}

pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> {
let res = unsafe {
libc::sched_setaffinity(pid.into(),
Expand All @@ -116,10 +97,10 @@ pub fn clone(mut cb: CloneCb,
let combined = flags.bits() | signal.unwrap_or(0);
let ptr = stack.as_mut_ptr().offset(stack.len() as isize);
let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1);
ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
libc::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
ptr_aligned as *mut c_void,
combined,
&mut cb)
&mut cb as *mut _ as *mut c_void)
};

Errno::result(res).map(Pid::from_raw)
Expand Down

0 comments on commit a1067a2

Please sign in to comment.