Struct kernel::sync::RawSpinLock
source · [−]pub struct RawSpinLock<T: ?Sized> { /* private fields */ }
Expand description
Exposes the kernel’s raw_spinlock_t
.
It is very similar to SpinLock
, except that it is guaranteed not to sleep even on RT
variants of the kernel.
Examples
struct Example {
a: u32,
b: u32,
}
// Function that acquires the raw spinlock without changing interrupt state.
fn lock_example(value: &RawSpinLock<Example>) {
let mut guard = value.lock();
guard.a = 10;
guard.b = 20;
}
// Function that acquires the raw spinlock and disables interrupts while holding it.
fn lock_irqdisable_example(value: &RawSpinLock<Example>) {
let mut guard = value.lock_irqdisable();
guard.a = 30;
guard.b = 40;
}
// Initialises a raw spinlock and calls the example functions.
fn spinlock_example() {
// SAFETY: `rawspinlock_init` is called below.
let mut value = unsafe { RawSpinLock::new(Example { a: 1, b: 2 }) };
// SAFETY: We don't move `value`.
kernel::rawspinlock_init!(unsafe { Pin::new_unchecked(&mut value) }, "value");
lock_example(&value);
lock_irqdisable_example(&value);
}
Implementations
sourceimpl<T> RawSpinLock<T>
impl<T> RawSpinLock<T>
sourcepub const unsafe fn new(t: T) -> Self
pub const unsafe fn new(t: T) -> Self
Constructs a new raw spinlock.
Safety
The caller must call RawSpinLock::init_lock
before using the raw spinlock.
sourceimpl<T: ?Sized> RawSpinLock<T>
impl<T: ?Sized> RawSpinLock<T>
sourcepub fn lock(&self) -> Guard<'_, Self, WriteLock>
pub fn lock(&self) -> Guard<'_, Self, WriteLock>
Locks the raw spinlock and gives the caller access to the data protected by it. Only one thread at a time is allowed to access the protected data.
sourcepub fn lock_irqdisable(&self) -> Guard<'_, Self, DisabledInterrupts>
pub fn lock_irqdisable(&self) -> Guard<'_, Self, DisabledInterrupts>
Locks the raw spinlock and gives the caller access to the data protected by it. Additionally it disables interrupts (if they are enabled).
When the lock in unlocked, the interrupt state (enabled/disabled) is restored.
Trait Implementations
sourceimpl<T: ?Sized> Lock<WriteLock> for RawSpinLock<T>
impl<T: ?Sized> Lock<WriteLock> for RawSpinLock<T>
type Inner = T
type Inner = T
The type of the data protected by the lock.
type GuardContext = EmptyGuardContext
type GuardContext = EmptyGuardContext
The type of context, if any, that needs to be stored in the guard.
sourcefn lock_noguard(&self) -> EmptyGuardContext
fn lock_noguard(&self) -> EmptyGuardContext
Acquires the lock, making the caller its owner.
sourceunsafe fn unlock(&self, _: &mut EmptyGuardContext)
unsafe fn unlock(&self, _: &mut EmptyGuardContext)
Releases the lock, giving up ownership of the lock. Read more
sourcefn locked_data(&self) -> &UnsafeCell<T>
fn locked_data(&self) -> &UnsafeCell<T>
Returns the data protected by the lock.
sourcefn relock(&self, ctx: &mut Self::GuardContext)
fn relock(&self, ctx: &mut Self::GuardContext)
Reacquires the lock, making the caller its owner. Read more
sourceimpl<T> LockFactory for RawSpinLock<T>
impl<T> LockFactory for RawSpinLock<T>
type LockedType<U> = RawSpinLock<U>
type LockedType<U> = RawSpinLock<U>
The parametrised type of the mutual exclusion primitive that can be created by this factory.
sourceunsafe fn new_lock<U>(data: U) -> RawSpinLock<U>
unsafe fn new_lock<U>(data: U) -> RawSpinLock<U>
Constructs a new instance of the mutual exclusion primitive. Read more
sourceimpl<T> LockIniter for RawSpinLock<T>
impl<T> LockIniter for RawSpinLock<T>
impl<T: ?Sized + Send> Send for RawSpinLock<T>
impl<T: ?Sized + Send> Sync for RawSpinLock<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for RawSpinLock<T>
impl<T> !Unpin for RawSpinLock<T>
impl<T: ?Sized> UnwindSafe for RawSpinLock<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<L> NeedsLockClass for L where
L: LockIniter,
impl<L> NeedsLockClass for L where
L: LockIniter,
sourcefn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
fn init(
self: Pin<&mut L>,
name: &'static CStr,
key: &'static LockClassKey,
&'static LockClassKey
)
Initialises the type instance so that it can be safely used. Read more