mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Start async tasks at lowest priority
This commit is contained in:
parent
d18955a134
commit
48e5acf294
8 changed files with 19 additions and 12 deletions
|
@ -289,11 +289,13 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
|
||||||
// Handle comma: ,
|
// Handle comma: ,
|
||||||
let _: Token![,] = content.parse()?;
|
let _: Token![,] = content.parse()?;
|
||||||
}
|
}
|
||||||
let priority = priority.unwrap_or(1);
|
|
||||||
let shared_resources = shared_resources.unwrap_or_default();
|
let shared_resources = shared_resources.unwrap_or_default();
|
||||||
let local_resources = local_resources.unwrap_or_default();
|
let local_resources = local_resources.unwrap_or_default();
|
||||||
|
|
||||||
Ok(if let Some(binds) = binds {
|
Ok(if let Some(binds) = binds {
|
||||||
|
// Hardware tasks can't run at anything lower than 1
|
||||||
|
let priority = priority.unwrap_or(1);
|
||||||
|
|
||||||
if priority == 0 {
|
if priority == 0 {
|
||||||
return Err(parse::Error::new(
|
return Err(parse::Error::new(
|
||||||
prio_span.unwrap(),
|
prio_span.unwrap(),
|
||||||
|
@ -308,6 +310,9 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
|
||||||
local_resources,
|
local_resources,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
// Software tasks start at idle priority
|
||||||
|
let priority = priority.unwrap_or(0);
|
||||||
|
|
||||||
Either::Right(SoftwareTaskArgs {
|
Either::Right(SoftwareTaskArgs {
|
||||||
priority,
|
priority,
|
||||||
shared_resources,
|
shared_resources,
|
||||||
|
|
|
@ -13,6 +13,8 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Make async task priorities start at 0, instead of 1, to always start at the lowest priority
|
||||||
|
|
||||||
## [v1.1.4] - 2023-02-26
|
## [v1.1.4] - 2023-02-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -53,13 +53,13 @@ mod app {
|
||||||
hprintln!("hello from hw");
|
hprintln!("hello from hw");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [a])]
|
#[task(shared = [a], priority = 1)]
|
||||||
async fn async_task(cx: async_task::Context) {
|
async fn async_task(cx: async_task::Context) {
|
||||||
let async_task::SharedResources { a: _, .. } = cx.shared;
|
let async_task::SharedResources { a: _, .. } = cx.shared;
|
||||||
hprintln!("hello from async");
|
hprintln!("hello from async");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task(priority = 1)]
|
||||||
async fn async_task_args(_cx: async_task_args::Context, a: u32, b: i32) {
|
async fn async_task_args(_cx: async_task_args::Context, a: u32, b: i32) {
|
||||||
hprintln!("hello from async with args a: {}, b: {}", a, b);
|
hprintln!("hello from async with args a: {}, b: {}", a, b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `local_to_foo` can only be accessed from this context
|
// `local_to_foo` can only be accessed from this context
|
||||||
#[task(local = [local_to_foo])]
|
#[task(local = [local_to_foo], priority = 1)]
|
||||||
async fn foo(cx: foo::Context) {
|
async fn foo(cx: foo::Context) {
|
||||||
let local_to_foo = cx.local.local_to_foo;
|
let local_to_foo = cx.local.local_to_foo;
|
||||||
*local_to_foo += 1;
|
*local_to_foo += 1;
|
||||||
|
@ -74,7 +74,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `local_to_bar` can only be accessed from this context
|
// `local_to_bar` can only be accessed from this context
|
||||||
#[task(local = [local_to_bar])]
|
#[task(local = [local_to_bar], priority = 1)]
|
||||||
async fn bar(cx: bar::Context) {
|
async fn bar(cx: bar::Context) {
|
||||||
let local_to_bar = cx.local.local_to_bar;
|
let local_to_bar = cx.local.local_to_bar;
|
||||||
*local_to_bar += 1;
|
*local_to_bar += 1;
|
||||||
|
|
|
@ -38,7 +38,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct destructure
|
// Direct destructure
|
||||||
#[task(shared = [&a, &b, &c])]
|
#[task(shared = [&a, &b, &c], priority = 1)]
|
||||||
async fn foo(cx: foo::Context) {
|
async fn foo(cx: foo::Context) {
|
||||||
let a = cx.shared.a;
|
let a = cx.shared.a;
|
||||||
let b = cx.shared.b;
|
let b = cx.shared.b;
|
||||||
|
@ -48,7 +48,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-structure-ing syntax
|
// De-structure-ing syntax
|
||||||
#[task(shared = [&a, &b, &c])]
|
#[task(shared = [&a, &b, &c], priority = 1)]
|
||||||
async fn bar(cx: bar::Context) {
|
async fn bar(cx: bar::Context) {
|
||||||
let bar::SharedResources { a, b, c, .. } = cx.shared;
|
let bar::SharedResources { a, b, c, .. } = cx.shared;
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `local_to_foo` can only be accessed from this context
|
// `local_to_foo` can only be accessed from this context
|
||||||
#[task(local = [local_to_foo])]
|
#[task(local = [local_to_foo], priority = 1)]
|
||||||
async fn foo(cx: foo::Context) {
|
async fn foo(cx: foo::Context) {
|
||||||
let local_to_foo = cx.local.local_to_foo;
|
let local_to_foo = cx.local.local_to_foo;
|
||||||
*local_to_foo += 1;
|
*local_to_foo += 1;
|
||||||
|
@ -74,7 +74,7 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `local_to_bar` can only be accessed from this context
|
// `local_to_bar` can only be accessed from this context
|
||||||
#[task(local = [local_to_bar])]
|
#[task(local = [local_to_bar], priority = 1)]
|
||||||
async fn bar(cx: bar::Context) {
|
async fn bar(cx: bar::Context) {
|
||||||
let local_to_bar = cx.local.local_to_bar;
|
let local_to_bar = cx.local.local_to_bar;
|
||||||
*local_to_bar += 1;
|
*local_to_bar += 1;
|
||||||
|
|
|
@ -54,13 +54,13 @@ mod app {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [&shared])]
|
#[task(shared = [&shared], priority = 1)]
|
||||||
async fn foo(c: foo::Context) {
|
async fn foo(c: foo::Context) {
|
||||||
let shared: &NotSync = c.shared.shared;
|
let shared: &NotSync = c.shared.shared;
|
||||||
hprintln!("foo a {}", shared.data);
|
hprintln!("foo a {}", shared.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [&shared])]
|
#[task(shared = [&shared], priority = 1)]
|
||||||
async fn bar(c: bar::Context) {
|
async fn bar(c: bar::Context) {
|
||||||
let shared: &NotSync = c.shared.shared;
|
let shared: &NotSync = c.shared.shared;
|
||||||
hprintln!("bar a {}", shared.data);
|
hprintln!("bar a {}", shared.data);
|
||||||
|
|
|
@ -51,7 +51,7 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [p, state: u32 = 0])]
|
#[task(local = [p, state: u32 = 0], priority = 1)]
|
||||||
async fn foo(c: foo::Context) {
|
async fn foo(c: foo::Context) {
|
||||||
*c.local.state += 1;
|
*c.local.state += 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue