Skip to content

Commit a1067a2

Browse files
committed
Use libc types for sched FFI
1 parent 28c5b4a commit a1067a2

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

src/sched.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,6 @@ impl CpuSet {
7373
}
7474
}
7575

76-
mod ffi {
77-
use libc::{c_void, c_int};
78-
79-
pub type CloneCb = extern "C" fn(data: *const super::CloneCb) -> c_int;
80-
81-
// We cannot give a proper #[repr(C)] to super::CloneCb
82-
#[allow(improper_ctypes)]
83-
extern "C" {
84-
// create a child process
85-
// doc: http://man7.org/linux/man-pages/man2/clone.2.html
86-
pub fn clone(cb: *const CloneCb,
87-
child_stack: *mut c_void,
88-
flags: c_int,
89-
arg: *mut super::CloneCb,
90-
...)
91-
-> c_int;
92-
}
93-
}
94-
9576
pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> {
9677
let res = unsafe {
9778
libc::sched_setaffinity(pid.into(),
@@ -116,10 +97,10 @@ pub fn clone(mut cb: CloneCb,
11697
let combined = flags.bits() | signal.unwrap_or(0);
11798
let ptr = stack.as_mut_ptr().offset(stack.len() as isize);
11899
let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1);
119-
ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
100+
libc::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
120101
ptr_aligned as *mut c_void,
121102
combined,
122-
&mut cb)
103+
&mut cb as *mut _ as *mut c_void)
123104
};
124105

125106
Errno::result(res).map(Pid::from_raw)

0 commit comments

Comments
 (0)