Struct parking_lot::ReentrantMutex [−][src]
pub struct ReentrantMutex<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:
- Locking multiple times from the same thread will work correctly instead of deadlocking.
ReentrantMutexGuard
does not give mutable references to the locked data. Use aRefCell
if you need this.ReentrantMutexGuard
is notSend
.
See Mutex
for more details about the underlying mutex
primitive.
Methods
impl<T> ReentrantMutex<T>
[src]
impl<T> ReentrantMutex<T>
pub const fn new(val: T) -> ReentrantMutex<T>
[src]
pub const fn new(val: T) -> ReentrantMutex<T>
Creates a new reentrant mutex in an unlocked state ready for use.
pub fn into_inner(self) -> T
[src]
pub fn into_inner(self) -> T
Consumes this reentrant mutex, returning the underlying data.
impl<T: ?Sized> ReentrantMutex<T>
[src]
impl<T: ?Sized> ReentrantMutex<T>
pub fn lock(&self) -> ReentrantMutexGuard<T>
[src]
pub fn lock(&self) -> ReentrantMutexGuard<T>
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<T>>
[src]
pub fn try_lock(&self) -> Option<ReentrantMutexGuard<T>>
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 try_lock_for(&self, timeout: Duration) -> Option<ReentrantMutexGuard<T>>
[src]
pub fn try_lock_for(&self, timeout: Duration) -> Option<ReentrantMutexGuard<T>>
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: Instant) -> Option<ReentrantMutexGuard<T>>
[src]
pub fn try_lock_until(&self, timeout: Instant) -> Option<ReentrantMutexGuard<T>>
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 get_mut(&mut self) -> &mut T
[src]
pub fn get_mut(&mut self) -> &mut T
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 raw_unlock(&self)
[src]
pub unsafe fn raw_unlock(&self)
Releases the mutex.
Safety
This function must only be called if the mutex was locked using
raw_lock
or raw_try_lock
, or if a ReentrantMutexGuard
from this mutex was
leaked (e.g. with mem::forget
). The mutex must be locked.
pub unsafe fn raw_unlock_fair(&self)
[src]
pub unsafe fn raw_unlock_fair(&self)
Releases the mutex using a fair unlock protocol.
See ReentrantMutexGuard::unlock_fair
.
Safety
This function must only be called if the mutex was locked using
raw_lock
or raw_try_lock
, or if a ReentrantMutexGuard
from this mutex was
leaked (e.g. with mem::forget
). The mutex must be locked.
impl ReentrantMutex<()>
[src]
impl ReentrantMutex<()>
pub fn raw_lock(&self)
[src]
pub fn raw_lock(&self)
Acquires a mutex, blocking the current thread until it is able to do so.
This is similar to lock
, except that a ReentrantMutexGuard
is not returned.
Instead you will need to call raw_unlock
to release the mutex.
pub fn raw_try_lock(&self) -> bool
[src]
pub fn raw_try_lock(&self) -> bool
Attempts to acquire this lock.
This is similar to try_lock
, except that a ReentrantMutexGuard
is not
returned. Instead you will need to call raw_unlock
to release the
mutex.
Trait Implementations
impl<T: ?Sized + Send> Send for ReentrantMutex<T>
[src]
impl<T: ?Sized + Send> Send for ReentrantMutex<T>
impl<T: ?Sized + Send> Sync for ReentrantMutex<T>
[src]
impl<T: ?Sized + Send> Sync for ReentrantMutex<T>
impl<T: ?Sized + Default> Default for ReentrantMutex<T>
[src]
impl<T: ?Sized + Default> Default for ReentrantMutex<T>
fn default() -> ReentrantMutex<T>
[src]
fn default() -> ReentrantMutex<T>
Returns the "default value" for a type. Read more
impl<T: ?Sized + Debug> Debug for ReentrantMutex<T>
[src]
impl<T: ?Sized + Debug> Debug for ReentrantMutex<T>