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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ track_caller = []
voladdress = "1.3.0"
bitfrob = "1"
bracer = "0.1.2"
critical-section = { version = "1.1.2", features = ["restore-state-bool"], optional = true }

[profile.dev]
opt-level = 3
Expand Down
18 changes: 18 additions & 0 deletions src/critical_section.rs
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);
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ mod macros;
pub mod asm_runtime;
pub mod bios;
pub mod builtin_art;
#[cfg(feature = "critical-section")]
mod critical_section;
pub mod dma;
pub mod fixed;
pub mod gba_cell;
Expand Down
Loading