Prefer receive over recv

This commit is contained in:
Ruben De Smet 2023-08-11 12:07:30 +02:00 committed by Dario Nieuwenhuis
parent a2656f402b
commit 1eb03dc41a
2 changed files with 20 additions and 20 deletions

View file

@ -131,24 +131,24 @@ impl<'d, const MTU: usize> Runner<'d, MTU> {
}
pub async fn tx_buf(&mut self) -> &mut [u8] {
let p = self.tx_chan.recv().await;
let p = self.tx_chan.receive().await;
&mut p.buf[..p.len]
}
pub fn try_tx_buf(&mut self) -> Option<&mut [u8]> {
let p = self.tx_chan.try_recv()?;
let p = self.tx_chan.try_receive()?;
Some(&mut p.buf[..p.len])
}
pub fn poll_tx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> {
match self.tx_chan.poll_recv(cx) {
match self.tx_chan.poll_receive(cx) {
Poll::Ready(p) => Poll::Ready(&mut p.buf[..p.len]),
Poll::Pending => Poll::Pending,
}
}
pub fn tx_done(&mut self) {
self.tx_chan.recv_done();
self.tx_chan.receive_done();
}
}
@ -205,24 +205,24 @@ impl<'d, const MTU: usize> RxRunner<'d, MTU> {
impl<'d, const MTU: usize> TxRunner<'d, MTU> {
pub async fn tx_buf(&mut self) -> &mut [u8] {
let p = self.tx_chan.recv().await;
let p = self.tx_chan.receive().await;
&mut p.buf[..p.len]
}
pub fn try_tx_buf(&mut self) -> Option<&mut [u8]> {
let p = self.tx_chan.try_recv()?;
let p = self.tx_chan.try_receive()?;
Some(&mut p.buf[..p.len])
}
pub fn poll_tx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> {
match self.tx_chan.poll_recv(cx) {
match self.tx_chan.poll_receive(cx) {
Poll::Ready(p) => Poll::Ready(&mut p.buf[..p.len]),
Poll::Pending => Poll::Pending,
}
}
pub fn tx_done(&mut self) {
self.tx_chan.recv_done();
self.tx_chan.receive_done();
}
}
@ -294,7 +294,7 @@ impl<'d, const MTU: usize> embassy_net_driver::Driver for Device<'d, MTU> {
type TxToken<'a> = TxToken<'a, MTU> where Self: 'a ;
fn receive(&mut self, cx: &mut Context) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
if self.rx.poll_recv(cx).is_ready() && self.tx.poll_send(cx).is_ready() {
if self.rx.poll_receive(cx).is_ready() && self.tx.poll_send(cx).is_ready() {
Some((RxToken { rx: self.rx.borrow() }, TxToken { tx: self.tx.borrow() }))
} else {
None
@ -338,9 +338,9 @@ impl<'a, const MTU: usize> embassy_net_driver::RxToken for RxToken<'a, MTU> {
F: FnOnce(&mut [u8]) -> R,
{
// NOTE(unwrap): we checked the queue wasn't full when creating the token.
let pkt = unwrap!(self.rx.try_recv());
let pkt = unwrap!(self.rx.try_receive());
let r = f(&mut pkt.buf[..pkt.len]);
self.rx.recv_done();
self.rx.receive_done();
r
}
}

View file

@ -27,7 +27,7 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
back: 0,
full: false,
send_waker: WakerRegistration::new(),
recv_waker: WakerRegistration::new(),
receive_waker: WakerRegistration::new(),
})),
}
}
@ -62,7 +62,7 @@ impl<'a, M: RawMutex, T> Sender<'a, M, T> {
match s.push_index() {
Some(i) => Poll::Ready(unsafe { &mut *self.channel.buf.add(i) }),
None => {
s.recv_waker.register(cx.waker());
s.receive_waker.register(cx.waker());
Poll::Pending
}
}
@ -76,7 +76,7 @@ impl<'a, M: RawMutex, T> Sender<'a, M, T> {
match s.push_index() {
Some(i) => Poll::Ready(i),
None => {
s.recv_waker.register(cx.waker());
s.receive_waker.register(cx.waker());
Poll::Pending
}
}
@ -99,7 +99,7 @@ impl<'a, M: RawMutex, T> Receiver<'a, M, T> {
Receiver { channel: self.channel }
}
pub fn try_recv(&mut self) -> Option<&mut T> {
pub fn try_receive(&mut self) -> Option<&mut T> {
self.channel.state.lock(|s| {
let s = &mut *s.borrow_mut();
match s.pop_index() {
@ -109,7 +109,7 @@ impl<'a, M: RawMutex, T> Receiver<'a, M, T> {
})
}
pub fn poll_recv(&mut self, cx: &mut Context) -> Poll<&mut T> {
pub fn poll_receive(&mut self, cx: &mut Context) -> Poll<&mut T> {
self.channel.state.lock(|s| {
let s = &mut *s.borrow_mut();
match s.pop_index() {
@ -122,7 +122,7 @@ impl<'a, M: RawMutex, T> Receiver<'a, M, T> {
})
}
pub async fn recv(&mut self) -> &mut T {
pub async fn receive(&mut self) -> &mut T {
let i = poll_fn(|cx| {
self.channel.state.lock(|s| {
let s = &mut *s.borrow_mut();
@ -139,7 +139,7 @@ impl<'a, M: RawMutex, T> Receiver<'a, M, T> {
unsafe { &mut *self.channel.buf.add(i) }
}
pub fn recv_done(&mut self) {
pub fn receive_done(&mut self) {
self.channel.state.lock(|s| s.borrow_mut().pop_done())
}
}
@ -157,7 +157,7 @@ struct State {
full: bool,
send_waker: WakerRegistration,
recv_waker: WakerRegistration,
receive_waker: WakerRegistration,
}
impl State {
@ -204,6 +204,6 @@ impl State {
assert!(!self.is_empty());
self.front = self.increment(self.front);
self.full = false;
self.recv_waker.wake();
self.receive_waker.wake();
}
}