mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
destruction problem
This commit is contained in:
parent
9d92f2ab70
commit
d6cffba14d
2 changed files with 65 additions and 0 deletions
60
examples/lockall_destruct.rs
Normal file
60
examples/lockall_destruct.rs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
//! examples/lockall.rs
|
||||||
|
|
||||||
|
#![deny(unsafe_code)]
|
||||||
|
#![deny(warnings)]
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA, GPIOB, GPIOC])]
|
||||||
|
mod app {
|
||||||
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {
|
||||||
|
a: u32,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
|
(Shared { a: 1, b: 2 }, Local {}, init::Monotonics())
|
||||||
|
}
|
||||||
|
|
||||||
|
// when omitted priority is assumed to be `1`
|
||||||
|
#[task(shared = [a, b])]
|
||||||
|
fn foo(mut c: foo::Context) {
|
||||||
|
c.shared.lock(|Shared { a, b }| {
|
||||||
|
hprintln!("foo: a = {}, b = {}", a, b).ok();
|
||||||
|
*a += 1;
|
||||||
|
bar::spawn().unwrap();
|
||||||
|
baz::spawn().unwrap();
|
||||||
|
hprintln!("still in foo::lock").ok();
|
||||||
|
});
|
||||||
|
hprintln!("still in foo").ok();
|
||||||
|
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(priority = 2, shared = [a])]
|
||||||
|
fn bar(mut c: bar::Context) {
|
||||||
|
// the higher priority task does still need a critical section
|
||||||
|
let a = c.shared.lock(|s| {
|
||||||
|
*s.a += 1;
|
||||||
|
// *s.b += 1; `b` not accessible
|
||||||
|
*s.a
|
||||||
|
});
|
||||||
|
|
||||||
|
hprintln!("bar: a = {}", a).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(priority = 3)]
|
||||||
|
fn baz(_: baz::Context) {
|
||||||
|
hprintln!("baz").unwrap();
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,6 +89,7 @@ pub fn codegen(
|
||||||
|
|
||||||
if ctxt.has_shared_resources(app) {
|
if ctxt.has_shared_resources(app) {
|
||||||
let ident = util::shared_resources_ident(ctxt, app);
|
let ident = util::shared_resources_ident(ctxt, app);
|
||||||
|
let ident_mut = util::shared_resources_ident_mut(ctxt, app);
|
||||||
let lt = if shared_resources_tick {
|
let lt = if shared_resources_tick {
|
||||||
lt = Some(quote!('a));
|
lt = Some(quote!('a));
|
||||||
Some(quote!('a))
|
Some(quote!('a))
|
||||||
|
@ -99,6 +100,10 @@ pub fn codegen(
|
||||||
module_items.push(quote!(
|
module_items.push(quote!(
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use super::#ident as SharedResources;
|
pub use super::#ident as SharedResources;
|
||||||
|
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use super::#ident_mut as Shared;
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
|
|
Loading…
Reference in a new issue