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.