From 8927ef00a230332be1669144e0dbd2a4d6db8ee6 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 25 Nov 2020 20:26:21 +0800 Subject: [PATCH] kernel: add TryReceiveMessage support This is a nonblocking form of ReceiveMessage. Signed-off-by: Sean Cross --- kernel/src/syscall.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 4f4ae472d..3d7a36ae8 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -10,6 +10,12 @@ use xous_kernel::*; /// This is the context that called SwitchTo static mut SWITCHTO_CALLER: Option<(PID, TID)> = None; +#[derive(PartialEq)] +enum ExecutionType { + Blocking, + NonBlocking, +} + fn retry_syscall(pid: PID, tid: TID) -> SysCallResult { if cfg!(baremetal) { arch::process::Process::with_current_mut(|p| p.retry_instruction(tid))?; @@ -480,7 +486,7 @@ fn return_scalar2( }) } -fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult { +fn receive_message(pid: PID, tid: TID, sid: SID, blocking: ExecutionType) -> SysCallResult { SystemServices::with_mut(|ss| { assert!( ss.thread_is_running(pid, tid), @@ -506,6 +512,11 @@ fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult { return Ok(xous_kernel::Result::Message(msg)); } + if blocking == ExecutionType::NonBlocking { + klog!("nonblocking message -- returning None"); + return Ok(xous_kernel::Result::None); + } + // There is no pending message, so return control to the parent // process and mark ourselves as awaiting an event. When a message // arrives, our return value will already be set to the @@ -712,7 +723,8 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR }; Ok(xous_kernel::Result::ResumeProcess) } - SysCall::ReceiveMessage(sid) => receive_message(pid, tid, sid), + SysCall::ReceiveMessage(sid) => receive_message(pid, tid, sid, ExecutionType::Blocking), + SysCall::TryReceiveMessage(sid) => receive_message(pid, tid, sid, ExecutionType::NonBlocking), SysCall::WaitEvent => SystemServices::with_mut(|ss| { let process = ss.get_process(pid).expect("Can't get current process"); let ppid = process.ppid;