diff --git a/qemu/examples/spawn3.rs b/qemu/examples/spawn3.rs index 82ca0b230c7a10cd9bd0f41b7806bc0882bd60e5..54ea4daf9bd1f72dafefe3fd570415fcd7d97ea0 100644 --- a/qemu/examples/spawn3.rs +++ b/qemu/examples/spawn3.rs @@ -41,7 +41,7 @@ mod app { // BEGIN BOILERPLATE type F = impl Future + 'static; fn create(c: foo::Context<'static>) -> F { - task(c) + _foo(c) } static mut TASK: Task<F> = Task::new(); @@ -58,19 +58,6 @@ mod app { }); } // END BOILERPLATE - - async fn task(mut c: foo::Context<'static>) { - loop { - c.resources.counter.lock(|c| { - *c += 1; - if *c > 10 { - debug::exit(debug::EXIT_SUCCESS); - } - hprintln!("foo {}", *c).ok(); - }); - please_yield().await; - } - } } #[task(resources = [counter])] @@ -78,7 +65,7 @@ mod app { // BEGIN BOILERPLATE type F = impl Future + 'static; fn create(c: bar::Context<'static>) -> F { - task(c) + _bar(c) } static mut TASK: Task<F> = Task::new(); @@ -95,17 +82,6 @@ mod app { }); } // END BOILERPLATE - - async fn task(mut c: bar::Context<'static>) { - loop { - c.resources.counter.lock(|c| { - *c += 1; - hprintln!("bar {}", *c).ok(); - }); - rt_task::spawn(); - please_yield().await; - } - } } #[task(resources = [counter], priority = 2)] @@ -122,6 +98,32 @@ mod app { } } +async fn _foo(mut c: foo::Context<'static>) { + use rtic::Mutex; + loop { + c.resources.counter.lock(|c| { + *c += 1; + if *c > 10 { + debug::exit(debug::EXIT_SUCCESS); + } + hprintln!("foo {}", *c).ok(); + }); + please_yield().await; + } +} + +async fn _bar(mut c: bar::Context<'static>) { + use rtic::Mutex; + loop { + c.resources.counter.lock(|c| { + *c += 1; + hprintln!("bar {}", *c).ok(); + }); + rt_task::spawn(); + please_yield().await; + } +} + //============= // Waker