Struct bitflags::__core::sync::StaticMutex
[−]
[src]
pub struct StaticMutex { // some fields omitted }
static_mutex
): may be merged with Mutex in the future
The static mutex type is provided to allow for static allocation of mutexes.
Note that this is a separate type because using a Mutex correctly means that
it needs to have a destructor run. In Rust, statics are not allowed to have
destructors. As a result, a StaticMutex
has one extra method when compared
to a Mutex
, a destroy
method. This method is unsafe to call, and
documentation can be found directly on the method.
Examples
#![feature(static_mutex)] use std::sync::{StaticMutex, MUTEX_INIT}; static LOCK: StaticMutex = MUTEX_INIT; { let _g = LOCK.lock().unwrap(); // do some productive work } // lock is unlocked here.
Methods
impl StaticMutex
fn new() -> StaticMutex
static_mutex
): may be merged with Mutex in the future
Creates a new mutex in an unlocked state ready for use.
fn lock(&'static self) -> Result<MutexGuard<'static, ()>, PoisonError<MutexGuard<'static, ()>>>
static_mutex
): may be merged with Mutex in the future
Acquires this lock, see Mutex::lock
fn try_lock(&'static self) -> Result<MutexGuard<'static, ()>, TryLockError<MutexGuard<'static, ()>>>
static_mutex
): may be merged with Mutex in the future
Attempts to grab this lock, see Mutex::try_lock
unsafe fn destroy(&'static self)
static_mutex
): may be merged with Mutex in the future
Deallocates resources associated with this static mutex.
This method is unsafe because it provides no guarantees that there are no active users of this mutex, and safety is not guaranteed if there are active users of this mutex.
This method is required to ensure that there are no memory leaks on all platforms. It may be the case that some platforms do not leak memory if this method is not called, but this is not guaranteed to be true on all platforms.