From 6fd6f429fe5dc789a049b81d80dc240fcca001d4 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 9 Apr 2020 02:56:54 +0200 Subject: [PATCH] libcortex_a9: impl Iterator for sync_channel::Receiver --- experiments/src/main.rs | 10 +++------- libcortex_a9/src/sync_channel.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index dd18d1d..189fa5a 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -135,11 +135,9 @@ pub fn main_core0() { let core1 = boot::Core1::start(core1_stack); - let (tx, mut rx) = sync_channel(1000); + let (tx, mut rx) = sync_channel(10); *SHARED.lock() = Some(tx); - let mut i = 0u32; - loop { - let r = rx.recv(); + for (i, r) in rx.enumerate() { // println!("Recvd {}", r); if i != *r { println!("Expected {}, received {}", i, r); @@ -147,8 +145,6 @@ pub fn main_core0() { if i % 100000 == 0 { println!("{} Ok", i); } - - i += 1; } core1.reset(); @@ -253,7 +249,7 @@ pub fn main_core0() { }); } -static SHARED: Mutex>> = Mutex::new(None); +static SHARED: Mutex>> = Mutex::new(None); static DONE: Mutex = Mutex::new(false); #[no_mangle] diff --git a/libcortex_a9/src/sync_channel.rs b/libcortex_a9/src/sync_channel.rs index c6ac8fc..7b4e830 100644 --- a/libcortex_a9/src/sync_channel.rs +++ b/libcortex_a9/src/sync_channel.rs @@ -102,3 +102,11 @@ impl Receiver { } } } + +impl Iterator for Receiver { + type Item = Box; + + fn next(&mut self) -> Option { + Some(self.recv()) + } +}