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

Constructs a new raw spinlock.

Safety

The caller must call RawSpinLock::init_lock before using the raw spinlock.

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.

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

The type of the data protected by the lock.

The type of context, if any, that needs to be stored in the guard.

Acquires the lock, making the caller its owner.

Releases the lock, giving up ownership of the lock. Read more

Returns the data protected by the lock.

Reacquires the lock, making the caller its owner. Read more

The parametrised type of the mutual exclusion primitive that can be created by this factory.

Constructs a new instance of the mutual exclusion primitive. Read more

Initialises the lock instance so that it can be safely used.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Initialises the type instance so that it can be safely used. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This documentation is an old archive. Please see https://rust.docs.kernel.org instead.