Skip to content

Commit f464616

Browse files
committed
rtic-sync: debug_assert and explicitly drop(item).
1 parent fa473b8 commit f464616

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

rtic-sync/src/channel.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ impl<T, const N: usize> Channel<T, N> {
104104

105105
/// Clear any remaining items from this `Channel`.
106106
pub fn clear(&mut self) {
107-
for _ in self.queued_items() {}
107+
for item in self.queued_items() {
108+
drop(item);
109+
}
108110
}
109111

110112
/// Return an iterator over the still-queued items, removing them
@@ -131,7 +133,7 @@ impl<T, const N: usize> Channel<T, N> {
131133
// NOTE: do not `return_free_slot`, as we have mutable
132134
// access to this `Channel` and no `Receiver` or `Sender`
133135
// exist.
134-
assert!(!self.inner.freeq.as_mut().is_full());
136+
debug_assert!(!self.inner.freeq.as_mut().is_full());
135137
unsafe {
136138
// SAFETY: `freeq` is not ful.
137139
self.inner.freeq.as_mut().push_back_unchecked(slot);
@@ -163,11 +165,10 @@ impl<T, const N: usize> Channel<T, N> {
163165

164166
// Fill free queue
165167
for idx in 0..N as u8 {
166-
// NOTE(assert): `split`-ing does not put `freeq` into a known-empty
167-
// state, so `debug_assert` is not good enough.
168-
assert!(!freeq.is_full());
168+
debug_assert!(!freeq.is_full());
169169

170-
// SAFETY: This safe as the loop goes from 0 to the capacity of the underlying queue.
170+
// SAFETY: This safe as the loop goes from 0 to the capacity of the underlying queue,
171+
// and the queue is cleared beforehand.
171172
unsafe {
172173
freeq.push_back_unchecked(idx);
173174
}
@@ -207,7 +208,7 @@ impl<T, const N: usize> Channel<T, N> {
207208
// SAFETY: `self.freeq` is not called recursively.
208209
unsafe {
209210
self.freeq(cs, |freeq| {
210-
assert!(!freeq.is_full());
211+
debug_assert!(!freeq.is_full());
211212
// SAFETY: `freeq` is not full.
212213
freeq.push_back_unchecked(slot);
213214
});
@@ -385,7 +386,7 @@ impl<T, const N: usize> Sender<'_, T, N> {
385386
// SAFETY: `self.0.readyq` is not called recursively.
386387
unsafe {
387388
self.0.readyq(cs, |readyq| {
388-
assert!(!readyq.is_full());
389+
debug_assert!(!readyq.is_full());
389390
// SAFETY: ready is not full.
390391
readyq.push_back_unchecked(idx);
391392
});
@@ -519,7 +520,7 @@ impl<T, const N: usize> Sender<'_, T, N> {
519520
// SAFETY: `self.0.freeq` is not called recursively.
520521
unsafe {
521522
self.0.freeq(cs, |freeq| {
522-
assert!(!freeq.is_empty());
523+
debug_assert!(!freeq.is_empty());
523524
// SAFETY: `freeq` is non-empty
524525
let slot = freeq.pop_back_unchecked();
525526
Poll::Ready(Ok(slot))

0 commit comments

Comments
 (0)