diff options
| author | huntc <[email protected]> | 2021-07-14 12:17:27 +1000 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-07-15 12:31:53 +1000 |
| commit | a247fa4f2c90993bad3501349029c52e7bb06f9d (patch) | |
| tree | 71122cde94ca62fcbabce2e3a9162c90d4d710ff | |
| parent | 7c723d2bfd3e8b8cf6fa289b822a254180601528 (diff) | |
Explicitly drop non consumed items
| -rw-r--r-- | embassy/src/util/mpsc.rs | 11 |
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; | |||
| 41 | use core::fmt; | 41 | use core::fmt; |
| 42 | use core::mem::MaybeUninit; | 42 | use core::mem::MaybeUninit; |
| 43 | use core::pin::Pin; | 43 | use core::pin::Pin; |
| 44 | use core::ptr; | ||
| 44 | use core::task::Context; | 45 | use core::task::Context; |
| 45 | use core::task::Poll; | 46 | use core::task::Poll; |
| 46 | use core::task::Waker; | 47 | use core::task::Waker; |
| @@ -416,6 +417,16 @@ impl<T, const N: usize> ChannelState<T, N> { | |||
| 416 | } | 417 | } |
| 417 | } | 418 | } |
| 418 | 419 | ||
| 420 | impl<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 | /// |
