pub struct RawSpinlock<R: Relax = Spin> { /* private fields */ }
Expand description

Provides mutual exclusion based on spinning on an AtomicBool.

It’s recommended to use this type either combination with lock_api::Mutex or through the Spinlock type.

Example

use lock_api::RawMutex;
use spinning_top::RawSpinlock;

let lock: RawSpinlock = RawSpinlock::INIT;
assert_eq!(lock.try_lock(), true); // lock it
assert_eq!(lock.try_lock(), false); // can't be locked a second time
unsafe { lock.unlock(); } // unlock it
assert_eq!(lock.try_lock(), true); // now it can be locked again

Trait Implementations§

source§

impl<R: Debug + Relax> Debug for RawSpinlock<R>

source§

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

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

impl<R: Relax> RawMutex for RawSpinlock<R>

source§

const INIT: RawSpinlock<R> = _

Initial value for an unlocked mutex.
§

type GuardMarker = GuardSend

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.

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for RawSpinlock<R>where R: RefUnwindSafe,

§

impl<R> Send for RawSpinlock<R>where R: Send,

§

impl<R> Sync for RawSpinlock<R>where R: Sync,

§

impl<R> Unpin for RawSpinlock<R>where R: Unpin,

§

impl<R> UnwindSafe for RawSpinlock<R>where R: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.
§

impl<T> Erased for T