From 3958953ceb56aa81e33fb4f3d19ab7ee4c06d1ba Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 5 Aug 2020 15:29:28 +0800 Subject: [PATCH] libcortex_a9/sync_channel: added drop_elements function. --- experiments/src/main.rs | 3 +++ libcortex_a9/src/sync_channel.rs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index d9e13f3..6f5d132 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -200,6 +200,9 @@ pub fn main_core0() { println!("{} -> {}", i, j); } }); + unsafe { + core1_req.drop_elements(); + } let eth = zynq::eth::Eth::default(HWADDR.clone()); println!("Eth on"); diff --git a/libcortex_a9/src/sync_channel.rs b/libcortex_a9/src/sync_channel.rs index d8ef51f..139c8fb 100644 --- a/libcortex_a9/src/sync_channel.rs +++ b/libcortex_a9/src/sync_channel.rs @@ -86,6 +86,17 @@ impl<'a, T> Sender<'a, T> where T: Clone { }.await } + /// free all items in the queue. It is the user's responsibility to + /// ensure no reader is trying to copy the data. + pub unsafe fn drop_elements(&mut self) { + for v in self.list.iter() { + let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed); + if !original.is_null() { + drop_in_place(original); + } + } + } + /// Reset the `sync_channel`, *forget* all items in the queue. Affects both the sender and /// receiver. pub unsafe fn reset(&mut self) {