iceoryx2_bb_threadsafe::trigger_queue

Struct Mutex

source
pub struct Mutex<'a, T>
where T: Debug,
{ /* private fields */ }
Expand description

Represents a POSIX mutex which can be created by the MutexBuilder.

§Example

For a detailed builder example, see MutexBuilder.

use iceoryx2_bb_posix::mutex::*;
use std::time::Duration;

let handle = MutexHandle::<i32>::new();
let mutex = MutexBuilder::new().create(5, &handle)
    .expect("Failed to create mutex");

{
    let guard = mutex.lock().expect("failed to lock mutex");
    println!("current mutex value is: {}", *guard);
}

match mutex.try_lock().expect("failed to lock") {
    Some(mut guard) => *guard = 123, // set mutex value to 123
    None => println!("unable to acquire lock"),
};

match mutex.timed_lock(Duration::from_secs(1)).expect("failed to lock") {
    Some(guard) => println!("New mutex value is: {}", *guard),
    None => println!("Timeout occurred while trying to get lock.")
};

Implementations§

source§

impl<'a, T> Mutex<'a, T>
where T: Debug,

source

pub fn lock(&self) -> Result<MutexGuard<'_, '_, T>, MutexLockError<'_, '_, T>>

Blocks until the ownership of the lock could be acquired. If it was successful it returns a MutexGuard to allow access to the underlying value. If the previously owning thread has died and MutexThreadTerminationBehavior::ReleaseWhenLocked was set it returns the error MutexLockError::LockAcquiredButOwnerDied which contains also the MutexGuard. The new owner now has the responsibility to either repair the underlying value of the mutex and call Mutex::make_consistent() when it is repaired or to undertake other measures when it is unrepairable.

source

pub fn try_lock( &self, ) -> Result<Option<MutexGuard<'_, '_, T>>, MutexLockError<'_, '_, T>>

Tries to acquire the ownership of the lock. If it was successful it returns a MutexGuard packed inside an Option, if the lock is already owned by someone else it returns None. If the previously owning thread has died and MutexThreadTerminationBehavior::ReleaseWhenLocked was set it returns the error MutexLockError::LockAcquiredButOwnerDied which contains also the MutexGuard. The new owner now has the responsibility to either repair the underlying value of the mutex and call Mutex::make_consistent() when it is repaired or to undertake other measures when it is unrepairable.

source

pub fn timed_lock( &self, duration: Duration, ) -> Result<Option<MutexGuard<'_, '_, T>>, MutexTimedLockError<'_, '_, T>>

Tries to acquire the ownership of the lock until the provided timeout has elapsed. If it was successful it returns a MutexGuard packed inside an Option, if the could not be acquired lock when the timeout passed it returns None. If the previously owning thread has died and MutexThreadTerminationBehavior::ReleaseWhenLocked was set it returns the error MutexTimedLockError::MutexLockError which contains also the MutexGuard. The new owner now has the responsibility to either repair the underlying value of the mutex and call Mutex::make_consistent() when it is repaired or to undertake other measures when it is unrepairable.

source

pub fn make_consistent(&self)

If the previously owning thread has died and MutexThreadTerminationBehavior::ReleaseWhenLocked was set it returns the error MutexLockError::LockAcquiredButOwnerDied which contains also the MutexGuard. The new owner now has the responsibility to either repair the underlying value of the mutex and call Mutex::make_consistent() when it is repaired or to undertake other measures when it is unrepairable.

source

pub fn priority_ceiling(&self) -> Result<i32, MutexGetPrioCeilingError>

Returns the current priority ceiling of the mutex.

source

pub fn set_priority_ceiling( &self, value: i32, ) -> Result<i32, MutexSetPrioCeilingError>

Sets a new priority ceiling for the mutex and returns the old value.

Trait Implementations§

source§

impl<'a, T> Debug for Mutex<'a, T>
where T: Debug,

source§

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

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

impl<'a, T> IpcCapable<'a, MutexHandle<T>> for Mutex<'a, T>
where T: Debug,

source§

fn is_interprocess_capable(&self) -> bool

Returns true if the object is interprocess capable, otherwise false
source§

unsafe fn from_ipc_handle(handle: &'a T) -> Self

Creates an IPC Capable object from its handle. Read more
source§

impl<T> Send for Mutex<'_, T>
where T: Send + Debug,

source§

impl<T> Sync for Mutex<'_, T>
where T: Send + Debug,

Auto Trait Implementations§

§

impl<'a, T> Freeze for Mutex<'a, T>

§

impl<'a, T> !RefUnwindSafe for Mutex<'a, T>

§

impl<'a, T> Unpin for Mutex<'a, T>

§

impl<'a, T> !UnwindSafe for Mutex<'a, T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

source§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.