Struct rustrt::mutex::NativeMutex[src]

pub struct NativeMutex {
    // some fields omitted
}

A native mutex with a destructor for clean-up.

See StaticNativeMutex for a version that is suitable for storing in statics.

Methods

impl NativeMutex

unsafe fn new() -> NativeMutex

Creates a new mutex.

The user must be careful to ensure the mutex is not locked when its is being destroyed. Also it is important to avoid locking until mutex has stopped moving

unsafe fn lock<'a>(&'a self) -> LockGuard<'a>

Acquires this lock. This assumes that the current thread does not already hold the lock.

Example

use std::rt::mutex::NativeMutex;
unsafe {
    let mut lock = NativeMutex::new();

    {
        let _guard = lock.lock();
        // critical section...
    } // automatically unlocked in `_guard`'s destructor
}

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::lock.

unsafe fn trylock<'a>(&'a self) -> Option<LockGuard<'a>>

Attempts to acquire the lock. The value returned is Some if the attempt succeeded.

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::trylock.

unsafe fn lock_noguard(&self)

Acquire the lock without creating a LockGuard.

These needs to be paired with a call to .unlock_noguard. Prefer using .lock.

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::lock_noguard.

unsafe fn trylock_noguard(&self) -> bool

Attempts to acquire the lock without creating a LockGuard. The value returned is whether the lock was acquired or not.

If true is returned, this needs to be paired with a call to .unlock_noguard. Prefer using .trylock.

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::trylock_noguard.

unsafe fn unlock_noguard(&self)

Unlocks the lock. This assumes that the current thread already holds the lock.

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::unlock_noguard.

unsafe fn wait_noguard(&self)

Block on the internal condition variable.

This function assumes that the lock is already held. Prefer using LockGuard.wait since that guarantees that the lock is held.

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::wait_noguard.

unsafe fn signal_noguard(&self)

Signals a thread in wait to wake up

Unsafety

This method is unsafe due to the same reasons as StaticNativeMutex::signal_noguard.

Trait Implementations

impl Drop for NativeMutex

fn drop(&mut self)