[][src]Struct spin_sync::Mutex8Guard

#[must_use = "if unused the Mutex8 will immediately unlock"]pub struct Mutex8Guard<'a> { /* fields omitted */ }

An RAII implementation of a "scoped lock(s)" of a Mutex8 .

When this structure is dropped, all the lock(s) will be released at once.

Implementations

impl<'_> Mutex8Guard<'_>[src]

pub fn release(&mut self, lock_bits: u8)[src]

Releases the lock(s) partially indicated by lock_bits .

Each bit of lock_bits indicates the lock of Mutex8 . For example, '0x01' corresponds to the first lock and '0x02' does to the second lock. If 2 or more than 2 bits are set, the lock_bits means all of them. In case of '0x03', for example, it means both the first and the second locks.

If lock_bits is same to that is being holded, self releases all the locks; otherwise, the others will still be being holded after the method returns.

lock_bits must not include a bit that self is not holding.

Panics

Panics if lock_bits includes a bit that self is not holding.

Examples

use spin_sync::Mutex8;

let mutex8 = Mutex8::new();

// Acquire 0x01 and 0x02 at the same time.
let mut guard = mutex8.lock(0x03);

{
    // Fail to acquire 0x01 again.
    let e = mutex8.try_lock(0x01);
    assert!(e.is_err());

    // Fail to acquire 0x02 again.
    let e = mutex8.try_lock(0x02);
    assert!(e.is_err());
}

// Release only 0x01. (0x02 is left.)
guard.release(0x01);

{
    // Success to acquire 0x01 now.
    let o = mutex8.try_lock(0x01);
    assert!(o.is_ok());

    // Still fail to acquire 0x02.
    let e = mutex8.try_lock(0x02);
    assert!(e.is_err());
}

pub fn lock_bits(&self) -> u8[src]

Returns the bits that self is holding.

Example

use spin_sync::Mutex8;

let mutex8 = Mutex8::new();

// Acquire 0x01 and 0x02 at the same time.
let mut guard = mutex8.lock(0x03);
assert_eq!(0x03, guard.lock_bits());

// Release only 0x02. (0x01 is left.)
guard.release(0x02);
assert_eq!(0x01, guard.lock_bits());

// Release 0x01. (No lock is left.)
guard.release(0x01);
assert_eq!(0x00, guard.lock_bits());

Trait Implementations

impl<'_> Debug for Mutex8Guard<'_>[src]

impl<'_> Display for Mutex8Guard<'_>[src]

impl<'_> Drop for Mutex8Guard<'_>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Mutex8Guard<'a>

impl<'a> !Send for Mutex8Guard<'a>

impl<'a> Sync for Mutex8Guard<'a>

impl<'a> Unpin for Mutex8Guard<'a>

impl<'a> UnwindSafe for Mutex8Guard<'a>

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> ToString for T where
    T: Display + ?Sized
[src]

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.