[−][src]Struct ruspiro_lock::Semaphore
Simple counting blocking or non-blocking lock
Methods
impl Semaphore[src]
pub const fn new(initial: u16) -> Semaphore[src]
Instantiate a new semaphore with a given initial value
Example
let mut sema = Semaphore::new(5); // semaphore could be used/aquired 5 timespub fn up(&self)[src]
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 increasedpub fn down(&self)[src]
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 1pub fn try_down(&self) -> Result<(), ()>[src]
try to decrease a semaphore for usage. Returns [Ok()] if the semaphore could be used.
Example
let sema = Semaphore::new(0);
if sema.try_down().is_ok() {
// do something... the counter of the semaphore has been decreased by 1
}Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,