aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuntc <[email protected]>2021-07-14 12:17:27 +1000
committerhuntc <[email protected]>2021-07-15 12:31:53 +1000
commita247fa4f2c90993bad3501349029c52e7bb06f9d (patch)
tree71122cde94ca62fcbabce2e3a9162c90d4d710ff
parent7c723d2bfd3e8b8cf6fa289b822a254180601528 (diff)
Explicitly drop non consumed items
-rw-r--r--embassy/src/util/mpsc.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/embassy/src/util/mpsc.rs b/embassy/src/util/mpsc.rs
index f049b6217..b64d81c89 100644
--- a/embassy/src/util/mpsc.rs
+++ b/embassy/src/util/mpsc.rs
@@ -41,6 +41,7 @@ use core::cell::UnsafeCell;
41use core::fmt; 41use core::fmt;
42use core::mem::MaybeUninit; 42use core::mem::MaybeUninit;
43use core::pin::Pin; 43use core::pin::Pin;
44use core::ptr;
44use core::task::Context; 45use core::task::Context;
45use core::task::Poll; 46use core::task::Poll;
46use core::task::Waker; 47use core::task::Waker;
@@ -416,6 +417,16 @@ impl<T, const N: usize> ChannelState<T, N> {
416 } 417 }
417} 418}
418 419
420impl<T, const N: usize> Drop for ChannelState<T, N> {
421 fn drop(&mut self) {
422 while self.read_pos != self.write_pos || self.full {
423 self.full = false;
424 unsafe { ptr::drop_in_place(self.buf[self.read_pos].as_mut_ptr()) };
425 self.read_pos = (self.read_pos + 1) % N;
426 }
427 }
428}
429
419/// A a bounded mpsc channel for communicating between asynchronous tasks 430/// A a bounded mpsc channel for communicating between asynchronous tasks
420/// with backpressure. 431/// with backpressure.
421/// 432///