rtic
rtic copied to clipboard
Naming lock types
I want to pass a shared resource to a function, but I'm unable to name the lock.
The path app::shared_resources::resource_that_needs_to_be_locked
is not accessible, as app::shared_resources
is private.
Also the generated name resource_that_needs_to_be_locked
is inconvenient.
Does passing it using the Mutex
trait work? e.g. fn do_work(counter: impl rtic::Mutex<u32>)
Unfortunately no, because it's a trait object function.
@LU15W1R7H Could you provide some MWE showcasing the issue you have?
@AfoHT Sure! I created a git repository with two branches, one showing the problem and the other demonstrating the solution!
The problem branch doesn't compile. The fix branch compiles because it uses #612.
Is it when you want to embed the function into a trait that the problem occurs. I mean in general you can pass a Mutex<T>
to a free function like this:
https://github.com/rtic-rs/cortex-m-rtic/blob/master/examples/generics.rs
@perlindgren
Is it when you want to embed the function into a trait that the problem occurs.
Yes, it's about trait object safety!
I mean in general you can pass a Mutex<T> to a free function like this:
That's what i used in the problem branch, which doesn't compile.