ARWLock Class Reference

#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.

公共成员函数

  ARWLock ()
  ~ARWLock ()
void  ReadLock ()
void  ReadUnlock ()
void  WriteLock ()
void  WriteUnlock ()
MAXON_WARN_UNUSED Bool   AttemptWriteLock ()

私有成员函数

  MAXON_DISALLOW_COPY_AND_ASSIGN ( ARWLock )

Private Attributes

ARWArray *  _reader
Int16   _readerIndex
Int16   _readerOffset
UChar   _readerSetMask
UChar   _readerClearMask
Int16   _dummy
Spinlock _writer

构造函数 & 析构函数文档编制

◆  ARWLock()

ARWLock ( )

◆  ~ARWLock()

~ ARWLock ( )

成员函数文档编制

◆  MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( ARWLock   )
private

◆  ReadLock()

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.

◆  ReadUnlock()

void ReadUnlock ( )

Balances a preceding ReadLock() when the reading thread has finished. Creates a memory barrier. THREADSAFE.

◆  WriteLock()

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.

◆  WriteUnlock()

void WriteUnlock ( )

Balances a preceding WriteLock() when the writing thread has finished. Creates a memory barrier. THREADSAFE.

◆  AttemptWriteLock()

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.

返回
True if successful. THREADSAFE.

Member Data Documentation

◆  _reader

ARWArray* _reader private

◆  _readerIndex

Int16 _readerIndex
private

◆  _readerOffset

Int16 _readerOffset
private

◆  _readerSetMask

UChar _readerSetMask
private

◆  _readerClearMask

UChar _readerClearMask
private

◆  _dummy

Int16 _dummy
private

◆  _writer

Spinlock * _writer
private