vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrecko::MTReadWriteLock Class Reference

#include <MTLock.h>

Public Member Functions

 MTReadWriteLock ()
 
 ~MTReadWriteLock ()
 
bool lockRead (DWORD Timeout=INFINITE)
 
bool lockWrite (DWORD Timeout=INFINITE)
 
void unlockRead (DWORD Timeout=INFINITE)
 
void unlockWrite (DWORD Timeout=INFINITE)
 

Protected Attributes

HANDLE m_Access
 
int m_Readers
 
HANDLE m_WriterMutex
 
HANDLE m_CanRead
 
HANDLE m_CanWrite
 

Detailed Description

ReadWrite locks are from the following article by Ivan Krivyakov: http://www.codeguru.com/cpp/w-p/system/misc/article.php/c5679

MTReadWriteLock is a read/write mutex.

Any number of readers can acquire the mutex for read (LockRead()). Only single writer can acquire the mutex for write (LockWrite()). No other writers or readers can hold the mutex while writer uses it.

MTReadWriteLock does not prefer neither writers nor readers. I.e. if both writers and readers are waiting for the lock, any of them can grab the lock when it is released by previous owner.

MTReadWriteLock is recursive, but not upgradable. This means that

if you have a read lock, you can safely acquire another read lock. if you have a read lock, you CANNOT acquire a write lock (deadlock!).

if you have a write lock, you can safely acquire another write lock. if you have a write lock, you CANNOT acquire a read lock (deadlock!).

Constructor & Destructor Documentation

vrecko::MTReadWriteLock::MTReadWriteLock ( )
vrecko::MTReadWriteLock::~MTReadWriteLock ( )

Member Function Documentation

MTLOCK_IMP_EXP bool vrecko::MTReadWriteLock::lockRead ( DWORD  Timeout = INFINITE)
MTLOCK_IMP_EXP bool vrecko::MTReadWriteLock::lockWrite ( DWORD  Timeout = INFINITE)
MTLOCK_IMP_EXP void vrecko::MTReadWriteLock::unlockRead ( DWORD  Timeout = INFINITE)
MTLOCK_IMP_EXP void vrecko::MTReadWriteLock::unlockWrite ( DWORD  Timeout = INFINITE)

Member Data Documentation

HANDLE vrecko::MTReadWriteLock::m_Access
protected
HANDLE vrecko::MTReadWriteLock::m_CanRead
protected
HANDLE vrecko::MTReadWriteLock::m_CanWrite
protected
int vrecko::MTReadWriteLock::m_Readers
protected
HANDLE vrecko::MTReadWriteLock::m_WriterMutex
protected

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