diff options
| author | xoviat <[email protected]> | 2023-07-21 22:29:15 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-21 22:29:15 +0000 |
| commit | 4db63677f6e56c52ea3d432542513967f5d93c69 (patch) | |
| tree | ad109082d957fced3b0e9a33ba74f3a47ea1da54 /embassy-sync/src | |
| parent | 4d1d125f4157084668a949f9bc24e4417628f9fe (diff) | |
| parent | f4d6a23f92c8f6d3eb97a09e5bc51bac5e8d6837 (diff) | |
Merge pull request #1658 from xoviat/mac
implement most infra for wpan mac
Diffstat (limited to 'embassy-sync/src')
| -rw-r--r-- | embassy-sync/src/channel.rs | 22 |
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 } |
