pub struct Semaphore { /* private fields */ }
Expand description
Atomic counting semaphore
similar to Struct tokio::sync::Semaphore
and super::Mutex
.
A semaphore can be used to
- synchronize on one or more event (e.g. interrupt)
- synchronize multiple tasks
Implementations
sourceimpl Semaphore
impl Semaphore
pub fn new(permits: usize) -> Self
sourcepub fn register(&self) -> Result<(), Error>
pub fn register(&self) -> Result<(), Error>
Allocate an event ot the semaphore.
Note: The kernel must be initialized before calling this method.
sourcepub fn try_acquire(&self) -> Result<SemaphorePermit<'_>, Error>
pub fn try_acquire(&self) -> Result<SemaphorePermit<'_>, Error>
Try to acquire a semaphore permit (non-blocking). Returns a
SemaphorePermit
or an error if no permit is available or semaphore
is poisoned.
sourcepub fn acquire(&self, timeout: u32) -> Result<SemaphorePermit<'_>, Error>
pub fn acquire(&self, timeout: u32) -> Result<SemaphorePermit<'_>, Error>
Try to acquire a semaphore permit (blocking). Returns a
SemaphorePermit
or an error if the request timed out or the semaphore
was poisoned.
Note: The timeout function is not implemented yet.
sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Number of permits that can be issued from this semaphore
pub fn add_permits(&self, n: usize)
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Semaphore
impl Send for Semaphore
impl Unpin for Semaphore
impl UnwindSafe for Semaphore
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more