File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
library/std/src/sync/nonpoison Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 33//! The difference from the locks in the [`poison`] module is that the locks in this module will not
44//! become poisoned when a thread panics while holding a guard.
55
6+ /// A type alias for the result of a nonblocking locking method.
7+ pub type TryLockResult < Guard > = Result < Guard , WouldBlock > ;
8+
9+ /// A lock could not be acquired at this time because the operation would otherwise block.
10+ pub struct WouldBlock ;
11+
612#[ unstable( feature = "sync_nonpoison" , issue = "134645" ) ]
713pub use self :: mutex:: MappedMutexGuard ;
814#[ unstable( feature = "sync_nonpoison" , issue = "134645" ) ]
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use crate::marker::PhantomData;
44use crate :: mem:: ManuallyDrop ;
55use crate :: ops:: { Deref , DerefMut } ;
66use crate :: ptr:: NonNull ;
7+ use crate :: sync:: nonpoison:: { TryLockResult , WouldBlock } ;
78use crate :: sys:: sync as sys;
89
910/// A mutual exclusion primitive useful for protecting shared data.
@@ -256,8 +257,8 @@ impl<T: ?Sized> Mutex<T> {
256257 /// assert_eq!(*mutex.lock(), 10);
257258 /// ```
258259 #[ unstable( feature = "nonpoison_mutex" , issue = "134645" ) ]
259- pub fn try_lock ( & self ) -> Option < MutexGuard < ' _ , T > > {
260- unsafe { if self . inner . try_lock ( ) { Some ( MutexGuard :: new ( self ) ) } else { None } }
260+ pub fn try_lock ( & self ) -> TryLockResult < MutexGuard < ' _ , T > > {
261+ unsafe { if self . inner . try_lock ( ) { Ok ( MutexGuard :: new ( self ) ) } else { Err ( WouldBlock ) } }
261262 }
262263
263264 /// Consumes this mutex, returning the underlying data.
You can’t perform that action at this time.
0 commit comments