pub use ::alloc::sync::Arc;
use core::ops::{Deref, DerefMut};
-use core::time::Duration;
use core::cell::{RefCell, Ref, RefMut};
use super::{LockTestExt, LockHeldState};
pub type LockResult<Guard> = Result<Guard, ()>;
-pub struct Condvar {}
-
-impl Condvar {
- pub fn new() -> Condvar {
- Condvar { }
- }
-
- pub fn wait<'a, T>(&'a self, guard: MutexGuard<'a, T>) -> LockResult<MutexGuard<'a, T>> {
- Ok(guard)
- }
-
- #[allow(unused)]
- pub fn wait_timeout<'a, T>(&'a self, guard: MutexGuard<'a, T>, _dur: Duration) -> LockResult<(MutexGuard<'a, T>, ())> {
- Ok((guard, ()))
- }
-
- pub fn notify_all(&self) {}
-}
-
pub struct Mutex<T: ?Sized> {
inner: RefCell<T>
}
pub fn try_lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
Ok(MutexGuard { lock: self.inner.borrow_mut() })
}
+
+ pub fn into_inner(self) -> LockResult<T> {
+ Ok(self.inner.into_inner())
+ }
}
-impl<T> LockTestExt for Mutex<T> {
+impl<'a, T: 'a> LockTestExt<'a> for Mutex<T> {
#[inline]
fn held_by_thread(&self) -> LockHeldState {
if self.lock().is_err() { return LockHeldState::HeldByThread; }
else { return LockHeldState::NotHeldByThread; }
}
+ type ExclLock = MutexGuard<'a, T>;
+ #[inline]
+ fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard<T> { self.lock().unwrap() }
}
pub struct RwLock<T: ?Sized> {
}
}
-impl<T> LockTestExt for RwLock<T> {
+impl<'a, T: 'a> LockTestExt<'a> for RwLock<T> {
#[inline]
fn held_by_thread(&self) -> LockHeldState {
if self.write().is_err() { return LockHeldState::HeldByThread; }
else { return LockHeldState::NotHeldByThread; }
}
+ type ExclLock = RwLockWriteGuard<'a, T>;
+ #[inline]
+ fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard<T> { self.write().unwrap() }
}
pub type FairRwLock<T> = RwLock<T>;