Struct spinlock::BaseSpinLock

source ·
pub struct BaseSpinLock<G: BaseGuard, T: ?Sized> { /* private fields */ }
Expand description

A spin lock providing mutually exclusive access to data.

This is a base struct, the specific behavior depends on the generic parameter G that implements BaseGuard, such as whether to disable local IRQs or kernel preemption before acquiring the lock.

For single-core environment (without the “smp” feature), we remove the lock state, CPU can always get the lock if we follow the proper guard in use.

Implementations§

source§

impl<G: BaseGuard, T> BaseSpinLock<G, T>

source

pub const fn new(data: T) -> Self

Creates a new BaseSpinLock wrapping the supplied data.

source

pub fn into_inner(self) -> T

Consumes this BaseSpinLock and unwraps the underlying data.

source§

impl<G: BaseGuard, T: ?Sized> BaseSpinLock<G, T>

source

pub fn lock(&self) -> BaseSpinLockGuard<'_, G, T>

Locks the BaseSpinLock and returns a guard that permits access to the inner data.

The returned value may be dereferenced for data access and the lock will be dropped when the guard falls out of scope.

source

pub fn is_locked(&self) -> bool

Returns true if the lock is currently held.

Safety

This function provides no synchronization guarantees and so its result should be considered ‘out of date’ the instant it is called. Do not use it for synchronization purposes. However, it may be useful as a heuristic.

source

pub fn try_lock(&self) -> Option<BaseSpinLockGuard<'_, G, T>>

Try to lock this BaseSpinLock, returning a lock guard if successful.

source

pub unsafe fn force_unlock(&self)

Force unlock this BaseSpinLock.

Safety

This is extremely unsafe if the lock is not held by the current thread. However, this can be useful in some instances for exposing the lock to FFI that doesn’t know how to deal with RAII.

source

pub fn get_mut(&mut self) -> &mut T

Returns a mutable reference to the underlying data.

Since this call borrows the BaseSpinLock mutably, and a mutable reference is guaranteed to be exclusive in Rust, no actual locking needs to take place – the mutable borrow statically guarantees no locks exist. As such, this is a ‘zero-cost’ operation.

Trait Implementations§

source§

impl<G: BaseGuard, T: ?Sized + Debug> Debug for BaseSpinLock<G, T>

source§

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

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

impl<G: BaseGuard, T: ?Sized + Default> Default for BaseSpinLock<G, T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<G: BaseGuard, T: ?Sized + Send> Send for BaseSpinLock<G, T>

source§

impl<G: BaseGuard, T: ?Sized + Send> Sync for BaseSpinLock<G, T>

Auto Trait Implementations§

§

impl<G, T> !RefUnwindSafe for BaseSpinLock<G, T>

§

impl<G, T: ?Sized> Unpin for BaseSpinLock<G, T>
where G: Unpin, T: Unpin,

§

impl<G, T: ?Sized> UnwindSafe for BaseSpinLock<G, T>
where G: UnwindSafe, T: UnwindSafe,

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.