aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben De Smet <[email protected]>2023-08-11 11:15:17 +0200
committerRuben De Smet <[email protected]>2023-08-11 12:13:46 +0200
commitf9d251cd5cd9c84718cd66e7697a8502c4d61a0a (patch)
treea5609c9b9ea462da66ffed7d82b6409fec1ad2f3
parentb658f10db9a963d85b8465759692b0aa7973a1d1 (diff)
Channel poll methods return Poll instead of bool
-rw-r--r--embassy-stm32-wpan/src/mac/driver.rs4
-rw-r--r--embassy-stm32/src/can/bxcan.rs9
-rw-r--r--embassy-sync/src/channel.rs36
3 files changed, 26 insertions, 23 deletions
diff --git a/embassy-stm32-wpan/src/mac/driver.rs b/embassy-stm32-wpan/src/mac/driver.rs
index f8e3a2b08..a58ee231b 100644
--- a/embassy-stm32-wpan/src/mac/driver.rs
+++ b/embassy-stm32-wpan/src/mac/driver.rs
@@ -28,7 +28,9 @@ impl<'d> embassy_net_driver::Driver for Driver<'d> {
28 type TxToken<'a> = TxToken<'d> where Self: 'a; 28 type TxToken<'a> = TxToken<'d> where Self: 'a;
29 29
30 fn receive(&mut self, cx: &mut Context) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { 30 fn receive(&mut self, cx: &mut Context) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
31 if self.runner.rx_channel.poll_ready_to_receive(cx) && self.runner.tx_buf_channel.poll_ready_to_receive(cx) { 31 if self.runner.rx_channel.poll_ready_to_receive(cx).is_ready()
32 && self.runner.tx_buf_channel.poll_ready_to_receive(cx).is_ready()
33 {
32 Some(( 34 Some((
33 RxToken { 35 RxToken {
34 rx: &self.runner.rx_channel, 36 rx: &self.runner.rx_channel,
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs
index fb223e4a9..e439207ef 100644
--- a/embassy-stm32/src/can/bxcan.rs
+++ b/embassy-stm32/src/can/bxcan.rs
@@ -506,14 +506,7 @@ impl<'c, 'd, T: Instance> CanRx<'c, 'd, T> {
506 506
507 /// Waits while receive queue is empty. 507 /// Waits while receive queue is empty.
508 pub async fn wait_not_empty(&mut self) { 508 pub async fn wait_not_empty(&mut self) {
509 poll_fn(|cx| { 509 poll_fn(|cx| T::state().rx_queue.poll_ready_to_receive(cx)).await
510 if T::state().rx_queue.poll_ready_to_receive(cx) {
511 Poll::Ready(())
512 } else {
513 Poll::Pending
514 }
515 })
516 .await
517 } 510 }
518 511
519 fn curr_error(&self) -> Option<BusError> { 512 fn curr_error(&self) -> Option<BusError> {
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 3896f70ac..e7224856c 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -69,7 +69,7 @@ where
69 /// Allows a poll_fn to poll until the channel is ready to send 69 /// Allows a poll_fn to poll until the channel is ready to send
70 /// 70 ///
71 /// See [`Channel::poll_ready_to_send()`] 71 /// See [`Channel::poll_ready_to_send()`]
72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 72 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
73 self.channel.poll_ready_to_send(cx) 73 self.channel.poll_ready_to_send(cx)
74 } 74 }
75} 75}
@@ -117,7 +117,7 @@ impl<'ch, T> DynamicSender<'ch, T> {
117 /// Allows a poll_fn to poll until the channel is ready to send 117 /// Allows a poll_fn to poll until the channel is ready to send
118 /// 118 ///
119 /// See [`Channel::poll_ready_to_send()`] 119 /// See [`Channel::poll_ready_to_send()`]
120 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 120 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
121 self.channel.poll_ready_to_send(cx) 121 self.channel.poll_ready_to_send(cx)
122 } 122 }
123} 123}
@@ -162,7 +162,7 @@ where
162 /// Allows a poll_fn to poll until the channel is ready to receive 162 /// Allows a poll_fn to poll until the channel is ready to receive
163 /// 163 ///
164 /// See [`Channel::poll_ready_to_receive()`] 164 /// See [`Channel::poll_ready_to_receive()`]
165 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 165 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
166 self.channel.poll_ready_to_receive(cx) 166 self.channel.poll_ready_to_receive(cx)
167 } 167 }
168} 168}
@@ -198,7 +198,7 @@ impl<'ch, T> DynamicReceiver<'ch, T> {
198 /// Allows a poll_fn to poll until the channel is ready to receive 198 /// Allows a poll_fn to poll until the channel is ready to receive
199 /// 199 ///
200 /// See [`Channel::poll_ready_to_receive()`] 200 /// See [`Channel::poll_ready_to_receive()`]
201 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 201 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
202 self.channel.poll_ready_to_receive(cx) 202 self.channel.poll_ready_to_receive(cx)
203 } 203 }
204} 204}
@@ -315,8 +315,8 @@ trait DynamicChannel<T> {
315 315
316 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>; 316 fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryRecvError>;
317 317
318 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool; 318 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()>;
319 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool; 319 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()>;
320} 320}
321 321
322/// Error returned by [`try_recv`](Channel::try_recv). 322/// Error returned by [`try_recv`](Channel::try_recv).
@@ -370,10 +370,14 @@ impl<T, const N: usize> ChannelState<T, N> {
370 } 370 }
371 } 371 }
372 372
373 fn poll_ready_to_receive(&mut self, cx: &mut Context<'_>) -> bool { 373 fn poll_ready_to_receive(&mut self, cx: &mut Context<'_>) -> Poll<()> {
374 self.receiver_waker.register(cx.waker()); 374 self.receiver_waker.register(cx.waker());
375 375
376 !self.queue.is_empty() 376 if !self.queue.is_empty() {
377 Poll::Ready(())
378 } else {
379 Poll::Pending
380 }
377 } 381 }
378 382
379 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> { 383 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> {
@@ -395,10 +399,14 @@ impl<T, const N: usize> ChannelState<T, N> {
395 } 399 }
396 } 400 }
397 401
398 fn poll_ready_to_send(&mut self, cx: &mut Context<'_>) -> bool { 402 fn poll_ready_to_send(&mut self, cx: &mut Context<'_>) -> Poll<()> {
399 self.senders_waker.register(cx.waker()); 403 self.senders_waker.register(cx.waker());
400 404
401 !self.queue.is_full() 405 if !self.queue.is_full() {
406 Poll::Ready(())
407 } else {
408 Poll::Pending
409 }
402 } 410 }
403} 411}
404 412
@@ -449,12 +457,12 @@ where
449 } 457 }
450 458
451 /// Allows a poll_fn to poll until the channel is ready to receive 459 /// Allows a poll_fn to poll until the channel is ready to receive
452 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 460 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
453 self.lock(|c| c.poll_ready_to_receive(cx)) 461 self.lock(|c| c.poll_ready_to_receive(cx))
454 } 462 }
455 463
456 /// Allows a poll_fn to poll until the channel is ready to send 464 /// Allows a poll_fn to poll until the channel is ready to send
457 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 465 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
458 self.lock(|c| c.poll_ready_to_send(cx)) 466 self.lock(|c| c.poll_ready_to_send(cx))
459 } 467 }
460 468
@@ -524,11 +532,11 @@ where
524 Channel::try_recv_with_context(self, cx) 532 Channel::try_recv_with_context(self, cx)
525 } 533 }
526 534
527 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool { 535 fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
528 Channel::poll_ready_to_send(self, cx) 536 Channel::poll_ready_to_send(self, cx)
529 } 537 }
530 538
531 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool { 539 fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> Poll<()> {
532 Channel::poll_ready_to_receive(self, cx) 540 Channel::poll_ready_to_receive(self, cx)
533 } 541 }
534} 542}