pub struct Semaphore { /* private fields */ }Expand description
Counting semaphore.
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub fn new(initial: u32, max: u32) -> Result<Self>
pub fn new(initial: u32, max: u32) -> Result<Self>
Create a counting semaphore via heap allocation (only in heap mode).
Sourcepub fn create(
storage: &'static SemaphoreStorage,
initial: u32,
max: u32,
) -> Result<Self>
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.
Sourcepub fn acquire(&self) -> Result<()>
pub fn acquire(&self) -> Result<()>
Acquire one permit, blocking indefinitely. tokio::sync::Semaphore::acquire
analog (sans .await).
Sourcepub fn try_acquire(&self) -> Result<()>
pub fn try_acquire(&self) -> Result<()>
Attempt to acquire one permit without blocking.
§Errors
Returns Error::WouldBlock if no permit is available.
Sourcepub fn try_acquire_for(&self, d: Duration) -> Result<()>
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.
Sourcepub fn try_acquire_until(&self, deadline: Instant) -> Result<()>
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.
Sourcepub fn release(&self)
pub fn release(&self)
Release one permit. tokio::sync::Semaphore::add_permits(1) /
embassy_sync::Semaphore::release(1) analog.
Sourcepub fn release_n(&self, n: u32)
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.
Sourcepub unsafe fn set_notify(
&self,
cb: Option<unsafe extern "C" fn(*mut c_void)>,
user_data: *mut c_void,
) -> Result<()>
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.