Small Fix && cargo fmt
This commit is contained in:
parent
c9583b0f53
commit
ae3ba9c26f
83 changed files with 1085 additions and 1079 deletions
|
@ -1,6 +1,6 @@
|
|||
use alloc::{sync::Arc, collections::VecDeque};
|
||||
use crate::task::{add_task, TaskControlBlock, current_task, block_current_and_run_next};
|
||||
use crate::sync::{Mutex, UPSafeCell};
|
||||
use crate::task::{add_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
pub struct Condvar {
|
||||
pub inner: UPSafeCell<CondvarInner>,
|
||||
|
@ -13,11 +13,11 @@ pub struct CondvarInner {
|
|||
impl Condvar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: unsafe { UPSafeCell::new(
|
||||
CondvarInner {
|
||||
inner: unsafe {
|
||||
UPSafeCell::new(CondvarInner {
|
||||
wait_queue: VecDeque::new(),
|
||||
}
|
||||
)},
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ impl Condvar {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn wait(&self, mutex:Arc<dyn Mutex>) {
|
||||
pub fn wait(&self, mutex: Arc<dyn Mutex>) {
|
||||
mutex.unlock();
|
||||
let mut inner = self.inner.exclusive_access();
|
||||
inner.wait_queue.push_back(current_task().unwrap());
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
mod up;
|
||||
mod condvar;
|
||||
mod mutex;
|
||||
mod semaphore;
|
||||
mod condvar;
|
||||
mod up;
|
||||
|
||||
pub use up::UPSafeCell;
|
||||
pub use mutex::{Mutex, MutexSpin, MutexBlocking};
|
||||
pub use condvar::Condvar;
|
||||
pub use mutex::{Mutex, MutexBlocking, MutexSpin};
|
||||
pub use semaphore::Semaphore;
|
||||
pub use condvar::Condvar;
|
||||
pub use up::UPSafeCell;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::UPSafeCell;
|
||||
use crate::task::{block_current_and_run_next, suspend_current_and_run_next};
|
||||
use crate::task::TaskControlBlock;
|
||||
use crate::task::{add_task, current_task};
|
||||
use alloc::{sync::Arc, collections::VecDeque};
|
||||
use crate::task::{block_current_and_run_next, suspend_current_and_run_next};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
pub trait Mutex: Sync + Send {
|
||||
fn lock(&self);
|
||||
|
@ -77,7 +77,7 @@ impl Mutex for MutexBlocking {
|
|||
}
|
||||
|
||||
fn unlock(&self) {
|
||||
let mut mutex_inner = self.inner.exclusive_access();
|
||||
let mut mutex_inner = self.inner.exclusive_access();
|
||||
assert_eq!(mutex_inner.locked, true);
|
||||
if let Some(waking_task) = mutex_inner.wait_queue.pop_front() {
|
||||
add_task(waking_task);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use alloc::{sync::Arc, collections::VecDeque};
|
||||
use crate::task::{add_task, TaskControlBlock, current_task, block_current_and_run_next};
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::task::{add_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
pub struct Semaphore {
|
||||
pub inner: UPSafeCell<SemaphoreInner>,
|
||||
|
@ -14,12 +14,12 @@ pub struct SemaphoreInner {
|
|||
impl Semaphore {
|
||||
pub fn new(res_count: usize) -> Self {
|
||||
Self {
|
||||
inner: unsafe { UPSafeCell::new(
|
||||
SemaphoreInner {
|
||||
inner: unsafe {
|
||||
UPSafeCell::new(SemaphoreInner {
|
||||
count: res_count as isize,
|
||||
wait_queue: VecDeque::new(),
|
||||
}
|
||||
)},
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ impl<T> UPSafeCell<T> {
|
|||
/// User is responsible to guarantee that inner struct is only used in
|
||||
/// uniprocessor.
|
||||
pub unsafe fn new(value: T) -> Self {
|
||||
Self { inner: RefCell::new(value) }
|
||||
Self {
|
||||
inner: RefCell::new(value),
|
||||
}
|
||||
}
|
||||
/// Panic if the data has been borrowed.
|
||||
pub fn exclusive_access(&self) -> RefMut<'_, T> {
|
||||
self.inner.borrow_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue