aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-10-07 15:42:48 +0000
committerGitHub <[email protected]>2024-10-07 15:42:48 +0000
commit42815e944af09f7de6278483caf0fb7e65ab1d1d (patch)
treea0e24a8a1517584555213f688afe39f05f9795fe /embassy-sync
parent7920ba8f8fe4d8880fa81f8481ad594041966e30 (diff)
parent2704ac3d289650173b60e1a29d70e8903bea4cf1 (diff)
Merge pull request #3401 from sourcebox/sync-additions
Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `priority_channel::{Sender, Receiver}`
Diffstat (limited to 'embassy-sync')
-rw-r--r--embassy-sync/CHANGELOG.md1
-rw-r--r--embassy-sync/README.md2
-rw-r--r--embassy-sync/src/priority_channel.rs84
3 files changed, 86 insertions, 1 deletions
diff --git a/embassy-sync/CHANGELOG.md b/embassy-sync/CHANGELOG.md
index 83fd666ac..1668c9319 100644
--- a/embassy-sync/CHANGELOG.md
+++ b/embassy-sync/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10- Add LazyLock sync primitive. 10- Add LazyLock sync primitive.
11- Add `clear`, `len`, `is_empty` and `is_full` functions to `zerocopy_channel`. 11- Add `clear`, `len`, `is_empty` and `is_full` functions to `zerocopy_channel`.
12- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `channel::{Sender, Receiver}`. 12- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `channel::{Sender, Receiver}`.
13- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `priority_channel::{Sender, Receiver}`.
13 14
14## 0.6.0 - 2024-05-29 15## 0.6.0 - 2024-05-29
15 16
diff --git a/embassy-sync/README.md b/embassy-sync/README.md
index 3dcd9dcc8..6871bcabc 100644
--- a/embassy-sync/README.md
+++ b/embassy-sync/README.md
@@ -5,7 +5,7 @@ An [Embassy](https://embassy.dev) project.
5Synchronization primitives and data structures with async support: 5Synchronization primitives and data structures with async support:
6 6
7- [`Channel`](channel::Channel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. 7- [`Channel`](channel::Channel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer.
8- [`PriorityChannel`](channel::priority_channel::PriorityChannel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. Higher priority items are shifted to the front of the channel. 8- [`PriorityChannel`](priority_channel::PriorityChannel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. Higher priority items are shifted to the front of the channel.
9- [`PubSubChannel`](pubsub::PubSubChannel) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. 9- [`PubSubChannel`](pubsub::PubSubChannel) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers.
10- [`Signal`](signal::Signal) - Signalling latest value to a single consumer. 10- [`Signal`](signal::Signal) - Signalling latest value to a single consumer.
11- [`Watch`](watch::Watch) - Signalling latest value to multiple consumers. 11- [`Watch`](watch::Watch) - Signalling latest value to multiple consumers.
diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs
index 24c6c5a7f..1f4d8667c 100644
--- a/embassy-sync/src/priority_channel.rs
+++ b/embassy-sync/src/priority_channel.rs
@@ -71,6 +71,48 @@ where
71 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> { 71 pub fn poll_ready_to_send(&self, cx: &mut Context<'_>) -> Poll<()> {
72 self.channel.poll_ready_to_send(cx) 72 self.channel.poll_ready_to_send(cx)
73 } 73 }
74
75 /// Returns the maximum number of elements the channel can hold.
76 ///
77 /// See [`PriorityChannel::capacity()`]
78 pub const fn capacity(&self) -> usize {
79 self.channel.capacity()
80 }
81
82 /// Returns the free capacity of the channel.
83 ///
84 /// See [`PriorityChannel::free_capacity()`]
85 pub fn free_capacity(&self) -> usize {
86 self.channel.free_capacity()
87 }
88
89 /// Clears all elements in the channel.
90 ///
91 /// See [`PriorityChannel::clear()`]
92 pub fn clear(&self) {
93 self.channel.clear();
94 }
95
96 /// Returns the number of elements currently in the channel.
97 ///
98 /// See [`PriorityChannel::len()`]
99 pub fn len(&self) -> usize {
100 self.channel.len()
101 }
102
103 /// Returns whether the channel is empty.
104 ///
105 /// See [`PriorityChannel::is_empty()`]
106 pub fn is_empty(&self) -> bool {
107 self.channel.is_empty()
108 }
109
110 /// Returns whether the channel is full.
111 ///
112 /// See [`PriorityChannel::is_full()`]
113 pub fn is_full(&self) -> bool {
114 self.channel.is_full()
115 }
74} 116}
75 117
76impl<'ch, M, T, K, const N: usize> From<Sender<'ch, M, T, K, N>> for DynamicSender<'ch, T> 118impl<'ch, M, T, K, const N: usize> From<Sender<'ch, M, T, K, N>> for DynamicSender<'ch, T>
@@ -146,6 +188,48 @@ where
146 pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> { 188 pub fn poll_receive(&self, cx: &mut Context<'_>) -> Poll<T> {
147 self.channel.poll_receive(cx) 189 self.channel.poll_receive(cx)
148 } 190 }
191
192 /// Returns the maximum number of elements the channel can hold.
193 ///
194 /// See [`PriorityChannel::capacity()`]
195 pub const fn capacity(&self) -> usize {
196 self.channel.capacity()
197 }
198
199 /// Returns the free capacity of the channel.
200 ///
201 /// See [`PriorityChannel::free_capacity()`]
202 pub fn free_capacity(&self) -> usize {
203 self.channel.free_capacity()
204 }
205
206 /// Clears all elements in the channel.
207 ///
208 /// See [`PriorityChannel::clear()`]
209 pub fn clear(&self) {
210 self.channel.clear();
211 }
212
213 /// Returns the number of elements currently in the channel.
214 ///
215 /// See [`PriorityChannel::len()`]
216 pub fn len(&self) -> usize {
217 self.channel.len()
218 }
219
220 /// Returns whether the channel is empty.
221 ///
222 /// See [`PriorityChannel::is_empty()`]
223 pub fn is_empty(&self) -> bool {
224 self.channel.is_empty()
225 }
226
227 /// Returns whether the channel is full.
228 ///
229 /// See [`PriorityChannel::is_full()`]
230 pub fn is_full(&self) -> bool {
231 self.channel.is_full()
232 }
149} 233}
150 234
151impl<'ch, M, T, K, const N: usize> From<Receiver<'ch, M, T, K, N>> for DynamicReceiver<'ch, T> 235impl<'ch, M, T, K, const N: usize> From<Receiver<'ch, M, T, K, N>> for DynamicReceiver<'ch, T>