mirror of
https://github.com/italicsjenga/agb.git
synced 2025-02-23 22:58:18 +11:00
ensure mutex is unlocked before locking
This commit is contained in:
parent
a9aad11dd7
commit
1318e7eca4
1 changed files with 6 additions and 1 deletions
|
@ -261,7 +261,7 @@ fn test_vblank_interrupt_handler(gba: &mut crate::Gba) {
|
|||
);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
enum MutexState {
|
||||
Locked,
|
||||
Unlocked(bool),
|
||||
|
@ -279,6 +279,11 @@ impl<T> Mutex<T> {
|
|||
pub fn lock(&self) -> MutexRef<T> {
|
||||
let state = INTERRUPTS_ENABLED.get();
|
||||
INTERRUPTS_ENABLED.set(0);
|
||||
assert_eq!(
|
||||
unsafe { *self.state.get() },
|
||||
MutexState::Locked,
|
||||
"mutex must be unlocked to be able to lock it"
|
||||
);
|
||||
unsafe { *self.state.get() = MutexState::Unlocked(state != 0) };
|
||||
MutexRef {
|
||||
internal: &self.internal,
|
||||
|
|
Loading…
Add table
Reference in a new issue