From 997ec4320e5ce5200474a8098ec5f92f286439e6 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 07:15:29 +0000 Subject: [PATCH] crates/sel4-shared-ring-buffer/smoltcp: Add can_{receive,transmit} Signed-off-by: Nick Spinale --- crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs | 10 +++++++++- crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs index 093f8d93c..ed55da1df 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/inner.rs @@ -173,8 +173,16 @@ impl Inner { Ok(notify_rx || notify_tx) } + pub(crate) fn can_receive(&mut self) -> bool { + self.can_claim_rx_buffer() && self.can_claim_tx_buffer() + } + + pub(crate) fn can_transmit(&mut self) -> bool { + self.can_claim_tx_buffer() + } + pub(crate) fn receive(&mut self) -> Option<(RxBufferIndex, TxBufferIndex)> { - if self.can_claim_rx_buffer() && self.can_claim_tx_buffer() { + if self.can_receive() { let rx = self.claim_rx_buffer().unwrap(); let tx = self.claim_tx_buffer().unwrap(); Some((rx, tx)) diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs index be4e83954..c389de489 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs @@ -66,6 +66,14 @@ impl DeviceImpl { self.inner().borrow_mut().poll().unwrap() } + pub fn can_receive(&self) -> bool { + self.inner().borrow_mut().can_receive() + } + + pub fn can_transmit(&self) -> bool { + self.inner().borrow_mut().can_transmit() + } + fn new_rx_token(&self, rx_buffer: RxBufferIndex) -> RxToken { RxToken { buffer: rx_buffer,