From 621982fa16364fcfe93afdbb02fc1a45877d36c3 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 7 Jan 2023 14:23:32 +0100 Subject: [PATCH] examples/lock fixed --- examples/{lock-free.rs => lock-free.no_rs} | 9 +++++---- examples/lock.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) rename examples/{lock-free.rs => lock-free.no_rs} (83%) diff --git a/examples/lock-free.rs b/examples/lock-free.no_rs similarity index 83% rename from examples/lock-free.rs rename to examples/lock-free.no_rs index ea6ff1bf37..053307c16d 100644 --- a/examples/lock-free.rs +++ b/examples/lock-free.no_rs @@ -4,6 +4,7 @@ #![deny(warnings)] #![no_main] #![no_std] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -21,14 +22,14 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared { counter: 0 }, Local {}, init::Monotonics()) + (Shared { counter: 0 }, Local {}) } #[task(shared = [counter])] // <- same priority - fn foo(c: foo::Context) { + async fn foo(c: foo::Context) { bar::spawn().unwrap(); *c.shared.counter += 1; // <- no lock API required @@ -37,7 +38,7 @@ mod app { } #[task(shared = [counter])] // <- same priority - fn bar(c: bar::Context) { + async fn bar(c: bar::Context) { foo::spawn().unwrap(); *c.shared.counter += 1; // <- no lock API required diff --git a/examples/lock.rs b/examples/lock.rs index f1a16968ce..50b6aaaefd 100644 --- a/examples/lock.rs +++ b/examples/lock.rs @@ -4,6 +4,7 @@ #![deny(warnings)] #![no_main] #![no_std] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -20,15 +21,15 @@ mod app { struct Local {} #[init] - fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(_: init::Context) -> (Shared, Local) { foo::spawn().unwrap(); - (Shared { shared: 0 }, Local {}, init::Monotonics()) + (Shared { shared: 0 }, Local {}) } // when omitted priority is assumed to be `1` #[task(shared = [shared])] - fn foo(mut c: foo::Context) { + async fn foo(mut c: foo::Context) { hprintln!("A").unwrap(); // the lower priority task requires a critical section to access the data @@ -53,7 +54,7 @@ mod app { } #[task(priority = 2, shared = [shared])] - fn bar(mut c: bar::Context) { + async fn bar(mut c: bar::Context) { // the higher priority task does still need a critical section let shared = c.shared.shared.lock(|shared| { *shared += 1; @@ -65,7 +66,7 @@ mod app { } #[task(priority = 3)] - fn baz(_: baz::Context) { + async fn baz(_: baz::Context) { hprintln!("C").unwrap(); } }