Struct holochain::prelude::dependencies::kitsune_p2p_types::dependencies::lair_keystore_api::dependencies::parking_lot::lock_api::Mutex
pub struct Mutex<R, T>where
T: ?Sized,{ /* 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§
§impl<R, T> Mutex<R, T>where
R: RawMutex,
impl<R, T> Mutex<R, T>where
R: RawMutex,
pub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this mutex, returning the underlying data.
§impl<R, T> Mutex<R, T>where
R: RawMutex,
T: ?Sized,
impl<R, T> Mutex<R, T>where
R: RawMutex,
T: ?Sized,
pub fn lock(&self) -> MutexGuard<'_, R, T>
pub fn lock(&self) -> MutexGuard<'_, R, 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.
Attempts to lock a mutex in the thread which already holds the lock will result in a deadlock.
pub fn try_lock(&self) -> Option<MutexGuard<'_, R, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, R, 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 get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
Since this call borrows the Mutex
mutably, no actual locking needs to
take place—the mutable borrow statically guarantees no locks exist.
pub unsafe fn force_unlock(&self)
pub unsafe fn force_unlock(&self)
Forcibly unlocks the mutex.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a MutexGuard
object alive, for example when
dealing with FFI.
Safety
This method must only be called if the current thread logically owns a
MutexGuard
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
pub unsafe fn raw(&self) -> &R
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 MutexGuard
.
pub fn data_ptr(&self) -> *mut T
pub fn data_ptr(&self) -> *mut T
Returns a raw pointer to the underlying data.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a MutexGuard
object alive, for example when
dealing with FFI.
Safety
You must ensure that there are no data races when dereferencing the
returned pointer, for example if the current thread logically owns
a MutexGuard
but that guard has been discarded using mem::forget
.
§impl<R, T> Mutex<R, T>where
R: RawMutexFair,
T: ?Sized,
impl<R, T> Mutex<R, T>where
R: RawMutexFair,
T: ?Sized,
pub unsafe fn force_unlock_fair(&self)
pub unsafe fn force_unlock_fair(&self)
Forcibly unlocks the mutex using a fair unlock procotol.
This is useful when combined with mem::forget
to hold a lock without
the need to maintain a MutexGuard
object alive, for example when
dealing with FFI.
Safety
This method must only be called if the current thread logically owns a
MutexGuard
but that guard has be discarded using mem::forget
.
Behavior is undefined if a mutex is unlocked when not locked.
§impl<R, T> Mutex<R, T>where
R: RawMutexTimed,
T: ?Sized,
impl<R, T> Mutex<R, T>where
R: RawMutexTimed,
T: ?Sized,
pub fn try_lock_for(
&self,
timeout: <R as RawMutexTimed>::Duration
) -> Option<MutexGuard<'_, R, T>>
pub fn try_lock_for(
&self,
timeout: <R as RawMutexTimed>::Duration
) -> Option<MutexGuard<'_, R, 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: <R as RawMutexTimed>::Instant
) -> Option<MutexGuard<'_, R, T>>
pub fn try_lock_until(
&self,
timeout: <R as RawMutexTimed>::Instant
) -> Option<MutexGuard<'_, R, 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.
Trait Implementations§
§impl<K> ShrinkableKeyedStateStore<K> for Mutex<RawMutex, HashMap<K, InMemoryState, RandomState>>where
K: Hash + Eq + Clone,
impl<K> ShrinkableKeyedStateStore<K> for Mutex<RawMutex, HashMap<K, InMemoryState, RandomState>>where
K: Hash + Eq + Clone,
§fn retain_recent(&self, drop_below: Nanos)
fn retain_recent(&self, drop_below: Nanos)
drop_below
.§fn shrink_to_fit(&self)
fn shrink_to_fit(&self)
§impl<K> StateStore for Mutex<RawMutex, HashMap<K, InMemoryState, RandomState>>where
K: Hash + Eq + Clone,
impl<K> StateStore for Mutex<RawMutex, HashMap<K, InMemoryState, RandomState>>where
K: Hash + Eq + Clone,
impl<R, T> Send for Mutex<R, T>where
R: RawMutex + Send,
T: Send + ?Sized,
impl<R, T> Sync for Mutex<R, T>where
R: RawMutex + Sync,
T: Send + ?Sized,
Auto Trait Implementations§
impl<R, T> !RefUnwindSafe for Mutex<R, T>
impl<R, T: ?Sized> Unpin for Mutex<R, T>where
R: Unpin,
T: Unpin,
impl<R, T: ?Sized> UnwindSafe for Mutex<R, T>where
R: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.