Pigweed
 
Loading...
Searching...
No Matches
pw::sync::InterruptSpinLock Class Reference

#include <interrupt_spin_lock.h>

Public Types

using native_handle_type = backend::NativeInterruptSpinLockHandle
 

Public Member Functions

 InterruptSpinLock (const InterruptSpinLock &)=delete
 
 InterruptSpinLock (InterruptSpinLock &&)=delete
 
InterruptSpinLockoperator= (const InterruptSpinLock &)=delete
 
InterruptSpinLockoperator= (InterruptSpinLock &&)=delete
 
void lock ()
 
bool try_lock ()
 
void unlock ()
 
native_handle_type native_handle ()
 

Detailed Description

The InterruptSpinLock is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads and/or interrupts as a targeted global lock, with the exception of Non-Maskable Interrupts (NMIs). It offers exclusive, non-recursive ownership semantics where IRQs up to a backend defined level of "NMIs" will be masked to solve priority-inversion.

Note
This InterruptSpinLock relies on built-in local interrupt masking to make it interrupt safe without requiring the caller to separately mask and unmask interrupts when using this primitive.

Unlike global interrupt locks, this also works safely and efficiently on SMP systems. On systems which are not SMP, spinning is not required and it's possible that only interrupt masking occurs but some state may still be used to detect recursion.

This entire API is IRQ safe, but NOT NMI safe.

Precondition: Code that holds a specific InterruptSpinLock must not try to re-acquire it. However, it is okay to nest distinct spinlocks.

Member Function Documentation

◆ lock()

void pw::sync::InterruptSpinLock::lock ( )

Locks the spinlock, blocking indefinitely. Failures are fatal.

Precondition: Recursive locking is undefined behavior.

◆ try_lock()

bool pw::sync::InterruptSpinLock::try_lock ( )

Tries to lock the spinlock in a non-blocking manner. Returns true if the spinlock was successfully acquired.

Precondition: Recursive locking is undefined behavior.

◆ unlock()

void pw::sync::InterruptSpinLock::unlock ( )

Unlocks the spinlock. Failures are fatal.

Precondition: The spinlock is held by the caller.


The documentation for this class was generated from the following file: