pub struct Mutex<L: Level, T> { /* private fields */ }
Expand description
A mutual exclusion primitive useful for protecting shared data
This mutex will block threads waiting for the lock to become available. The
mutex can also be statically initialized or created via a new
constructor. Each mutex has a type parameter which represents the data that
it is protecting. The data can only be accessed through the RAII guards
returned from lock
and try_lock
, which guarantees that the data is only
ever accessed when the mutex is locked.
Implementations§
Source§impl<L: Level, T> Mutex<L, T>
impl<L: Level, T> Mutex<L, T>
Sourcepub fn lock<'a, LP: Lower<L> + 'a>(
&'a self,
lock_token: LockToken<'a, LP>,
) -> MutexGuard<'a, L, T>
pub fn lock<'a, LP: Lower<L> + 'a>( &'a self, lock_token: LockToken<'a, LP>, ) -> MutexGuard<'a, L, T>
Acquires a mutex, blocking the current thread until it is able to do so.
This function will block the local thread until it is available to acquire the mutex. 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.
Sourcepub fn try_lock<'a, LP: Lower<L> + 'a>(
&'a self,
lock_token: LockToken<'a, LP>,
) -> Option<MutexGuard<'a, L, T>>
pub fn try_lock<'a, LP: Lower<L> + 'a>( &'a self, lock_token: LockToken<'a, LP>, ) -> Option<MutexGuard<'a, L, 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.
Sourcepub fn try_lock_for<'a, LP: Lower<L> + 'a>(
&'a self,
lock_token: LockToken<'a, LP>,
duration: Duration,
) -> Option<MutexGuard<'a, L, T>>
pub fn try_lock_for<'a, LP: Lower<L> + 'a>( &'a self, lock_token: LockToken<'a, LP>, duration: Duration, ) -> Option<MutexGuard<'a, L, T>>
Attempts to acquire this lock. Timeout after duration has expired
Since this operation is not supported by a std::sync::mutex this this is implemented using try_lock and waits
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this Mutex, returning the underlying data.