try_lock

Struct TryLock

Source
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>

Source

pub fn new(val: T) -> TryLock<T>

Create a TryLock around the value.

Source

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.

Source

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.

Source

pub fn into_inner(self) -> T

Take the value back out of the lock when this is the sole owner.

Trait Implementations§

Source§

impl<T: Debug> Debug for TryLock<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for TryLock<T>

Source§

fn default() -> TryLock<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Send> Send for TryLock<T>

Source§

impl<T: Send> Sync for TryLock<T>

Auto Trait Implementations§

§

impl<T> !Freeze for TryLock<T>

§

impl<T> !RefUnwindSafe for TryLock<T>

§

impl<T> Unpin for TryLock<T>
where T: Unpin,

§

impl<T> UnwindSafe for TryLock<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.