Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JoinFlags::NON_BLOCKING to proc_join #4202

Merged
merged 2 commits into from
Sep 6, 2023
Merged
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
44 changes: 28 additions & 16 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,20 +182,32 @@ 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.contains(JoinFlags::NON_BLOCKING) {
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)
},
)?;
match res {
AsyncifyAction::Finish(ctx, result) => ret_result(ctx, result),
AsyncifyAction::Unwind => Ok(Errno::Success),
}
}
} else {
trace!(ret_id = pid.raw(), "status=nothing");
ret_result(ctx, JoinStatusResult::Nothing)
}

trace!(ret_id = pid.raw(), "status=nothing");
ret_result(ctx, JoinStatusResult::Nothing)
}