[−][src]Struct ruspiro_lock::semaphore::Semaphore
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(&mut 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(&mut 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 mut 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(&mut self) -> Result<(), &'static str>
[src]
try to decrease a semaphore for usage. Returns [Ok()] if the semaphore could be used.
Example
let mut sema = Semaphore::new(0); if sema.try_down().is_ok() { // do something... the counter of the semaphore has been decreased by 1 }
Auto Trait Implementations
Blanket Implementations
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,