blocxx
|
This class is the implementation of the read/write lock. More...
#include <GenericRWLockImpl.hpp>
Classes | |
struct | LockerInfo |
Public Member Functions | |
GenericRWLockImpl () | |
~GenericRWLockImpl () | |
void | acquireReadLock (const IdT id, const Timeout &timeout) |
void | acquireWriteLock (const IdT id, const Timeout &timeout) |
void | releaseReadLock (const IdT id) |
void | releaseWriteLock (const IdT id) |
Private Types | |
typedef std::map< IdT, LockerInfo, CompareT > | IdMap |
Private Member Functions | |
GenericRWLockImpl (const GenericRWLockImpl &) | |
GenericRWLockImpl & | operator= (const GenericRWLockImpl &) |
Private Attributes | |
Condition | m_waiting_writers |
bool | m_canRead |
Condition | m_waiting_readers |
NonRecursiveMutex | m_guard |
unsigned | m_numReaders |
unsigned | m_numWriters |
IdMap | m_lockerInfo |
This class is the implementation of the read/write lock.
It isn't thread specific and thus may be used for other types of locking, such as for transactions which may span threads, in which case the transaction would be the id. The read/write lock is recursive and also supports upgrading a read-lock to a write lock.
Definition at line 64 of file GenericRWLockImpl.hpp.
typedef std::map<IdT, LockerInfo, CompareT> BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::IdMap [private] |
Definition at line 120 of file GenericRWLockImpl.hpp.
BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::GenericRWLockImpl | ( | ) |
Definition at line 130 of file GenericRWLockImpl.hpp.
BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::~GenericRWLockImpl | ( | ) |
Definition at line 138 of file GenericRWLockImpl.hpp.
BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::GenericRWLockImpl | ( | const GenericRWLockImpl< IdT, CompareT > & | ) | [private] |
void BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireReadLock | ( | const IdT | id, |
const Timeout & | timeout | ||
) |
TimeoutException | if the lock isn't acquired within the timeout. |
Definition at line 144 of file GenericRWLockImpl.hpp.
References BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout(), BLOCXX_ASSERT, BLOCXX_THROW, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isReader(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isWriter(), m_guard, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::readCount, and BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::writeCount.
Referenced by BLOCXX_NAMESPACE::RWLocker::getReadLock().
void BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireWriteLock | ( | const IdT | id, |
const Timeout & | timeout | ||
) |
TimeoutException | if the lock isn't acquired within the timeout. |
DeadlockException | if this call would upgrade a read lock to a write lock and another id is already waiting to upgrade. If this happens, the calling thread must release it's read lock in order for forward progress to be made. |
Definition at line 211 of file GenericRWLockImpl.hpp.
References BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout(), BLOCXX_ASSERT, BLOCXX_THROW, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isReader(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isWriter(), m_guard, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::readCount, and BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::writeCount.
Referenced by BLOCXX_NAMESPACE::RWLocker::getWriteLock().
GenericRWLockImpl& BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::operator= | ( | const GenericRWLockImpl< IdT, CompareT > & | ) | [private] |
void BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::releaseReadLock | ( | const IdT | id | ) |
GenericRWLockImplException | if a read lock hasn't been acquired. |
Definition at line 181 of file GenericRWLockImpl.hpp.
References BLOCXX_THROW, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isReader(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isWriter(), m_guard, and BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::readCount.
Referenced by BLOCXX_NAMESPACE::RWLocker::releaseReadLock().
void BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::releaseWriteLock | ( | const IdT | id | ) |
GenericRWLockImplException | if a write lock hasn't been acquired. |
Definition at line 312 of file GenericRWLockImpl.hpp.
References BLOCXX_ASSERT, BLOCXX_THROW, BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isReader(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::isWriter(), m_guard, and BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::LockerInfo::writeCount.
Referenced by BLOCXX_NAMESPACE::RWLocker::releaseWriteLock().
bool BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_canRead [private] |
Definition at line 97 of file GenericRWLockImpl.hpp.
NonRecursiveMutex BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_guard [private] |
Definition at line 100 of file GenericRWLockImpl.hpp.
IdMap BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_lockerInfo [private] |
Definition at line 121 of file GenericRWLockImpl.hpp.
unsigned BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_numReaders [private] |
Definition at line 101 of file GenericRWLockImpl.hpp.
unsigned BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_numWriters [private] |
Definition at line 102 of file GenericRWLockImpl.hpp.
Condition BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_waiting_readers [private] |
Definition at line 98 of file GenericRWLockImpl.hpp.
Condition BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::m_waiting_writers [private] |
Definition at line 95 of file GenericRWLockImpl.hpp.