ShardedMutexGuard

Struct ShardedMutexGuard 

Source
pub struct ShardedMutexGuard<'a, T, TAG>(/* private fields */)
where
    T: AssocObjects<TAG>;
Expand description

The guard returned from locking a ShardedMutex. Dropping this will unlock the mutex. Access to the underlying value is done by dereferencing this guard.

Implementations§

Source§

impl<'a, T, TAG> ShardedMutexGuard<'a, T, TAG>
where T: AssocObjects<TAG>,

Source

pub fn then_lock<U, UTAG>( self, new: &'a ShardedMutex<U, UTAG>, timeout: Duration, ) -> Result<ShardedMutexGuard<'_, U, UTAG>, ShardedMutexGuard<'_, T, TAG>>
where U: AssocObjects<UTAG>,

Hand-over-hand locking, locks another ShardedMutex, then unlocks the mutex hold by the self guard. This can result in a deadlock because the locking order of the underlying mutexes is not known. To resolve this we use a timeout.

§Returns

Ok(ShardedMutexGuard<U, UTAG>) with the new acquired lock. When new is the same mutex as self refers to, then Ok(self) is returned.

§Errors

Err(self) with the old lock still held, when the new lock was not acquired

When this function returns an ‘Err’ a deadlock could be the cause, it the responsibility of the caller to resolve this. Usually this is done by undo any changes in the object that is hold by self, then drop self and then retry the whole operation. A error would also be returned when the new lock was not acquired within the timeout.

§Example
use sharded_mutex::*;
use std::time::Duration;

let x = ShardedMutex::new(123);
let y = ShardedMutex::new(23.4);

let mut guard_x = x.lock();
let guard_y = guard_x.then_lock(&y, Duration::from_millis(100)).unwrap();
let guard_again = guard_y.then_lock(&y, Duration::from_millis(100)).unwrap();

Trait Implementations§

Source§

impl<T, TAG> AsMut<T> for ShardedMutexGuard<'_, T, TAG>
where T: AssocObjects<TAG>,

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, TAG> AsRef<T> for ShardedMutexGuard<'_, T, TAG>
where T: AssocObjects<TAG>,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T, TAG: Debug> Debug for ShardedMutexGuard<'a, T, TAG>
where T: AssocObjects<TAG> + Debug,

Source§

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

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

impl<T, TAG> Deref for ShardedMutexGuard<'_, T, TAG>
where T: AssocObjects<TAG>,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, TAG> DerefMut for ShardedMutexGuard<'_, T, TAG>
where T: AssocObjects<TAG>,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T, TAG> Drop for ShardedMutexGuard<'_, T, TAG>
where T: AssocObjects<TAG>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T, TAG> Freeze for ShardedMutexGuard<'a, T, TAG>

§

impl<'a, T, TAG> !RefUnwindSafe for ShardedMutexGuard<'a, T, TAG>

§

impl<'a, T, TAG> Send for ShardedMutexGuard<'a, T, TAG>
where T: Send,

§

impl<'a, T, TAG> Sync for ShardedMutexGuard<'a, T, TAG>
where T: Send,

§

impl<'a, T, TAG> Unpin for ShardedMutexGuard<'a, T, TAG>

§

impl<'a, T, TAG> !UnwindSafe for ShardedMutexGuard<'a, T, TAG>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.