mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-12 01:51:34 +11:00
Make mutex new constant and reduce unsafe block size
This commit is contained in:
parent
1b40fe2b03
commit
a500c9dbb1
|
@ -347,7 +347,7 @@ impl<T> Mutex<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(val: T) -> Self {
|
pub const fn new(val: T) -> Self {
|
||||||
Mutex {
|
Mutex {
|
||||||
internal: UnsafeCell::new(val),
|
internal: UnsafeCell::new(val),
|
||||||
state: UnsafeCell::new(MutexState::Unlocked),
|
state: UnsafeCell::new(MutexState::Unlocked),
|
||||||
|
@ -362,17 +362,17 @@ pub struct MutexRef<'a, T> {
|
||||||
|
|
||||||
impl<'a, T> Drop for MutexRef<'a, T> {
|
impl<'a, T> Drop for MutexRef<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
let state = unsafe { &mut *self.state.get() };
|
||||||
let state = &mut *self.state.get();
|
|
||||||
let prev_state = *state;
|
let prev_state = *state;
|
||||||
*state = MutexState::Unlocked;
|
*state = MutexState::Unlocked;
|
||||||
|
|
||||||
match prev_state {
|
match prev_state {
|
||||||
MutexState::Locked(b) => INTERRUPTS_ENABLED.set(b as u16),
|
MutexState::Locked(b) => INTERRUPTS_ENABLED.set(b as u16),
|
||||||
MutexState::Unlocked => {}
|
MutexState::Unlocked => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> Deref for MutexRef<'a, T> {
|
impl<'a, T> Deref for MutexRef<'a, T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
Loading…
Reference in a new issue