-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional backend for
critical-section
(#191)
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`.
- Loading branch information
Showing
3 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use critical_section::{set_impl, Impl, RawRestoreState}; | ||
|
||
use crate::mmio::IME; | ||
|
||
struct GbaCriticalSection; | ||
set_impl!(GbaCriticalSection); | ||
|
||
unsafe impl Impl for GbaCriticalSection { | ||
unsafe fn acquire() -> RawRestoreState { | ||
let restore = IME.read(); | ||
IME.write(false); | ||
restore | ||
} | ||
|
||
unsafe fn release(restore: RawRestoreState) { | ||
IME.write(restore); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters