Struct r3::sync::mutex::GenericMutex
source · pub struct GenericMutex<Cell, Mutex> { /* private fields */ }
sync
only.Expand description
A mutual exclusion primitive useful for protecting shared data from concurrent access.
This type is implemented using r3::kernel::Mutex
, the low-level
synchronization primitive and therefore inherits its properties.
The important inherited properties are listed below:
-
When trying to lock an abandoned mutex, the lock function will return
Err(LockError::Abandoned(lock_guard))
. This state can be exited by callingGenericMutex::mark_consistent
. -
Mutexes must be unlocked in a lock-reverse order.
GenericMutexGuard
::drop
might panic if this is violated.
Example
See StaticMutex
.
Implementations§
source§impl<System, T: 'static> GenericMutex<Hunk<System, UnsafeCell<MaybeUninit<T>>>, MutexRef<'static, System>>where
System: KernelMutex + KernelStatic,
impl<System, T: 'static> GenericMutex<Hunk<System, UnsafeCell<MaybeUninit<T>>>, MutexRef<'static, System>>where System: KernelMutex + KernelStatic,
sourcepub const fn define() -> Definer<System, DefaultSource<T>>
pub const fn define() -> Definer<System, DefaultSource<T>>
Construct a Definer
to define a mutex in a configuration
function.
source§impl<Cell, Mutex, T> GenericMutex<Cell, Mutex>where
Cell: Deref<Target = UnsafeCell<MaybeUninit<T>>>,
Mutex: MutexHandle,
impl<Cell, Mutex, T> GenericMutex<Cell, Mutex>where Cell: Deref<Target = UnsafeCell<MaybeUninit<T>>>, Mutex: MutexHandle,
sourcepub fn lock(&self) -> LockResult<GenericMutexGuard<'_, Cell, Mutex>>
pub fn lock(&self) -> LockResult<GenericMutexGuard<'_, Cell, Mutex>>
Acquire the mutex, blocking the current thread until it is able to do so.
sourcepub fn try_lock(&self) -> TryLockResult<GenericMutexGuard<'_, Cell, Mutex>>
pub fn try_lock(&self) -> TryLockResult<GenericMutexGuard<'_, Cell, Mutex>>
Attempt to acquire the mutex.
sourcepub fn mark_consistent(&self) -> Result<(), MarkConsistentError>
pub fn mark_consistent(&self) -> Result<(), MarkConsistentError>
Mark the state protected by the mutex as consistent.