Mutex8Guard

Struct Mutex8Guard 

Source
pub struct Mutex8Guard<'a> { /* private fields */ }
Expand description

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§

Source§

impl Mutex8Guard<'_>

Source

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

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());
}
Source

pub fn lock_bits(&self) -> u8

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§

Source§

impl Debug for Mutex8Guard<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Mutex8Guard<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Mutex8Guard<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Mutex8Guard<'a>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.