From b65606f2d02fab273645835a102048b23c3394f7 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Mon, 3 Aug 2020 15:50:31 +0800 Subject: [PATCH] libcortex_a9/sync_channel: added reset. --- libcortex_a9/src/sync_channel.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libcortex_a9/src/sync_channel.rs b/libcortex_a9/src/sync_channel.rs index a30c315..effe4f1 100644 --- a/libcortex_a9/src/sync_channel.rs +++ b/libcortex_a9/src/sync_channel.rs @@ -87,6 +87,16 @@ impl<'a, T> Sender<'a, T> where T: Clone { content: Err(content.into()), }.await } + + /// Reset the `sync_channel`, *forget* all items in the queue. Affects both the sender and + /// receiver. + pub unsafe fn reset(&mut self) { + self.write.store(0, Ordering::Relaxed); + self.read.store(0, Ordering::Relaxed); + for v in self.list.iter() { + v.store(core::ptr::null_mut(), Ordering::Relaxed); + } + } } impl<'a, T> Receiver<'a, T> where T: Clone {