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

Add optional backend for critical-section #191

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

ids1024
Copy link
Contributor

@ids1024 ids1024 commented Feb 4, 2024

This is similar to the single-threaded bare metal implementations in cortex-m and riscv.

In theory there could be a race condition in acquire if an interrupt occurs between the read and write, and the interrupt disables IME. But it's probably not sensible to have an interrupt disable interrupts, so I don't think it's necessarily to complicate things with inline assembly using swp.

This is similar to the single-threaded bare metal implementations in
`cortex-m` and `riscv`.

In theory there could be a race condition in `acquire` if an interrupt
occurs between the `read` and `write`, and the interrupt disables `IME`.
But it's probably not sensible to have an interrupt disable interrupts,
so I don't think it's necessarily to complicate things with inline
assembly using `swp`.
@Lokathor
Copy link
Member

Lokathor commented Feb 5, 2024

I don't object to this, but I also have never heard of this crate before. I guess this is just a commonly used utility crate?

Interrupts actually happen with interrupts disabled (in the program status register) by default, and then our asm interrupt handler re-enabled interrupts as part of switching to System mode for the Rust interrupt handler to run.

I coulda sworn we had a utility fn to cleanly do a swp instruction, but I don't see it anywhere, if we did have it.

@ids1024
Copy link
Contributor Author

ids1024 commented Feb 5, 2024

Yeah, it seems to be commonly provided by basically all the hal crates (or one of their dependencies, anyway).

It sounds useful for creating portable abstractions, and in particular I see embassy-executor and embassy-time seem to use it, so presumably a backend like this would be needed to use those with gba.

Looking at git log -G swp, there were a couple swp related functions before bf853b7.

@Lokathor Lokathor merged commit cd4f2db into rust-console:main Mar 4, 2024
1 check passed
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