-
Notifications
You must be signed in to change notification settings - Fork 216
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
INIT constrains which types can be used to implement RawMutex #400
Comments
Sorry, the rp2040 Spinlock is not the best example, I had an incorrect assumption about how that API works. This may still be worth considering, I still think it would be good to allow raw mutexes that can't provide an INIT. But right now I don't have a good example where that is important. |
Duplicate of #117 The problem is that this would prevent |
If we have a |
I suppose that could work. I would be happy to accept a PR that split const initialization into a separate trait. You'll need to add a separate constructor method to build a |
That already exists as |
Mutexes that don't support const-initialization should be pretty rare, and should be exposed through a |
I also have a use for the However, to my surprise, I've found that the following works, provided that const INIT: Self = unimplemented!(); If using |
I'm happy to accept a PR to add |
I think the lock-api crate has a lot of potential in embedded, but right now it has a limitation that implementations of
RawMutex
must provide anINIT
constant value.Some MCUs have their own hardware synchronization primitives, but these are unique resources / peripherals that must be owned in order to use them, and ownership is generally handed to the application through a PAC, or "peripheral access crate". They naturally cannot be obtained in a const context, and they also cannot be cloned since they rely on ownership being unique.
Peripherals likerp2040_hal::sio::Spinlock
would be perfect for implementingRawMutex
, but it's impossible to create a value forINIT
without some kind of wrapper type that provides an illegal state.INIT
only seems necessary forMutex::new
and similar constructors that do not explicitly accept aRawMutex
parameter, so I think it would make sense to move it into a separate trait. The raw mutex can still be used with theconst_new
constructors; it would operate similar to constructors that accept an allocator argument (Box::new_in
etc.).The text was updated successfully, but these errors were encountered: