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

No longer set DEVICE_PERIPHERALS in steal() #735

Closed
wants to merge 1 commit into from

Conversation

adamgreig
Copy link
Member

We've discussed this a bit in the weekly meetings, I propose removing setting DEVICE_PERIPHERALS from steal() and leave it only in take(). This shouldn't meaningfully change the safety conditions or the use of either API, but does make stealing zero-cost. It was always possible to unsafely transmute() to obtain Peripherals without setting DEVICE_PERIPHERALS, so I'm interested if anyone can remember why this existed in the first place or if it is indeed still needed.

@adamgreig adamgreig requested a review from a team as a code owner June 13, 2023 21:30
@adamgreig
Copy link
Member Author

Closing this. We discovered why this is present: frameworks like RTIC want to take() the peripherals but know it cannot fail as they are running before any other code, so can use steal() to avoid the overhead associated with unwrap() while still setting the DEVICE_PERIPHERALS flag to ensure subsequent user code cannot safely end up with duplicate peripherals.

We should add this to the documentation ideally, but it doesn't seem worth changing this behaviour. Instead we can add the new per-peripheral steal() in #723 which needn't set DEVICE_PERIPHERALS, and that can be the zero-overhead way of unsafely creating a peripheral for new code.

@adamgreig adamgreig closed this Jun 20, 2023
@adamgreig adamgreig deleted the steal-without-setting branch June 20, 2023 19:05
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 this pull request may close these issues.

1 participant