diff options
Diffstat (limited to 'embassy-sync/src/pubsub')
| -rw-r--r-- | embassy-sync/src/pubsub/mod.rs | 16 | ||||
| -rw-r--r-- | embassy-sync/src/pubsub/publisher.rs | 10 | ||||
| -rw-r--r-- | embassy-sync/src/pubsub/subscriber.rs | 5 |
3 files changed, 31 insertions, 0 deletions
diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs index 637336d9d..66c9b0017 100644 --- a/embassy-sync/src/pubsub/mod.rs +++ b/embassy-sync/src/pubsub/mod.rs | |||
| @@ -173,6 +173,11 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 173 | CAP - self.len() | 173 | CAP - self.len() |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | /// Clears all elements in the channel. | ||
| 177 | pub fn clear(&self) { | ||
| 178 | self.inner.lock(|inner| inner.borrow_mut().clear()); | ||
| 179 | } | ||
| 180 | |||
| 176 | /// Returns the number of elements currently in the channel. | 181 | /// Returns the number of elements currently in the channel. |
| 177 | pub fn len(&self) -> usize { | 182 | pub fn len(&self) -> usize { |
| 178 | self.inner.lock(|inner| inner.borrow().len()) | 183 | self.inner.lock(|inner| inner.borrow().len()) |
| @@ -270,6 +275,10 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi | |||
| 270 | self.free_capacity() | 275 | self.free_capacity() |
| 271 | } | 276 | } |
| 272 | 277 | ||
| 278 | fn clear(&self) { | ||
| 279 | self.clear(); | ||
| 280 | } | ||
| 281 | |||
| 273 | fn len(&self) -> usize { | 282 | fn len(&self) -> usize { |
| 274 | self.len() | 283 | self.len() |
| 275 | } | 284 | } |
| @@ -407,6 +416,10 @@ impl<T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> PubSubSta | |||
| 407 | self.publisher_count -= 1; | 416 | self.publisher_count -= 1; |
| 408 | } | 417 | } |
| 409 | 418 | ||
| 419 | fn clear(&mut self) { | ||
| 420 | self.queue.clear(); | ||
| 421 | } | ||
| 422 | |||
| 410 | fn len(&self) -> usize { | 423 | fn len(&self) -> usize { |
| 411 | self.queue.len() | 424 | self.queue.len() |
| 412 | } | 425 | } |
| @@ -460,6 +473,9 @@ trait SealedPubSubBehavior<T> { | |||
| 460 | /// This is equivalent to `capacity() - len()` | 473 | /// This is equivalent to `capacity() - len()` |
| 461 | fn free_capacity(&self) -> usize; | 474 | fn free_capacity(&self) -> usize; |
| 462 | 475 | ||
| 476 | /// Clears all elements in the channel. | ||
| 477 | fn clear(&self); | ||
| 478 | |||
| 463 | /// Returns the number of elements currently in the channel. | 479 | /// Returns the number of elements currently in the channel. |
| 464 | fn len(&self) -> usize; | 480 | fn len(&self) -> usize; |
| 465 | 481 | ||
diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs index 26e2c63b7..e66b3b1db 100644 --- a/embassy-sync/src/pubsub/publisher.rs +++ b/embassy-sync/src/pubsub/publisher.rs | |||
| @@ -55,6 +55,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Pub<'a, PSB, T> { | |||
| 55 | self.channel.free_capacity() | 55 | self.channel.free_capacity() |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /// Clears all elements in the ***channel***. | ||
| 59 | pub fn clear(&self) { | ||
| 60 | self.channel.clear(); | ||
| 61 | } | ||
| 62 | |||
| 58 | /// Returns the number of elements currently in the ***channel***. | 63 | /// Returns the number of elements currently in the ***channel***. |
| 59 | pub fn len(&self) -> usize { | 64 | pub fn len(&self) -> usize { |
| 60 | self.channel.len() | 65 | self.channel.len() |
| @@ -155,6 +160,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> ImmediatePub<'a, PSB, T> { | |||
| 155 | self.channel.free_capacity() | 160 | self.channel.free_capacity() |
| 156 | } | 161 | } |
| 157 | 162 | ||
| 163 | /// Clears all elements in the ***channel***. | ||
| 164 | pub fn clear(&self) { | ||
| 165 | self.channel.clear(); | ||
| 166 | } | ||
| 167 | |||
| 158 | /// Returns the number of elements currently in the ***channel***. | 168 | /// Returns the number of elements currently in the ***channel***. |
| 159 | pub fn len(&self) -> usize { | 169 | pub fn len(&self) -> usize { |
| 160 | self.channel.len() | 170 | self.channel.len() |
diff --git a/embassy-sync/src/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs index 2e2bd26a9..6ad660cb3 100644 --- a/embassy-sync/src/pubsub/subscriber.rs +++ b/embassy-sync/src/pubsub/subscriber.rs | |||
| @@ -83,6 +83,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Sub<'a, PSB, T> { | |||
| 83 | self.channel.free_capacity() | 83 | self.channel.free_capacity() |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /// Clears all elements in the ***channel***. | ||
| 87 | pub fn clear(&self) { | ||
| 88 | self.channel.clear(); | ||
| 89 | } | ||
| 90 | |||
| 86 | /// Returns the number of elements currently in the ***channel***. | 91 | /// Returns the number of elements currently in the ***channel***. |
| 87 | /// See [Self::available] for how many messages are available for this subscriber. | 92 | /// See [Self::available] for how many messages are available for this subscriber. |
| 88 | pub fn len(&self) -> usize { | 93 | pub fn len(&self) -> usize { |
