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>
impl<'a> Debug for UnnamedSemaphore<'a>
Source§impl<'a> IpcCapable<'a, UnnamedSemaphoreHandle> for UnnamedSemaphore<'a>
impl<'a> IpcCapable<'a, UnnamedSemaphoreHandle> for UnnamedSemaphore<'a>
Source§fn is_interprocess_capable(&self) -> bool
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
unsafe fn from_ipc_handle(handle: &'a T) -> Self
Creates an IPC Capable object from its handle. Read more
Source§impl SemaphoreInterface for UnnamedSemaphore<'_>
impl SemaphoreInterface for UnnamedSemaphore<'_>
Source§fn post(&self) -> Result<(), SemaphorePostError>
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>
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>
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>
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.
fn clock_type(&self) -> ClockType
impl Send for UnnamedSemaphore<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more