Struct ruspiro_lock::sync::Semaphore [−][src]
#[repr(C, align(16))]pub struct Semaphore { /* fields omitted */ }
Expand description
Simple counting blocking or non-blocking lock
Implementations
Instantiate a new semaphore with a given initial value
Example
let mut sema = Semaphore::new(5); // semaphore could be used/aquired 5 times
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 increased
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 1