Struct r3::sync::mutex::GenericMutex

source ·
pub struct GenericMutex<Cell, Mutex> { /* private fields */ }
Available on crate feature 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 calling GenericMutex::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,

source

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,

source

pub fn lock(&self) -> LockResult<GenericMutexGuard<'_, Cell, Mutex>>

Acquire the mutex, blocking the current thread until it is able to do so.

source

pub fn try_lock(&self) -> TryLockResult<GenericMutexGuard<'_, Cell, Mutex>>

Attempt to acquire the mutex.

source

pub fn mark_consistent(&self) -> Result<(), MarkConsistentError>

Mark the state protected by the mutex as consistent.

source

pub fn get_ptr(&self) -> *mut T

Get a raw pointer to the contained data.

Trait Implementations§

source§

impl<Cell, Mutex, T: Debug> Debug for GenericMutex<Cell, Mutex>where Cell: Deref<Target = UnsafeCell<MaybeUninit<T>>>, Mutex: MutexHandle,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Cell, Mutex, T: Send> Send for GenericMutex<Cell, Mutex>where Cell: Deref<Target = UnsafeCell<MaybeUninit<T>>>,

source§

impl<Cell, Mutex, T: Send> Sync for GenericMutex<Cell, Mutex>where Cell: Deref<Target = UnsafeCell<MaybeUninit<T>>>,

Auto Trait Implementations§

§

impl<Cell, Mutex> RefUnwindSafe for GenericMutex<Cell, Mutex>where Cell: RefUnwindSafe, Mutex: RefUnwindSafe,

§

impl<Cell, Mutex> Unpin for GenericMutex<Cell, Mutex>where Cell: Unpin, Mutex: Unpin,

§

impl<Cell, Mutex> UnwindSafe for GenericMutex<Cell, Mutex>where Cell: UnwindSafe, Mutex: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.