From 37d3e4973e1f89b55a117664d7afe4369ac8a2fa Mon Sep 17 00:00:00 2001 From: kelas Date: Tue, 7 Jun 2022 19:21:43 +0200 Subject: [PATCH] don't block if the queue isn't empty --- services/keyboard/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index 1103fa862..2b882b951 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -790,6 +790,17 @@ fn main() -> ! { if ena != 0 { vibe = true } else { vibe = false } }), + Some(Opcode::BlockingKeyListener) => { + if blocking_queue.len() != 0 { + // we have a pending byte in the queue, return it + let k_prime = blocking_queue.pop_front().unwrap(); + xous::return_scalar2(msg.sender, k_prime, 0).unwrap(); + } else { + // by simply storing the sender address and not returning a value, + // the sender will remain blocked until the return value is generated + blocking_listener.push(msg.sender); + } + }, Some(Opcode::BlockingKeyListener) => { // by simply storing the sender address and not returning a value, // the sender will remain blocked until the return value is generated