mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
kernel: add TryReceiveMessage support
This is a nonblocking form of ReceiveMessage. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
6604bfcdb0
commit
8927ef00a2
1 changed files with 14 additions and 2 deletions
|
|
@ -10,6 +10,12 @@ use xous_kernel::*;
|
||||||
/// This is the context that called SwitchTo
|
/// This is the context that called SwitchTo
|
||||||
static mut SWITCHTO_CALLER: Option<(PID, TID)> = None;
|
static mut SWITCHTO_CALLER: Option<(PID, TID)> = None;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum ExecutionType {
|
||||||
|
Blocking,
|
||||||
|
NonBlocking,
|
||||||
|
}
|
||||||
|
|
||||||
fn retry_syscall(pid: PID, tid: TID) -> SysCallResult {
|
fn retry_syscall(pid: PID, tid: TID) -> SysCallResult {
|
||||||
if cfg!(baremetal) {
|
if cfg!(baremetal) {
|
||||||
arch::process::Process::with_current_mut(|p| p.retry_instruction(tid))?;
|
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| {
|
SystemServices::with_mut(|ss| {
|
||||||
assert!(
|
assert!(
|
||||||
ss.thread_is_running(pid, tid),
|
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));
|
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
|
// There is no pending message, so return control to the parent
|
||||||
// process and mark ourselves as awaiting an event. When a message
|
// process and mark ourselves as awaiting an event. When a message
|
||||||
// arrives, our return value will already be set to the
|
// 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)
|
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| {
|
SysCall::WaitEvent => SystemServices::with_mut(|ss| {
|
||||||
let process = ss.get_process(pid).expect("Can't get current process");
|
let process = ss.get_process(pid).expect("Can't get current process");
|
||||||
let ppid = process.ppid;
|
let ppid = process.ppid;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue