My Project
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParaEngine::BlockReadWriteLock Class Reference

multiple shared readers and multiple exclusive writers it favors writers over readers. More...

#include <BlockReadWriteLock.h>

Public Member Functions

void BeginRead ()
 recursive calls is possible and will be regarded as new readers at minimum cost. More...
 
void EndRead ()
 
void BeginWrite (size_t nWriterThreadId=0)
 
void EndWrite ()
 
size_t GetCurrentThreadId ()
 
bool HasWaitingWriters ()
 this function just check writer count WITHOUT using a lock. More...
 
bool HasWaitingWritersAndSingleReader ()
 
bool HasWriterLock ()
 
bool IsCurrentThreadHasWriterLock ()
 whether the current thread is holding the writer lock. More...
 
uint32 GetWritelockRecursiveDepth () const
 

Protected Member Functions

bool StartReadFromNewReader ()
 
bool StartReadFromWaitingReader ()
 
bool StartRead ()
 
bool AllowReader ()
 
bool StartWriteFromNewWriter (size_t nWriterId)
 
bool StartWrite (size_t nWriterId)
 
bool StartWriteFromWaitingWriter (size_t nWriterId)
 

Protected Attributes

uint32 m_nActiveReaders
 
uint32 m_nWaitingReaders
 
uint32 m_nWaitingWriters
 
size_t m_activeWriterId
 
uint32 m_writelock_recursive_depth
 
uint32 m_readlock_recursive_depth
 
std::condition_variable m_reader_signal
 
std::condition_variable m_writer_signal
 
std::mutex m_mutex
 

Detailed Description

multiple shared readers and multiple exclusive writers it favors writers over readers.

All lock functions are recursive of its kind. Within write lock, there can be read lock; but within read lock, there can NOT be write lock. Upgrade to write lock is not supported yet, but is possible.

This is synchronization object between main thread, the light calculation and the block IO thread. This is a special read/write lock class tailored for the situation in block rendering. it favors writers over readers. I have referred to Doug Lea's WriterPreferenceReadWriteLock class

Member Function Documentation

§ BeginRead()

void ParaEngine::BlockReadWriteLock::BeginRead ( )

recursive calls is possible and will be regarded as new readers at minimum cost.

§ HasWaitingWriters()

bool ParaEngine::BlockReadWriteLock::HasWaitingWriters ( )

this function just check writer count WITHOUT using a lock.

it is fast to call, but never rely on the result. The reader can use this function as a hint of whether writer is hungry now, and release lock for it.

§ IsCurrentThreadHasWriterLock()

bool ParaEngine::BlockReadWriteLock::IsCurrentThreadHasWriterLock ( )

whether the current thread is holding the writer lock.


The documentation for this class was generated from the following files: