Make mutex new constant and reduce unsafe block size

This commit is contained in:
Gwilym Kuiper 2021-08-16 21:02:03 +01:00
parent 1b40fe2b03
commit a500c9dbb1

View file

@ -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 => {}
}
}
}