#include <spinlock.h>

The RWSpinlock class implements a mutex that allows access of multiple readers or one exclusive writer. It will loop on a pause/idle instruction when it is already locked. This means you should only use a RWSpinlock for cases with almost no contention - otherwise you waste a lot of CPU power with idling and steal that from other tasks (and your battery). Having many concurrent readers may also noticably degrade performance because the lock is a shared resource and each read lock from a different thread will cause a write access to the RWSpinlock and requires synchronization of the CPU cores. If your problem produces a lot of contention (check scaling with more than 8 threads or profile with VTune/Instruments) it's most likely worth to rethink your approach and algorithm. Use ARWLock for high read to write ratios.
THREADSAFE.
Public Types | |
| using | RWState = typename ATOMICTYPE::Type |
Public Member Functions | |
| void | ReadLock () |
| void | ReadUnlock () |
| void | WriteLock () |
| void | WriteUnlock () |
| Bool | AttemptWriteLock () |
| Bool | IsReadLocked () const |
| Bool | IsWriteLocked () const |
Static Public Attributes | |
| static constexpr RWState | WRITER |
| static constexpr RWState | WRITER_PENDING |
| static constexpr RWState | READERS |
| static constexpr RWState | ONE_READER |
| static constexpr RWState | BUSY |
Additional Inherited Members | |
Protected Member Functions inherited from BaseLock< ATOMICTYPE > | |
| void | PerformanceMonitorLockAcquired () const |
| void | PerformanceMonitorLockReleased () const |
| BaseLock () | |
| ~BaseLock () | |
Protected Attributes inherited from BaseLock< ATOMICTYPE > | |
| ATOMICTYPE | _state |
| using RWState = typename ATOMICTYPE::Type |
| void ReadLock | ( | ) |
Read locks a user level spin lock. Will force synchronization when multiple readers are pending: Does not scale! Creates a memory barrier. If a write is pending an exponential backoff pause loop is used to wait. THREADSAFE.
| void ReadUnlock | ( | ) |
Balances a preceding ReadLock() when the reading thread has finished. THREADSAFE.
| void WriteLock | ( | ) |
Write locks a user level spin lock. As long as there are pending readers an exponential backoff pause loop is used to wait. Creates a memory barrier. THREADSAFE.
| void WriteUnlock | ( | ) |
Balances a preceding WriteLock() when the writing thread has finished. Creates a memory barrier. THREADSAFE.
| Bool AttemptWriteLock | ( | ) |
Tries to write lock. Creates a memory barrier if the lock can be taken. Immediately returns with false if there are pending reads or writes.
| Bool IsReadLocked | ( | ) | const |
Returns true if read-locked or false if unlocked (for diagnostics only). THREADSAFE.
| Bool IsWriteLocked | ( | ) | const |
Returns true if write-locked or false if unlocked (for diagnostics only). THREADSAFE.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |