Open Search
    ARWLock Class Reference

    #include <arwlock.h>

    Detailed Description

    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
     

    Constructor & Destructor Documentation

    ◆ ARWLock()

    ARWLock ( )

    ◆ ~ARWLock()

    ~ARWLock ( )

    Member Function Documentation

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

    Returns
    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