diff options
author | 2020-10-23 20:52:58 +0000 | |
---|---|---|
committer | 2020-10-23 20:52:58 +0000 | |
commit | bbcae14e37c5f4ab5701b2a688bee52bfa7aaa1b (patch) | |
tree | c70a80e9bcacb54838f09141bd1d2b27e844760f /examples/resource-user-struct.rs | |
parent | b3aa9e99a975eca637582f31de20fe11ae8f7d64 (diff) | |
parent | e8eca4be37a2fe1af25b203ace5e99b31fcc3972 (diff) | |
download | rtic-bbcae14e37c5f4ab5701b2a688bee52bfa7aaa1b.tar.gz rtic-bbcae14e37c5f4ab5701b2a688bee52bfa7aaa1b.tar.zst rtic-bbcae14e37c5f4ab5701b2a688bee52bfa7aaa1b.zip |
Merge #399
399: Now all locks are symmetric r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'examples/resource-user-struct.rs')
-rw-r--r-- | examples/resource-user-struct.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/resource-user-struct.rs b/examples/resource-user-struct.rs index ca4ca2af..a550bb2a 100644 --- a/examples/resource-user-struct.rs +++ b/examples/resource-user-struct.rs @@ -47,18 +47,23 @@ mod app { // `shared` can be accessed from this context #[task(binds = UART0, resources = [shared])] - fn uart0(cx: uart0::Context) { - let shared: &mut u32 = cx.resources.shared; - *shared += 1; + fn uart0(mut cx: uart0::Context) { + let shared = cx.resources.shared.lock(|shared| { + *shared += 1; + *shared + }); hprintln!("UART0: shared = {}", shared).unwrap(); } // `shared` can be accessed from this context #[task(binds = UART1, resources = [shared])] - fn uart1(cx: uart1::Context) { - *cx.resources.shared += 1; + fn uart1(mut cx: uart1::Context) { + let shared = cx.resources.shared.lock(|shared| { + *shared += 1; + *shared + }); - hprintln!("UART1: shared = {}", cx.resources.shared).unwrap(); + hprintln!("UART1: shared = {}", shared).unwrap(); } } |