[][src]Struct lock_api::ReentrantMutex

pub struct ReentrantMutex<R: RawMutex, G: GetThreadId, T: ?Sized> { /* fields omitted */ }

A mutex which can be recursively locked by a single thread.

This type is identical to Mutex except for the following points:

See Mutex for more details about the underlying mutex primitive.

Methods

impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T>[src]

pub fn new(val: T) -> ReentrantMutex<R, G, T>[src]

Creates a new reentrant mutex in an unlocked state ready for use.

pub fn into_inner(self) -> T[src]

Consumes this mutex, returning the underlying data.

impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T>[src]

pub fn lock(&self) -> ReentrantMutexGuard<R, G, T>[src]

Acquires a reentrant mutex, blocking the current thread until it is able to do so.

If the mutex is held by another thread then this function will block the local thread until it is available to acquire the mutex. If the mutex is already held by the current thread then this function will increment the lock reference count and return immediately. Upon returning, the thread is the only thread with the mutex held. An RAII guard is returned to allow scoped unlock of the lock. When the guard goes out of scope, the mutex will be unlocked.

pub fn try_lock(&self) -> Option<ReentrantMutexGuard<R, G, T>>[src]

Attempts to acquire this lock.

If the lock could not be acquired at this time, then None is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.

This function does not block.

pub fn get_mut(&mut self) -> &mut T[src]

Returns a mutable reference to the underlying data.

Since this call borrows the ReentrantMutex mutably, no actual locking needs to take place---the mutable borrow statically guarantees no locks exist.

pub unsafe fn force_unlock(&self)[src]

Forcibly unlocks the mutex.

This is useful when combined with mem::forget to hold a lock without the need to maintain a ReentrantMutexGuard object alive, for example when dealing with FFI.

Safety

This method must only be called if the current thread logically owns a ReentrantMutexGuard but that guard has be discarded using mem::forget. Behavior is undefined if a mutex is unlocked when not locked.

pub unsafe fn raw(&self) -> &R[src]

Returns the underlying raw mutex object.

Note that you will most likely need to import the RawMutex trait from lock_api to be able to call functions on the raw mutex.

Safety

This method is unsafe because it allows unlocking a mutex while still holding a reference to a ReentrantMutexGuard.

impl<R: RawMutexFair, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T>[src]

pub unsafe fn force_unlock_fair(&self)[src]

Forcibly unlocks the mutex using a fair unlock protocol.

This is useful when combined with mem::forget to hold a lock without the need to maintain a ReentrantMutexGuard object alive, for example when dealing with FFI.

Safety

This method must only be called if the current thread logically owns a ReentrantMutexGuard but that guard has be discarded using mem::forget. Behavior is undefined if a mutex is unlocked when not locked.

impl<R: RawMutexTimed, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T>[src]

pub fn try_lock_for(
    &self,
    timeout: R::Duration
) -> Option<ReentrantMutexGuard<R, G, T>>
[src]

Attempts to acquire this lock until a timeout is reached.

If the lock could not be acquired before the timeout expired, then None is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.

pub fn try_lock_until(
    &self,
    timeout: R::Instant
) -> Option<ReentrantMutexGuard<R, G, T>>
[src]

Attempts to acquire this lock until a timeout is reached.

If the lock could not be acquired before the timeout expired, then None is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.

Trait Implementations

impl<R: RawMutex, G: GetThreadId, T: ?Sized + Debug> Debug for ReentrantMutex<R, G, T>[src]

impl<R: RawMutex + Send, G: GetThreadId + Send, T: ?Sized + Send> Send for ReentrantMutex<R, G, T>[src]

impl<R: RawMutex + Sync, G: GetThreadId + Sync, T: ?Sized + Send> Sync for ReentrantMutex<R, G, T>[src]

impl<R: RawMutex, G: GetThreadId, T> From<T> for ReentrantMutex<R, G, T>[src]

impl<R: RawMutex, G: GetThreadId, T: ?Sized + Default> Default for ReentrantMutex<R, G, T>[src]

Auto Trait Implementations

impl<R, G, T: ?Sized> Unpin for ReentrantMutex<R, G, T> where
    G: Unpin,
    R: Unpin,
    T: Unpin

impl<R, G, T: ?Sized> UnwindSafe for ReentrantMutex<R, G, T> where
    G: UnwindSafe,
    R: UnwindSafe,
    T: UnwindSafe

impl<R, G, T> !RefUnwindSafe for ReentrantMutex<R, G, T>

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T[src]