| 1 | //! Non-poisoning synchronous locks. |
| 2 | //! |
| 3 | //! The difference from the locks in the [`poison`] module is that the locks in this module will not |
| 4 | //! become poisoned when a thread panics while holding a guard. |
| 5 | //! |
| 6 | //! [`poison`]: super::poison |
| 7 | |
| 8 | use crate::fmt; |
| 9 | |
| 10 | /// A type alias for the result of a nonblocking locking method. |
| 11 | #[unstable (feature = "sync_nonpoison" , issue = "134645" )] |
| 12 | pub type TryLockResult<Guard> = Result<Guard, WouldBlock>; |
| 13 | |
| 14 | /// A lock could not be acquired at this time because the operation would otherwise block. |
| 15 | #[unstable (feature = "sync_nonpoison" , issue = "134645" )] |
| 16 | pub struct WouldBlock; |
| 17 | |
| 18 | #[unstable (feature = "sync_nonpoison" , issue = "134645" )] |
| 19 | impl fmt::Debug for WouldBlock { |
| 20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 21 | "WouldBlock" .fmt(f) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | #[unstable (feature = "sync_nonpoison" , issue = "134645" )] |
| 26 | impl fmt::Display for WouldBlock { |
| 27 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 28 | "try_lock failed because the operation would block" .fmt(f) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | #[unstable (feature = "nonpoison_condvar" , issue = "134645" )] |
| 33 | pub use self::condvar::Condvar; |
| 34 | #[unstable (feature = "mapped_lock_guards" , issue = "117108" )] |
| 35 | pub use self::mutex::MappedMutexGuard; |
| 36 | #[unstable (feature = "nonpoison_mutex" , issue = "134645" )] |
| 37 | pub use self::mutex::{Mutex, MutexGuard}; |
| 38 | #[unstable (feature = "mapped_lock_guards" , issue = "117108" )] |
| 39 | pub use self::rwlock::{MappedRwLockReadGuard, MappedRwLockWriteGuard}; |
| 40 | #[unstable (feature = "nonpoison_rwlock" , issue = "134645" )] |
| 41 | pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; |
| 42 | |
| 43 | mod condvar; |
| 44 | mod mutex; |
| 45 | mod rwlock; |
| 46 | |