mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +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 {
|
||||
internal: UnsafeCell::new(val),
|
||||
state: UnsafeCell::new(MutexState::Unlocked),
|
||||
|
@ -362,14 +362,14 @@ pub struct MutexRef<'a, T> {
|
|||
|
||||
impl<'a, T> Drop for MutexRef<'a, T> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let state = &mut *self.state.get();
|
||||
let prev_state = *state;
|
||||
*state = MutexState::Unlocked;
|
||||
match prev_state {
|
||||
MutexState::Locked(b) => INTERRUPTS_ENABLED.set(b as u16),
|
||||
MutexState::Unlocked => {}
|
||||
}
|
||||
let state = unsafe { &mut *self.state.get() };
|
||||
|
||||
let prev_state = *state;
|
||||
*state = MutexState::Unlocked;
|
||||
|
||||
match prev_state {
|
||||
MutexState::Locked(b) => INTERRUPTS_ENABLED.set(b as u16),
|
||||
MutexState::Unlocked => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue