Add rustfmt from relibc and apply it with cargo fmt
This commit is contained in:
+2
-4
@@ -1,7 +1,5 @@
|
||||
pub use self::wait_condition::WaitCondition;
|
||||
pub use self::wait_queue::WaitQueue;
|
||||
pub use self::wait_map::WaitMap;
|
||||
pub use self::{wait_condition::WaitCondition, wait_map::WaitMap, wait_queue::WaitQueue};
|
||||
|
||||
pub mod wait_condition;
|
||||
pub mod wait_queue;
|
||||
pub mod wait_map;
|
||||
pub mod wait_queue;
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use spin::{Mutex, MutexGuard, RwLock};
|
||||
|
||||
use crate::context::{self, Context};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitCondition {
|
||||
contexts: Mutex<Vec<Arc<RwLock<Context>>>>
|
||||
contexts: Mutex<Vec<Arc<RwLock<Context>>>>,
|
||||
}
|
||||
|
||||
impl WaitCondition {
|
||||
pub const fn new() -> WaitCondition {
|
||||
WaitCondition {
|
||||
contexts: Mutex::new(Vec::new())
|
||||
contexts: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +56,9 @@ impl WaitCondition {
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
unsafe { context::switch(); }
|
||||
unsafe {
|
||||
context::switch();
|
||||
}
|
||||
|
||||
let mut waited = true;
|
||||
|
||||
@@ -86,7 +87,7 @@ impl WaitCondition {
|
||||
}
|
||||
|
||||
impl Drop for WaitCondition {
|
||||
fn drop(&mut self){
|
||||
fn drop(&mut self) {
|
||||
unsafe { self.notify_signal() };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,17 @@ use crate::sync::WaitCondition;
|
||||
pub struct WaitMap<K, V> {
|
||||
// Using BTreeMap as this depends on .keys() providing elements in sorted order.
|
||||
pub inner: Mutex<BTreeMap<K, V>>,
|
||||
pub condition: WaitCondition
|
||||
pub condition: WaitCondition,
|
||||
}
|
||||
|
||||
impl<K, V> WaitMap<K, V> where K: Clone + Ord {
|
||||
impl<K, V> WaitMap<K, V>
|
||||
where
|
||||
K: Clone + Ord,
|
||||
{
|
||||
pub fn new() -> WaitMap<K, V> {
|
||||
WaitMap {
|
||||
inner: Mutex::new(BTreeMap::new()),
|
||||
condition: WaitCondition::new()
|
||||
condition: WaitCondition::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-7
@@ -2,9 +2,13 @@ use alloc::collections::VecDeque;
|
||||
use spin::Mutex;
|
||||
use syscall::{EAGAIN, EINTR};
|
||||
|
||||
use crate::sync::WaitCondition;
|
||||
use crate::syscall::usercopy::UserSliceWo;
|
||||
use crate::syscall::error::{Error, EINVAL, Result};
|
||||
use crate::{
|
||||
sync::WaitCondition,
|
||||
syscall::{
|
||||
error::{Error, Result, EINVAL},
|
||||
usercopy::UserSliceWo,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitQueue<T> {
|
||||
@@ -16,11 +20,16 @@ impl<T> WaitQueue<T> {
|
||||
pub const fn new() -> WaitQueue<T> {
|
||||
WaitQueue {
|
||||
inner: Mutex::new(VecDeque::new()),
|
||||
condition: WaitCondition::new()
|
||||
condition: WaitCondition::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_into_user(&self, buf: UserSliceWo, block: bool, reason: &'static str) -> Result<usize> {
|
||||
pub fn receive_into_user(
|
||||
&self,
|
||||
buf: UserSliceWo,
|
||||
block: bool,
|
||||
reason: &'static str,
|
||||
) -> Result<usize> {
|
||||
loop {
|
||||
let mut inner = self.inner.lock();
|
||||
|
||||
@@ -41,8 +50,18 @@ impl<T> WaitQueue<T> {
|
||||
}
|
||||
|
||||
let (s1, s2) = inner.as_slices();
|
||||
let s1_bytes = unsafe { core::slice::from_raw_parts(s1.as_ptr().cast::<u8>(), s1.len() * core::mem::size_of::<T>()) };
|
||||
let s2_bytes = unsafe { core::slice::from_raw_parts(s2.as_ptr().cast::<u8>(), s2.len() * core::mem::size_of::<T>()) };
|
||||
let s1_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
s1.as_ptr().cast::<u8>(),
|
||||
s1.len() * core::mem::size_of::<T>(),
|
||||
)
|
||||
};
|
||||
let s2_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
s2.as_ptr().cast::<u8>(),
|
||||
s2.len() * core::mem::size_of::<T>(),
|
||||
)
|
||||
};
|
||||
|
||||
let mut bytes_copied = buf.copy_common_bytes_from_slice(s1_bytes)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user