Skip to content

Commit

Permalink
Add JoinFlags::NON_BLOCKING support to proc_join
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bartoszek committed Sep 5, 2023
1 parent 037b4bd commit 770e951
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/wasix/src/syscalls/wasix/proc_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn proc_join<M: MemorySize + 'static>(
pub(super) fn proc_join_internal<M: MemorySize + 'static>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
pid_ptr: WasmPtr<OptionPid, M>,
_flags: JoinFlags,
flags: JoinFlags,
status_ptr: WasmPtr<JoinStatus, M>,
) -> Result<Errno, WasiError> {
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
Expand Down Expand Up @@ -182,18 +182,30 @@ pub(super) fn proc_join_internal<M: MemorySize + 'static>(
}
));

// Wait for the process to finish
let process2 = process.clone();
let res =
__asyncify_with_deep_sleep::<M, _, _>(ctx, Duration::from_millis(50), async move {
let exit_code = process.join().await.unwrap_or_else(|_| Errno::Child.into());
tracing::trace!(%exit_code, "triggered child join");
JoinStatusResult::ExitNormal(pid, exit_code)
})?;
return match res {
AsyncifyAction::Finish(ctx, result) => ret_result(ctx, result),
AsyncifyAction::Unwind => Ok(Errno::Success),
};
if flags & JoinFlags::NON_BLOCKING != JoinFlags::from_bits_preserve(0) {
return if let Some(status) = process.try_join() {
let exit_code = status.unwrap_or_else(|_| Errno::Child.into());
ret_result(ctx, JoinStatusResult::ExitNormal(pid, exit_code))
} else {
ret_result(ctx, JoinStatusResult::Nothing)
};
} else {
// Wait for the process to finish
let process2 = process.clone();
let res = __asyncify_with_deep_sleep::<M, _, _>(
ctx,
Duration::from_millis(50),
async move {
let exit_code = process.join().await.unwrap_or_else(|_| Errno::Child.into());
tracing::trace!(%exit_code, "triggered child join");
JoinStatusResult::ExitNormal(pid, exit_code)
},
)?;
return match res {
AsyncifyAction::Finish(ctx, result) => ret_result(ctx, result),
AsyncifyAction::Unwind => Ok(Errno::Success),
};
}
}

trace!(ret_id = pid.raw(), "status=nothing");
Expand Down

0 comments on commit 770e951

Please sign in to comment.