#[repr(C, align(16))]pub struct Semaphore { /* private fields */ }Expand description
Simple counting blocking or non-blocking lock
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub const fn new(initial: u32) -> Semaphore
pub const fn new(initial: u32) -> Semaphore
Instantiate a new semaphore with a given initial value
§Example
let mut sema = Semaphore::new(5); // semaphore could be used/aquired 5 timesSourcepub fn up(&self)
pub fn up(&self)
increase the inner count of a semaphore allowing it to be used as many times as the inner counters value
§Example
let mut sema = Semaphore::new(0);
sema.up(); // the counter of the semaphore will be increasedSourcepub fn down(&self)
pub fn down(&self)
decrease the inner count of a semaphore. This blocks the current core if the current count is 0 and could not beeing decreased. For an unblocking operation use Semaphore::try_down
§Example
let sema = Semaphore::new(0);
sema.down();
// if we reache this line, we have used the semaphore and decreased the counter by 1Trait Implementations§
impl Send for Semaphore
impl Sync for Semaphore
Auto Trait Implementations§
impl !Freeze for Semaphore
impl RefUnwindSafe for Semaphore
impl Unpin for Semaphore
impl UnwindSafe for Semaphore
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