From b06432b20f152dbc8e526548fc1aa6e705ad5116 Mon Sep 17 00:00:00 2001 From: Philipp Matthias Schaefer Date: Thu, 7 Apr 2016 20:08:56 +0200 Subject: [PATCH] Allow to specify signal when calling clone. --- src/sched.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sched.rs b/src/sched.rs index 7216a2d887..934ce13ff9 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -1,5 +1,6 @@ use std::mem; use std::os::unix::io::RawFd; +use std::option::Option; use libc::{self, c_int, c_void, c_ulong, pid_t}; use {Errno, Result}; @@ -197,17 +198,18 @@ pub fn sched_setaffinity(pid: isize, cpuset: &CpuSet) -> Result<()> { Errno::result(res).map(drop) } -pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> Result { +pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags, signal: Option) -> Result { extern "C" fn callback(data: *mut CloneCb) -> c_int { let cb: &mut CloneCb = unsafe { &mut *data }; (*cb)() as c_int } let res = unsafe { + let combined = flags.bits() | signal.unwrap_or(0); let ptr = stack.as_mut_ptr().offset(stack.len() as isize); ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32), ptr as *mut c_void, - flags.bits(), + combined, &mut cb) };