Struct parking_lot::raw_mutex::RawMutex

source ·
pub struct RawMutex {
    state: AtomicU8,
}
Expand description

Raw mutex type backed by the parking lot.

Fields§

§state: AtomicU8

This atomic integer holds the current state of the mutex instance. Only the two lowest bits are used. See LOCKED_BIT and PARKED_BIT for the bitmask for these bits.

§State table:

PARKED_BIT | LOCKED_BIT | Description 0 | 0 | The mutex is not locked, nor is anyone waiting for it. ———–+————+—————————————————————— 0 | 1 | The mutex is locked by exactly one thread. No other thread is | | waiting for it. ———–+————+—————————————————————— 1 | 0 | The mutex is not locked. One or more thread is parked or about to | | park. At least one of the parked threads are just about to be | | unparked, or a thread heading for parking might abort the park. ———–+————+—————————————————————— 1 | 1 | The mutex is locked by exactly one thread. One or more thread is | | parked or about to park, waiting for the lock to become available. | | In this state, PARKED_BIT is only ever cleared when a bucket lock | | is held (i.e. in a parking_lot_core callback). This ensures that | | we never end up in a situation where there are parked threads but | | PARKED_BIT is not set (which would result in those threads | | potentially never getting woken up).

Implementations§

source§

impl RawMutex

source

pub(crate) fn mark_parked_if_locked(&self) -> bool

source

pub(crate) fn mark_parked(&self)

source

fn lock_slow(&self, timeout: Option<Instant>) -> bool

source

fn unlock_slow(&self, force_fair: bool)

source

fn bump_slow(&self)

Trait Implementations§

source§

impl RawMutex for RawMutex

source§

const INIT: RawMutex = _

Initial value for an unlocked mutex.
§

type GuardMarker = GuardNoSend

Marker type which determines whether a lock guard should be Send. Use one of the GuardSend or GuardNoSend helper types here.
source§

fn lock(&self)

Acquires this mutex, blocking the current thread until it is able to do so.
source§

fn try_lock(&self) -> bool

Attempts to acquire this mutex without blocking. Returns true if the lock was successfully acquired and false otherwise.
source§

unsafe fn unlock(&self)

Unlocks this mutex. Read more
source§

fn is_locked(&self) -> bool

Checks whether the mutex is currently locked.
source§

impl RawMutexFair for RawMutex

source§

unsafe fn unlock_fair(&self)

Unlocks this mutex using a fair unlock protocol. Read more
source§

unsafe fn bump(&self)

Temporarily yields the mutex to a waiting thread if there is one. Read more
source§

impl RawMutexTimed for RawMutex

§

type Duration = Duration

Duration type used for try_lock_for.
§

type Instant = Instant

Instant type used for try_lock_until.
source§

fn try_lock_until(&self, timeout: Instant) -> bool

Attempts to acquire this lock until a timeout is reached.
source§

fn try_lock_for(&self, timeout: Duration) -> bool

Attempts to acquire this lock until a timeout is reached.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.