mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
parent
2f3b5cba80
commit
a7ed040799
1 changed files with 43 additions and 0 deletions
|
@ -201,6 +201,49 @@ fn bar(cx: bar::Context) {
|
||||||
|
|
||||||
Note that the performance does not change thanks to LLVM's optimizations which optimizes away unnecessary locks.
|
Note that the performance does not change thanks to LLVM's optimizations which optimizes away unnecessary locks.
|
||||||
|
|
||||||
|
## Lock-free resource access
|
||||||
|
|
||||||
|
In RTIC 0.5 resources shared by tasks running at the same priority could be accessed *without* the `lock` API.
|
||||||
|
This is still possible in 0.6: the `#[shared]` resource must be annotated with the field-level `#[lock_free]` attribute.
|
||||||
|
|
||||||
|
v0.5 code:
|
||||||
|
|
||||||
|
``` rust
|
||||||
|
struct Resources {
|
||||||
|
counter: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(resources = [counter])]
|
||||||
|
fn a(cx: a::Context) {
|
||||||
|
*cx.resources.counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(resources = [counter])]
|
||||||
|
fn b(cx: b::Context) {
|
||||||
|
*cx.resources.counter += 1;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
v0.6 code:
|
||||||
|
|
||||||
|
``` rust
|
||||||
|
#[shared]
|
||||||
|
struct Shared {
|
||||||
|
#[lock_free]
|
||||||
|
counter: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(shared = [counter])]
|
||||||
|
fn a(cx: a::Context) {
|
||||||
|
*cx.shared.counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(shared = [counter])]
|
||||||
|
fn b(cx: b::Context) {
|
||||||
|
*cx.shared.counter += 1;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## no `static mut` transform
|
## no `static mut` transform
|
||||||
|
|
||||||
`static mut` variables are no longer transformed to safe `&'static mut` references.
|
`static mut` variables are no longer transformed to safe `&'static mut` references.
|
||||||
|
|
Loading…
Reference in a new issue