Exclusive spin-based lock wrapper with explicit initialization, locking, and unlocking operations. The wrapper has no shared-lock mode or try operation.
Spinlock model
Spinlock provides only the exclusive pair lock and unlock.
- Scope helpers that rely only on exclusive locking are compatible.
- Shared locking and condition-variable waiting are unsupported.
LOCKED is 1n8 and UNLOCKED is 0n8.
lock busy-spins in the current raw thread until one atomic transition from UNLOCKED to LOCKED succeeds.
- The interface exposes no sleep-based waiting path, no waiter queue, no timeout result, and no fairness guarantee.
- In
DEBUG mode, more than MAXIMUM_SPIN_COUNT failed spin attempts are rejected through assertion.
- A
Spinlock owns one lock state. No separate lock token or guard object is produced by the wrapper itself.
Spinlock
Methods
INIT |
(--) |
Resets the lock state to UNLOCKED. |
lock |
(--) |
Acquires the lock in exclusive mode by repeatedly attempting the transition from UNLOCKED to LOCKED until one attempt succeeds. |
unlock |
(--) |
Releases one exclusive lock acquisition. |
Preconditions
- The current state is
LOCKED.
Remarks
- A newly constructed
Spinlock starts unlocked.