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

try to decrease a semaphore for usage. Returns [value@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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.