[][src]Struct greenie::common::mutex::Mutex

pub struct Mutex { /* fields omitted */ }

A mutual exclusion primitive useful for protecting shared data

This mutex will block threads waiting for the lock to become available. The mutex can also be statically initialized or created via a new constructor. Each mutex has a type parameter which represents the data that it is protecting. The data can only be accessed through the RAII guards returned from lock and try_lock, which guarantees that the data is only ever accessed when the mutex is locked.

Methods

impl Mutex[src]

pub fn new() -> Self[src]

Creates a new mutex in an unlocked state ready for use.

pub fn lock(&self)[src]

Acquires a mutex, blocking the current thread until it is able to do so.

This function will block the local thread until it is available to acquire the mutex. Upon returning, the thread is the only thread with the lock held. An RAII guard is returned to allow scoped unlock of the lock. When the guard goes out of scope, the mutex will be unlocked.

The exact behavior on locking a mutex in the thread which already holds the lock is left unspecified. However, this function will not return on the second call (it might panic or deadlock, for example).

pub fn try_lock(&self) -> bool[src]

Attempts to acquire this lock. If the lock could not be acquired at this time, then false is returned. Otherwise, true is returned. This function does not block.

pub fn unlock(&self)[src]

Unlock current mutex.

Panics

Panics if somebody tries to unlock mutex from another thread

Trait Implementations

impl Clone for Mutex[src]

impl Drop for Mutex[src]

impl Eq for Mutex[src]

impl PartialEq<Mutex> for Mutex[src]

impl StructuralEq for Mutex[src]

impl StructuralPartialEq for Mutex[src]

Auto Trait Implementations

impl !RefUnwindSafe for Mutex

impl !Send for Mutex

impl !Sync for Mutex

impl Unpin for Mutex

impl !UnwindSafe for Mutex

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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.