pub struct TryLock<T> { /* private fields */ }
Expand description
A light-weight lock guarded by an atomic boolean.
Most efficient when contention is low, acquiring the lock is a single atomic swap, and releasing it just 1 more atomic swap.
It is only possible to try to acquire the lock, it is not possible to
wait for the lock to become ready, like with a Mutex
.
Implementations§
source§impl<T> TryLock<T>
impl<T> TryLock<T>
sourcepub fn try_lock(&self) -> Option<Locked<'_, T>>
pub fn try_lock(&self) -> Option<Locked<'_, T>>
Try to acquire the lock of this value.
If the lock is already acquired by someone else, this returns
None
. You can try to acquire again whenever you want, perhaps
by spinning a few times, or by using some other means of
notification.
§Note
The default memory ordering is to use Acquire
to lock, and Release
to unlock. If different ordering is required, use
try_lock_order
.
sourcepub fn try_lock_order(
&self,
lock_order: Ordering,
unlock_order: Ordering,
) -> Option<Locked<'_, T>>
pub fn try_lock_order( &self, lock_order: Ordering, unlock_order: Ordering, ) -> Option<Locked<'_, T>>
Try to acquire the lock of this value using the lock and unlock orderings.
If the lock is already acquired by someone else, this returns
None
. You can try to acquire again whenever you want, perhaps
by spinning a few times, or by using some other means of
notification.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Take the value back out of the lock when this is the sole owner.