[][src]Struct ruspiro_lock::semaphore::Semaphore

#[repr(C)]
pub struct Semaphore { /* fields omitted */ }

Methods

impl Semaphore[src]

pub const fn new(initial: u32) -> Semaphore[src]

Instantiate a new semaphore with a given initial value

Example

    let mut sema = Semaphore::new(5); // semaphore could be used/aquired 5 times

pub 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 increased

pub 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 1

pub fn try_down(&self) -> Result<(), &'static str>[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

impl Debug for Semaphore[src]

impl Send for Semaphore[src]

impl Sync for Semaphore[src]

Auto Trait Implementations

impl Unpin for Semaphore

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]