#include <arwlock.h>
The ARWLock class implements an asymmetric read write lock. It's a mutex that allows access of multiple readers or one exclusive writer. The readers are preferred and the writes are slower. The read to write ratio should at least be 10 : 1, with more writes its only marginally faster or even slower than a RWSpinlock.
In contrast to RWSpinlock this scales when multiple readers are locking and performance does not degrade. This comes at the cost of a slightly higher overhead and more memory (about 128 to 256 bytes are used for the ARWLock, depending on the number of threads).
THREADSAFE.
Public Member Functions | |
| ARWLock () | |
| ~ARWLock () | |
| void | ReadLock () |
| void | ReadUnlock () |
| void | WriteLock () |
| void | WriteUnlock () |
| MAXON_WARN_UNUSED Bool | AttemptWriteLock () |
Private Member Functions | |
| MAXON_DISALLOW_COPY_AND_ASSIGN (ARWLock) | |
Private Attributes | |
| ARWArray * | _reader |
| Int16 | _readerIndex |
| Int16 | _readerOffset |
| UChar | _readerSetMask |
| UChar | _readerClearMask |
| Int16 | _dummy |
| Spinlock * | _writer |
| ARWLock | ( | ) |
| ~ARWLock | ( | ) |
|
private |
| void ReadLock | ( | ) |
Read locks a user level spin lock. Does not trash other thread's cache lines or force synchronization. If a write is pending an exponential backoff pause loop is used to wait. Creates a memory barrier. THREADSAFE.
| void ReadUnlock | ( | ) |
Balances a preceding ReadLock() when the reading thread has finished. Creates a memory barrier. 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.
| MAXON_WARN_UNUSED 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.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |