Skip to content

use const steal#641

Open
xoviat wants to merge 2 commits intorust-embedded:masterfrom
xoviat:const-steal
Open

use const steal#641
xoviat wants to merge 2 commits intorust-embedded:masterfrom
xoviat:const-steal

Conversation

@xoviat
Copy link
Copy Markdown

@xoviat xoviat commented Apr 10, 2026

The steal function is already unsafe, so there's no need to mark taken to make sure that someone else doesn't take it.

@wt
Copy link
Copy Markdown
Contributor

wt commented Apr 11, 2026

Doesn't the steal function need to mark the peripherals taken so that take will work as intended? Otherwise, using take after steal will get the peripherals when we don't know that there is exclusive access via take.

@xoviat
Copy link
Copy Markdown
Author

xoviat commented Apr 11, 2026

Otherwise, using take after steal will get the peripherals when we don't know that there is exclusive access via take.

Yes, and this is the correct result. steal is already unsafe, therefore, if you call it, you cannot guarantee that other code somewhere else does not have a duplicate instance of the peripherals. It is therefore your job to make sure that this isn't a problem.

However, suppose you are writing unsafe code and you need to call cortex-m methods, while still allowing safe code to take them. There is no way to do so without using a transmute, because calling steal will impact take.

@xoviat xoviat closed this Apr 11, 2026
@xoviat xoviat reopened this Apr 11, 2026
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.

2 participants