Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming lock types #611

Open
luiswirth opened this issue Feb 15, 2022 · 6 comments
Open

Naming lock types #611

luiswirth opened this issue Feb 15, 2022 · 6 comments

Comments

@luiswirth
Copy link

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.

@mattico
Copy link
Contributor

mattico commented Feb 15, 2022

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

@luiswirth
Copy link
Author

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

@AfoHT
Copy link
Contributor

AfoHT commented Feb 15, 2022

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

@luiswirth
Copy link
Author

luiswirth commented Feb 15, 2022

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

@perlindgren
Copy link
Collaborator

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

@luiswirth
Copy link
Author

luiswirth commented Feb 15, 2022

@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 to a free function like this:

That's what i used in the problem branch, which doesn't compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants