cargo fmt

This commit is contained in:
Yu Chen 2022-05-14 22:53:45 +08:00
parent babcd45c9c
commit 4e2436f757
11 changed files with 47 additions and 38 deletions

View file

@ -1,5 +1,8 @@
use crate::sync::{Mutex, UPIntrFreeCell};
use crate::task::{add_task, block_current_task, block_current_and_run_next, current_task, TaskControlBlock, TaskContext};
use crate::task::{
add_task, block_current_and_run_next, block_current_task, current_task, TaskContext,
TaskControlBlock,
};
use alloc::{collections::VecDeque, sync::Arc};
pub struct Condvar {

View file

@ -1,7 +1,7 @@
use core::cell::{RefCell, RefMut, UnsafeCell};
use core::ops::{Deref, DerefMut};
use riscv::register::sstatus;
use lazy_static::*;
use riscv::register::sstatus;
/*
/// Wrap a static data structure inside it so that we are
@ -56,9 +56,8 @@ pub struct IntrMaskingInfo {
}
lazy_static! {
static ref INTR_MASKING_INFO: UPSafeCellRaw<IntrMaskingInfo> = unsafe {
UPSafeCellRaw::new(IntrMaskingInfo::new())
};
static ref INTR_MASKING_INFO: UPSafeCellRaw<IntrMaskingInfo> =
unsafe { UPSafeCellRaw::new(IntrMaskingInfo::new()) };
}
impl IntrMaskingInfo {
@ -71,7 +70,9 @@ impl IntrMaskingInfo {
pub fn enter(&mut self) {
let sie = sstatus::read().sie();
unsafe { sstatus::clear_sie(); }
unsafe {
sstatus::clear_sie();
}
if self.nested_level == 0 {
self.sie_before_masking = sie;
}
@ -81,7 +82,9 @@ impl IntrMaskingInfo {
pub fn exit(&mut self) {
self.nested_level -= 1;
if self.nested_level == 0 && self.sie_before_masking {
unsafe { sstatus::set_sie(); }
unsafe {
sstatus::set_sie();
}
}
}
}
@ -101,14 +104,17 @@ impl<T> UPIntrFreeCell<T> {
inner: RefCell::new(value),
}
}
/// Panic if the data has been borrowed.
pub fn exclusive_access(&self) -> UPIntrRefMut<'_, T> {
INTR_MASKING_INFO.get_mut().enter();
UPIntrRefMut(Some(self.inner.borrow_mut()))
}
pub fn exclusive_session<F, V>(&self, f: F) -> V where F: FnOnce(&mut T) -> V {
pub fn exclusive_session<F, V>(&self, f: F) -> V
where
F: FnOnce(&mut T) -> V,
{
let mut inner = self.exclusive_access();
f(inner.deref_mut())
}
@ -132,4 +138,3 @@ impl<'a, T> DerefMut for UPIntrRefMut<'a, T> {
self.0.as_mut().unwrap().deref_mut()
}
}