diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index 4a8cdff7e..ca63b4606 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -46,7 +46,7 @@ pub struct Context { } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, PartialEq)] /// A struct describing memory that is passed between processes. /// The `buf` value will get translated as necessary. pub struct MemoryMessage { @@ -72,7 +72,7 @@ pub struct MemoryMessage { } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, PartialEq)] /// A simple scalar message. This is similar to a `move` message. pub struct ScalarMessage { pub id: MessageId, @@ -83,7 +83,7 @@ pub struct ScalarMessage { } #[repr(usize)] -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum Message { MutableBorrow(MemoryMessage), ImmutableBorrow(MemoryMessage), diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 184684ae3..70427d7f8 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -143,7 +143,9 @@ pub enum SysCall { /// This process will now wait for an event such as an IRQ or Message. WaitEvent, - /// This context will now wait for a message with the given server ID + /// This context will now wait for a message with the given server ID.. + /// You can set up a pool by having multiple threads call `WaitMessage` + /// with the same SID. WaitMessage(SID), /// Stop running the given process. @@ -223,7 +225,7 @@ pub enum SysCall { /// * **ProcessNotChild**: The given process was not a child process, and /// therefore couldn't be resumed. /// * **ProcessTerminated**: The process has crashed. - SwitchTo(PID, usize /* thread ID */), + SwitchTo(PID, usize /* context ID */), /// Create a new Server /// @@ -564,6 +566,7 @@ pub enum Result { ResumeProcess, ServerID(SID), ConnectionID(CID), + Message(Message), UnknownResult(usize, usize, usize, usize, usize, usize, usize), } @@ -655,6 +658,16 @@ pub fn create_server(name: usize) -> core::result::Result { Err(Error::InternalError) } +/// Connect to a server with the given SID +pub fn connect(server: SID) -> core::result::Result { + let result = rsyscall(SysCall::Connect(server))?; + if let Result::ConnectionID(cid) = result { + Ok(cid) + } else { + Err(Error::InternalError) + } +} + /// Suspend the current process until a message is received. This thread will /// block until a message is received. ///