![]() |
SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Recursive spinlock. More...
#include <stk_sync_spinlock.h>
Public Member Functions | |
| SpinLock () | |
| Construct a SpinLock in the unlocked state. | |
| STK_VIRT_DTOR | ~SpinLock () |
| Destructor. | |
| void | Lock () |
| Acquire the lock. | |
| bool | TryLock () |
| Attempt to acquire the lock without blocking. | |
| void | Unlock () |
| Release the lock or decrement the recursion counter. | |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (SpinLock) | |
| bool | LockRecursively (TId locking_tid) |
| void | MakeLocked (TId locking_tid) |
Private Attributes | |
| TId | m_owner_tid |
| thread id of the current owner | |
| uint16_t | m_recursion_count |
| nesting depth | |
| hw::SpinLock | m_lock |
| low-level spin lock | |
Static Private Attributes | |
| static const uint16_t | RECURSION_MAX = 0xFFFEU |
| maximum nesting depth | |
Recursive spinlock.
SpinLock is a high-performance synchronization primitive intended for extremely short critical sections where the overhead of a kernel context switch (as seen in Mutex) is undesirable.
This implementation provides:
0xFFFE.Definition at line 53 of file stk_sync_spinlock.h.
|
inlineexplicit |
Construct a SpinLock in the unlocked state.
Definition at line 58 of file stk_sync_spinlock.h.
References m_owner_tid, m_recursion_count, and stk::TID_NONE.
Referenced by STK_NONCOPYABLE_CLASS().
|
inline |
Destructor.
Definition at line 66 of file stk_sync_spinlock.h.
References m_owner_tid, STK_ASSERT, STK_VIRT_DTOR, and stk::TID_NONE.
|
inlinevirtual |
Acquire the lock.
Blocks until the low-level lock is available, then takes ownership. If the calling task already owns the lock, increments the recursion counter and returns immediately without re-acquiring.
Implements stk::IMutex.
Definition at line 111 of file stk_sync_spinlock.h.
References stk::GetTid(), LockRecursively(), m_lock, and MakeLocked().
Referenced by stk_spinlock_lock().
|
inlineprivate |
Definition at line 171 of file stk_sync_spinlock.h.
References m_owner_tid, m_recursion_count, RECURSION_MAX, and STK_ASSERT.
Referenced by Lock(), and TryLock().
|
inlineprivate |
Definition at line 190 of file stk_sync_spinlock.h.
References stk::KERNEL_PANIC_ASSERT, m_owner_tid, m_recursion_count, stk::STK_KERNEL_PANIC(), and stk::TID_NONE.
Referenced by Lock(), and TryLock().
|
private |
|
inline |
Attempt to acquire the lock without blocking.
true if acquired (or already owned by the calling task); false if currently owned by another task. Definition at line 127 of file stk_sync_spinlock.h.
References stk::GetTid(), LockRecursively(), m_lock, and MakeLocked().
Referenced by stk_spinlock_trylock().
|
inlinevirtual |
Release the lock or decrement the recursion counter.
If the calling task holds the lock recursively, decrements the recursion counter and returns. On the final Unlock() the lock is fully released and becomes available to other tasks.
Implements stk::IMutex.
Definition at line 152 of file stk_sync_spinlock.h.
References stk::GetTid(), stk::hw::IsInsideISR(), m_lock, m_owner_tid, m_recursion_count, STK_ASSERT, and stk::TID_NONE.
Referenced by stk_spinlock_unlock().
|
private |
low-level spin lock
Definition at line 104 of file stk_sync_spinlock.h.
|
private |
thread id of the current owner
Definition at line 102 of file stk_sync_spinlock.h.
Referenced by LockRecursively(), MakeLocked(), SpinLock(), Unlock(), and ~SpinLock().
|
private |
nesting depth
Definition at line 103 of file stk_sync_spinlock.h.
Referenced by LockRecursively(), MakeLocked(), SpinLock(), and Unlock().
|
staticprivate |
maximum nesting depth
Definition at line 100 of file stk_sync_spinlock.h.
Referenced by LockRecursively().