rtic icon indicating copy to clipboard operation
rtic copied to clipboard

Naming lock types

Open luiswirth opened this issue 3 years ago • 6 comments

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.

luiswirth avatar Feb 15 '22 00:02 luiswirth

Does passing it using the Mutex trait work? e.g. fn do_work(counter: impl rtic::Mutex<u32>)

mattico avatar Feb 15 '22 01:02 mattico

Unfortunately no, because it's a trait object function.

luiswirth avatar Feb 15 '22 02:02 luiswirth

@LU15W1R7H Could you provide some MWE showcasing the issue you have?

AfoHT avatar Feb 15 '22 18:02 AfoHT

@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.

luiswirth avatar Feb 15 '22 19:02 luiswirth

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 avatar Feb 15 '22 20:02 perlindgren

@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.

luiswirth avatar Feb 15 '22 20:02 luiswirth