Skip to main content

Semaphore

Struct Semaphore 

Source
pub struct Semaphore { /* private fields */ }
Expand description

Counting semaphore.

Implementations§

Source§

impl Semaphore

Source

pub fn new(initial: u32, max: u32) -> Result<Self>

Create a counting semaphore via heap allocation (only in heap mode).

Source

pub fn create( storage: &'static SemaphoreStorage, initial: u32, max: u32, ) -> Result<Self>

Create a counting semaphore that works in both heap and zero-heap modes (see Mutex::create). Heap mode ignores storage; zero-heap mode backs the handle with the caller-provided storage.

Source

pub fn acquire(&self) -> Result<()>

Acquire one permit, blocking indefinitely. tokio::sync::Semaphore::acquire analog (sans .await).

Source

pub fn try_acquire(&self) -> Result<()>

Attempt to acquire one permit without blocking.

§Errors

Returns Error::WouldBlock if no permit is available.

Source

pub fn try_acquire_for(&self, d: Duration) -> Result<()>

Attempt to acquire one permit, waiting up to d. parking_lot::Semaphore doesn’t exist; this matches the try_lock_for convention.

§Errors

Returns Error::Timeout if the duration elapses with no permit available.

Source

pub fn try_acquire_until(&self, deadline: Instant) -> Result<()>

Attempt to acquire one permit by the given deadline. Use Instant::FOREVER for an indefinite wait.

Source

pub fn release(&self)

Release one permit. tokio::sync::Semaphore::add_permits(1) / embassy_sync::Semaphore::release(1) analog.

Source

pub fn release_n(&self, n: u32)

Release n permits. Binding-side loop — substrate currently has no ove_sem_give_n, so this calls ove_sem_give n times.

Source

pub unsafe fn set_notify( &self, cb: Option<unsafe extern "C" fn(*mut c_void)>, user_data: *mut c_void, ) -> Result<()>

Register a notify callback fired after every successful release. Wraps the C-level ove_sem_set_notify.

§Safety

Same as crate::Stream::set_notify: user_data must remain valid for as long as the callback may fire, and cb must be ISR-safe.

Trait Implementations§

Source§

impl Debug for Semaphore

Source§

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

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

impl Drop for Semaphore

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Semaphore

Source§

impl Sync for Semaphore

Auto Trait Implementations§

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.