forked from M-Labs/zynq-rs
1
0
Fork 0

libcortex_a9/sync_channel: added drop_elements function.

This commit is contained in:
pca006132 2020-08-05 15:29:28 +08:00
parent a36a82d86d
commit 3958953ceb
2 changed files with 14 additions and 0 deletions

View File

@ -200,6 +200,9 @@ pub fn main_core0() {
println!("{} -> {}", i, j); println!("{} -> {}", i, j);
} }
}); });
unsafe {
core1_req.drop_elements();
}
let eth = zynq::eth::Eth::default(HWADDR.clone()); let eth = zynq::eth::Eth::default(HWADDR.clone());
println!("Eth on"); println!("Eth on");

View File

@ -86,6 +86,17 @@ impl<'a, T> Sender<'a, T> where T: Clone {
}.await }.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 /// Reset the `sync_channel`, *forget* all items in the queue. Affects both the sender and
/// receiver. /// receiver.
pub unsafe fn reset(&mut self) { pub unsafe fn reset(&mut self) {