UnnamedSemaphore

Struct UnnamedSemaphore 

Source
pub struct UnnamedSemaphore<'a> { /* private fields */ }
Expand description

An unnamed semaphore which can be used process locally or for inter-process triggers.

§Example


use iceoryx2_bb_posix::semaphore::*;
use std::thread;
use iceoryx2_bb_posix::clock::*;
use core::time::Duration;

let semaphore_handle = UnnamedSemaphoreHandle::new();
let semaphore = UnnamedSemaphoreBuilder::new().create(&semaphore_handle)
    .expect("failed to create semaphore");

thread::scope(|s| {
    s.spawn(|| {
        loop {
            semaphore.blocking_wait().expect("failed to wait on semaphore");
            println!("the thread was triggered");
        }
    });

    loop {
        nanosleep(Duration::from_secs(1));
        println!("trigger thread");
        semaphore.post().expect("failed to trigger semaphore");
    }
});

Trait Implementations§

Source§

impl<'a> Debug for UnnamedSemaphore<'a>

Source§

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

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

impl<'a> IpcCapable<'a, UnnamedSemaphoreHandle> for UnnamedSemaphore<'a>

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 SemaphoreInterface for UnnamedSemaphore<'_>

Source§

fn post(&self) -> Result<(), SemaphorePostError>

Increments the semaphore by one. If the semaphore already holds the maximum supported value another post call will lead to SemaphorePostError::Overflow.
Source§

fn blocking_wait(&self) -> Result<(), SemaphoreWaitError>

Decrements the semaphore by one. If the semaphore is zero it waits until a SemaphoreInterface::post() call incremented the semaphore by one. A semaphores internal value is always greater or equal to zero.
Source§

fn try_wait(&self) -> Result<bool, SemaphoreWaitError>

Tries to decrement the semaphore by one if it is greater zero and returns true. If the semaphores internal value is zero it returns false and does not decrement the semaphore.
Source§

fn timed_wait(&self, timeout: Duration) -> Result<bool, SemaphoreTimedWaitError>

Tries to decrement the semaphore until the decrement was successful and returns true or the timeout has passed and then returns false.
Source§

fn clock_type(&self) -> ClockType

Source§

impl Send for UnnamedSemaphore<'_>

Source§

impl Sync for UnnamedSemaphore<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for UnnamedSemaphore<'a>

§

impl<'a> !RefUnwindSafe for UnnamedSemaphore<'a>

§

impl<'a> Unpin for UnnamedSemaphore<'a>

§

impl<'a> !UnwindSafe for UnnamedSemaphore<'a>

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.