This commit is contained in:
DeathWish5 2022-03-07 15:07:42 +08:00
parent 596a8a7c5f
commit d6d80b0bf6
14 changed files with 1098 additions and 141 deletions

View File

@ -1,7 +1,7 @@
use core::cell::{RefCell, RefMut};
use lazy_static::*;
extern "C" {
extern "C" interrupt_ffi {
pub fn intr_on();
pub fn intr_off();
pub fn intr_get() -> bool;

View File

@ -1,129 +0,0 @@
// use alloc::collections::linked_list::LinkedList;
// use core::cell::UnsafeCell;
// use core::future::Future;
// use core::ops::{Deref, DerefMut};
// use core::pin::Pin;
// use core::sync::atomic::{AtomicBool, Ordering};
// use core::task::{Context, Poll, Waker};
// use crate::spinlock::SpinLock;
// /// A mutual exclusion and asynchronous primitive which could work
// /// in bare metal environments.
// ///
// /// This mutex block coroutine waiting for the lock to become available.
// /// The mutex can also be statically initialized or created via a new
// /// constructor. Each mutex has a type parameter which represents the
// /// data that it is protecting. The data can only be accessed through
// /// the RAII guards returned from lock and try_lock, which guarantees
// /// that the data is only ever accessed when the mutex is locked.
// pub struct AMutex<T: ?Sized> {
// state: AtomicBool,
// wakers: SpinLock<LinkedList<Waker>>,
// data: UnsafeCell<T>,
// }
// /// An RAII implementation of a "scoped lock" of a mutex. When this structure is
// /// dropped (falls out of scope), the lock will be unlocked.
// ///
// /// The data protected by the mutex can be accessed through this guard via its
// /// [`Deref`] and [`DerefMut`] implementations.
// ///
// /// This structure is created by the [`lock`] and [`try_lock`] methods on
// /// [`AMutex`].
// ///
// /// [`lock`]: AMutex::lock
// /// [`try_lock`]: AMutex::try_lock
// #[must_use = "if unused the AMutex will immediately unlock"]
// pub struct AMutexGuard<'a, T: ?Sized> {
// mutex: &'a AMutex<T>,
// }
// /// A future which resolves when the target mutex has been successfully
// /// acquired.
// pub struct AMutexLockFuture<'a, T: ?Sized> {
// mutex: &'a AMutex<T>,
// }
// unsafe impl<T: ?Sized + Send> Send for AMutex<T> {}
// unsafe impl<T: ?Sized + Send> Sync for AMutex<T> {}
// unsafe impl<T: ?Sized + Send> Send for AMutexGuard<'_, T> {}
// unsafe impl<T: ?Sized + Sync> Sync for AMutexGuard<'_, T> {}
// unsafe impl<T: ?Sized + Send> Send for AMutexLockFuture<'_, T> {}
// impl<T> AMutex<T> {
// /// Creates a new mutex in an unlocked state ready for use.
// pub fn new(t: T) -> Self {
// AMutex {
// state: AtomicBool::new(false),
// wakers: SpinLock::new(LinkedList::new()),
// data: UnsafeCell::new(t),
// }
// }
// }
// impl<T: ?Sized> AMutex<T> {
// pub fn lock(&self) -> AMutexLockFuture<'_, T> {
// return AMutexLockFuture { mutex: self };
// }
// /// Attempts to acquire this lock immedidately.
// pub fn try_lock(&self) -> Option<AMutexGuard<'_, T>> {
// if !self.state.fetch_or(true, Ordering::Acquire) {
// Some(AMutexGuard { mutex: self })
// } else {
// None
// }
// }
// pub fn unlock(&self) {
// self.state.store(false, Ordering::Release);
// let waker = self.wakers.lock().pop_front();
// if waker.is_some() {
// waker.unwrap().wake();
// }
// }
// pub fn register(&self, waker: Waker) {
// self.wakers.lock().push_back(waker);
// }
// }
// impl<'a, T: ?Sized> Future for AMutexLockFuture<'a, T> {
// type Output = AMutexGuard<'a, T>;
// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// if let Some(lock) = self.mutex.try_lock() {
// return Poll::Ready(lock);
// }
// let waker = cx.waker().clone();
// self.mutex.register(waker);
// if let Some(lock) = self.mutex.try_lock() {
// return Poll::Ready(lock);
// }
// Poll::Pending
// }
// }
// impl<T: ?Sized> Deref for AMutexGuard<'_, T> {
// type Target = T;
// #[inline]
// fn deref(&self) -> &T {
// unsafe { &*self.mutex.data.get() }
// }
// }
// impl<T: ?Sized> DerefMut for AMutexGuard<'_, T> {
// #[inline]
// fn deref_mut(&mut self) -> &mut T {
// unsafe { &mut *self.mutex.data.get() }
// }
// }
// impl<T: ?Sized> Drop for AMutexGuard<'_, T> {
// #[inline]
// fn drop(&mut self) {
// self.mutex.unlock();
// }
// }

1077
lock/src/rwlock.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@ use {
crate::object::*,
alloc::{sync::Arc, vec::Vec},
lazy_static::lazy_static,
spin::Mutex,
// spin::Mutex,
lock::spinlock::Mutex,
};
lazy_static! {

View File

@ -4,7 +4,8 @@ use {
crate::vm::*,
alloc::{sync::Arc, vec::Vec},
dev::Iommu,
spin::Mutex,
// spin::Mutex,
lock::spinlock::Mutex,
};
/// Bus Transaction Initiator.

View File

@ -1,5 +1,5 @@
use kernel_hal::interrupt;
use {super::*, spin::Mutex};
use {super::*, /*spin::Mutex*/lock::spinlock::Mutex,};
pub struct EventInterrupt {
vector: usize,

View File

@ -7,7 +7,8 @@ use {
crate::signal::*,
alloc::{boxed::Box, sync::Arc},
bitflags::bitflags,
spin::Mutex,
// spin::Mutex,
lock::spinlock::Mutex,
};
mod event_interrupt;

View File

@ -7,7 +7,8 @@ use {
core::sync::atomic::{AtomicU32, Ordering},
futures::channel::oneshot::{self, Sender},
hashbrown::HashMap,
spin::Mutex,
// spin::Mutex,
lock::spinlock::Mutex,
};
/// Bidirectional interprocess communication

View File

@ -2,7 +2,8 @@ use {
crate::object::*,
alloc::collections::VecDeque,
alloc::sync::{Arc, Weak},
spin::Mutex,
// spin::Mutex,
lock::spinlock::Mutex,
};
/// First-In First-Out inter-process queue.

View File

@ -105,7 +105,7 @@ use {
task::{Context, Poll},
},
downcast_rs::{impl_downcast, DowncastSync},
spin::Mutex,
lock::spinlock::Mutex, // spin::Mutex,
};
pub use {super::*, handle::*, rights::*, signal::*};

View File

@ -6,7 +6,7 @@ use {
crate::task::Task,
alloc::sync::{Arc, Weak},
alloc::vec::Vec,
spin::Mutex,
lock::spinlock::Mutex, //spin::Mutex,
};
/// Control a group of processes

View File

@ -1,4 +1,7 @@
use {super::*, crate::object::*, alloc::sync::Arc, numeric_enum_macro::numeric_enum, spin::Mutex};
use {
super::*, crate::object::*, alloc::sync::Arc, lock::spinlock::Mutex, /*spin::Mutex*/
numeric_enum_macro::numeric_enum,
};
/// A readable, writable, seekable interface to some underlying storage
///

View File

@ -1,4 +1,4 @@
use {super::*, alloc::sync::Arc, spin::Mutex};
use {super::*, alloc::sync::Arc, lock::spinlock::Mutex /*spin::Mutex*/};
/// VMO representing a physical range of memory.
pub struct VMObjectPhysical {

View File

@ -1,6 +1,7 @@
use {
super::*,
alloc::{string::String, vec::Vec},
lock::spinlock::Mutex, //spin::Mutex,
zircon_object::{
ipc::{Channel, MessagePacket},
object::{obj_type, HandleInfo},
@ -320,7 +321,7 @@ pub struct HandleDisposition {
result: i32,
}
static TESTS_ARGS: spin::Mutex<String> = spin::Mutex::new(String::new());
static TESTS_ARGS: Mutex<String> = Mutex::new(String::new());
/// HACK: pass arguments to standalone-test
#[allow(clippy::naive_bytecount)]