|
1 | | -pub use ::alloc::sync::Arc; |
| 1 | +use super::{LockHeldState, LockTestExt}; |
| 2 | +pub use alloc::sync::Arc; |
| 3 | +use core::cell::{Ref, RefCell, RefMut}; |
2 | 4 | use core::ops::{Deref, DerefMut}; |
3 | | -use core::cell::{RefCell, Ref, RefMut}; |
4 | | -use super::{LockTestExt, LockHeldState}; |
5 | 5 |
|
6 | 6 | pub type LockResult<Guard> = Result<Guard, ()>; |
7 | 7 |
|
8 | 8 | pub struct Mutex<T: ?Sized> { |
9 | | - inner: RefCell<T> |
| 9 | + inner: RefCell<T>, |
10 | 10 | } |
11 | 11 |
|
12 | 12 | #[must_use = "if unused the Mutex will immediately unlock"] |
@@ -45,16 +45,21 @@ impl<T> Mutex<T> { |
45 | 45 | impl<'a, T: 'a> LockTestExt<'a> for Mutex<T> { |
46 | 46 | #[inline] |
47 | 47 | fn held_by_thread(&self) -> LockHeldState { |
48 | | - if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } |
49 | | - else { return LockHeldState::NotHeldByThread; } |
| 48 | + if self.inner.try_borrow_mut().is_err() { |
| 49 | + return LockHeldState::HeldByThread; |
| 50 | + } else { |
| 51 | + return LockHeldState::NotHeldByThread; |
| 52 | + } |
50 | 53 | } |
51 | 54 | type ExclLock = MutexGuard<'a, T>; |
52 | 55 | #[inline] |
53 | | - fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard<T> { self.lock().unwrap() } |
| 56 | + fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard<T> { |
| 57 | + self.lock().unwrap() |
| 58 | + } |
54 | 59 | } |
55 | 60 |
|
56 | 61 | pub struct RwLock<T: ?Sized> { |
57 | | - inner: RefCell<T> |
| 62 | + inner: RefCell<T>, |
58 | 63 | } |
59 | 64 |
|
60 | 65 | pub struct RwLockReadGuard<'a, T: ?Sized + 'a> { |
@@ -103,20 +108,25 @@ impl<T> RwLock<T> { |
103 | 108 | pub fn try_write<'a>(&'a self) -> LockResult<RwLockWriteGuard<'a, T>> { |
104 | 109 | match self.inner.try_borrow_mut() { |
105 | 110 | Ok(lock) => Ok(RwLockWriteGuard { lock }), |
106 | | - Err(_) => Err(()) |
| 111 | + Err(_) => Err(()), |
107 | 112 | } |
108 | 113 | } |
109 | 114 | } |
110 | 115 |
|
111 | 116 | impl<'a, T: 'a> LockTestExt<'a> for RwLock<T> { |
112 | 117 | #[inline] |
113 | 118 | fn held_by_thread(&self) -> LockHeldState { |
114 | | - if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } |
115 | | - else { return LockHeldState::NotHeldByThread; } |
| 119 | + if self.inner.try_borrow_mut().is_err() { |
| 120 | + return LockHeldState::HeldByThread; |
| 121 | + } else { |
| 122 | + return LockHeldState::NotHeldByThread; |
| 123 | + } |
116 | 124 | } |
117 | 125 | type ExclLock = RwLockWriteGuard<'a, T>; |
118 | 126 | #[inline] |
119 | | - fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard<T> { self.write().unwrap() } |
| 127 | + fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard<T> { |
| 128 | + self.write().unwrap() |
| 129 | + } |
120 | 130 | } |
121 | 131 |
|
122 | 132 | pub type FairRwLock<T> = RwLock<T>; |
0 commit comments