lock_api

Struct RawReentrantMutex

source
pub struct RawReentrantMutex<R, G> { /* private fields */ }
Expand description

A raw mutex type that wraps another raw mutex to provide reentrancy.

Although this has the same methods as the RawMutex trait, it does not implement it, and should not be used in the same way, since this mutex can successfully acquire a lock multiple times in the same thread. Only use this when you know you want a raw mutex that can be locked reentrantly; you probably want ReentrantMutex instead.

Implementations§

source§

impl<R: RawMutex, G: GetThreadId> RawReentrantMutex<R, G>

source

pub const INIT: Self = _

Initial value for an unlocked mutex.

source

pub fn lock(&self)

Acquires this mutex, blocking if it’s held by another thread.

source

pub fn try_lock(&self) -> bool

Attempts to acquire this mutex without blocking. Returns true if the lock was successfully acquired and false otherwise.

source

pub unsafe fn unlock(&self)

Unlocks this mutex. The inner mutex may not be unlocked if this mutex was acquired previously in the current thread.

§Safety

This method may only be called if the mutex is held by the current thread.

source

pub fn is_locked(&self) -> bool

Checks whether the mutex is currently locked.

source

pub fn is_owned_by_current_thread(&self) -> bool

Checks whether the mutex is currently held by the current thread.

source§

impl<R: RawMutexFair, G: GetThreadId> RawReentrantMutex<R, G>

source

pub unsafe fn unlock_fair(&self)

Unlocks this mutex using a fair unlock protocol. The inner mutex may not be unlocked if this mutex was acquired previously in the current thread.

§Safety

This method may only be called if the mutex is held by the current thread.

source

pub unsafe fn bump(&self)

Temporarily yields the mutex to a waiting thread if there is one.

This method is functionally equivalent to calling unlock_fair followed by lock, however it can be much more efficient in the case where there are no waiting threads.

§Safety

This method may only be called if the mutex is held by the current thread.

source§

impl<R: RawMutexTimed, G: GetThreadId> RawReentrantMutex<R, G>

source

pub fn try_lock_until(&self, timeout: R::Instant) -> bool

Attempts to acquire this lock until a timeout is reached.

source

pub fn try_lock_for(&self, timeout: R::Duration) -> bool

Attempts to acquire this lock until a timeout is reached.

Trait Implementations§

Auto Trait Implementations§

§

impl<R, G> !Freeze for RawReentrantMutex<R, G>

§

impl<R, G> !RefUnwindSafe for RawReentrantMutex<R, G>

§

impl<R, G> Unpin for RawReentrantMutex<R, G>
where R: Unpin, G: Unpin,

§

impl<R, G> UnwindSafe for RawReentrantMutex<R, G>
where R: UnwindSafe, G: 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.