aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/channel.rs
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-07-18 18:28:12 -0500
committerxoviat <[email protected]>2023-07-18 18:28:12 -0500
commit890d113b855dc11be75a9716401c7703f4ce48e1 (patch)
tree1906fc00f0ffea07f0f9a0b4c47810916c8a7c7e /embassy-sync/src/channel.rs
parentd040871f7a078db94846305463c30a461f821d7f (diff)
wpan: fully implement initial draft concept
Diffstat (limited to 'embassy-sync/src/channel.rs')
-rw-r--r--embassy-sync/src/channel.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index 77352874d..f421af392 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -335,6 +335,12 @@ impl<T, const N: usize> ChannelState<T, N> {
335 } 335 }
336 } 336 }
337 337
338 fn poll_ready_to_receive(&mut self, cx: &mut Context<'_>) -> bool {
339 self.receiver_waker.register(cx.waker());
340
341 !self.queue.is_empty()
342 }
343
338 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> { 344 fn try_send(&mut self, message: T) -> Result<(), TrySendError<T>> {
339 self.try_send_with_context(message, None) 345 self.try_send_with_context(message, None)
340 } 346 }
@@ -353,6 +359,12 @@ impl<T, const N: usize> ChannelState<T, N> {
353 } 359 }
354 } 360 }
355 } 361 }
362
363 fn poll_ready_to_send(&mut self, cx: &mut Context<'_>) -> bool {
364 self.senders_waker.register(cx.waker());
365
366 !self.queue.is_full()
367 }
356} 368}
357 369
358/// A bounded channel for communicating between asynchronous tasks 370/// A bounded channel for communicating between asynchronous tasks
@@ -401,6 +413,16 @@ where
401 self.lock(|c| c.try_send_with_context(m, cx)) 413 self.lock(|c| c.try_send_with_context(m, cx))
402 } 414 }
403 415
416 /// Allows a poll_fn to poll until the channel is ready to receive
417 pub fn poll_ready_to_receive(&self, cx: &mut Context<'_>) -> bool {
418 self.lock(|c| c.poll_ready_to_receive(cx))
419 }
420
421 /// Allows a poll_fn to poll until the channel is ready to send
422 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> bool {
423 self.lock(|c| c.poll_ready_to_send(cx))
424 }
425
404 /// Get a sender for this channel. 426 /// Get a sender for this channel.
405 pub fn sender(&self) -> Sender<'_, M, T, N> { 427 pub fn sender(&self) -> Sender<'_, M, T, N> {
406 Sender { channel: self } 428 Sender { channel: self }