Struct SemaphoreRef

Source
pub struct SemaphoreRef<'l>(/* private fields */);
Expand description

Like a sem_t * as a borrow of a semaphore that is known to be initialized and so valid to do operations on.

Implementations§

Source§

impl<'l> SemaphoreRef<'l>

Source

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

Like sem_post, and async-signal-safe like that.

It is safe for this to be called from a signal handler. That is a primary use-case for POSIX Semaphores versus other better synchronization APIs (which shouldn’t be used in signal handlers).

This synchronizes memory with respect to other threads on all successful calls. That is a primary use-case so that memory writes to other objects, sequenced before a call to this, will be visible to other threads after returning from Self::wait() (et al). If this returns an error, it is unspecified whether the invocation causes memory to be synchronized. (See: POSIX’s requirements.)

§Errors

If sem_post() does. errno is set to indicate the error. Its EINVAL case should be impossible.

Source

pub fn wait(&self) -> Result<(), ()>

Like sem_wait.

Might block the calling thread.

This synchronizes memory with respect to other threads on all successful calls. That is a primary use-case so that other threads’ memory writes to other objects, sequenced before Self::post(), will be visible to the current thread after returning from this. If this returns an error, it is unspecified whether the invocation causes memory to be synchronized. (See: POSIX’s requirements.)

§Errors

If sem_wait() does. errno is set to indicate the error. Its EINVAL case should be impossible.

Source

pub fn try_wait(&self) -> Result<(), ()>

Like sem_trywait.

Won’t block the calling thread.

This synchronizes memory with respect to other threads on all successful calls. That is a primary use-case so that other threads’ memory writes to other objects, sequenced before Self::post(), will be visible to the current thread after returning from this. If this returns an error, it is unspecified whether the invocation causes memory to be synchronized. (See: POSIX’s requirements.)

§Errors

If sem_trywait() does. errno is set to indicate the error. Its EINVAL case should be impossible.

Source

pub fn get_value(&self) -> c_int

Trait Implementations§

Source§

impl<'l> Clone for SemaphoreRef<'l>

Source§

fn clone(&self) -> SemaphoreRef<'l>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SemaphoreRef<'_>

Shows the sem_t * pointer.

Source§

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

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

impl Display for SemaphoreRef<'_>

Human-readable representation that shows the semaphore’s current count value.

Source§

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

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

impl PartialEq for SemaphoreRef<'_>

Compare by sem_t * pointer equality.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'l> Copy for SemaphoreRef<'l>

Source§

impl Eq for SemaphoreRef<'_>

Source§

impl Send for SemaphoreRef<'_>

SAFETY: Ditto.

Source§

impl Sync for SemaphoreRef<'_>

SAFETY: The POSIX Semaphores API intends for sem_t *, after the pointed-to instance is initialized, to be shared between threads and its operations are thread-safe (similar to atomic types). Our API ensures by construction that multiple threads can only operate on a sem_t * after initialization. Therefore we can expose this in Rust as having “thread-safe interior mutability”.

Auto Trait Implementations§

§

impl<'l> Freeze for SemaphoreRef<'l>

§

impl<'l> !RefUnwindSafe for SemaphoreRef<'l>

§

impl<'l> Unpin for SemaphoreRef<'l>

§

impl<'l> !UnwindSafe for SemaphoreRef<'l>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.