39 #ifndef BLOCXX_GENERIC_RWLOCK_IMPL_HPP_INCLUDE_GUARD_
40 #define BLOCXX_GENERIC_RWLOCK_IMPL_HPP_INCLUDE_GUARD_
41 #include "blocxx/BLOCXX_config.h"
54 namespace BLOCXX_NAMESPACE
63 template <
typename IdT,
typename CompareT>
120 typedef std::map<IdT, LockerInfo, CompareT>
IdMap;
129 template <
typename IdT,
typename CompareT>
137 template <
typename IdT,
typename CompareT>
142 template <
typename IdT,
typename CompareT>
149 typename IdMap::iterator info = m_lockerInfo.find(
id);
151 if (info != m_lockerInfo.end())
161 while (!m_canRead || m_numWriters > 0)
173 m_lockerInfo.insert(
typename IdMap::value_type(
id, lockerInfo));
179 template <
typename IdT,
typename CompareT>
185 typename IdMap::iterator pInfo = m_lockerInfo.find(
id);
187 if (pInfo == m_lockerInfo.end() || !pInfo->second.isReader())
198 if (m_numReaders == 0)
202 m_waiting_writers.notifyAll();
204 m_lockerInfo.erase(pInfo);
209 template <
typename IdT,
typename CompareT>
233 typename IdMap::iterator pInfo = m_lockerInfo.find(
id);
234 if (pInfo != m_lockerInfo.end())
245 if (m_numWriters == 1)
257 while (m_numReaders != 0)
268 if (m_numWriters == 0)
270 m_waiting_readers.notifyAll();
283 while (m_numReaders != 0 || m_numWriters != 0)
291 if (m_numWriters == 0)
293 m_waiting_readers.notifyAll();
302 m_lockerInfo.insert(
typename IdMap::value_type(
id, ti));
310 template <
typename IdT,
typename CompareT>
316 typename IdMap::iterator pInfo = m_lockerInfo.find(
id);
318 if (pInfo == m_lockerInfo.end() || !pInfo->second.isWriter())
344 m_waiting_writers.notifyOne();
345 m_lockerInfo.erase(pInfo);
347 m_waiting_readers.notifyAll();
void releaseWriteLock(const IdT id)
void acquireWriteLock(const IdT id, const Timeout &timeout)
void acquireReadLock(const IdT id, const Timeout &timeout)
Timeout asAbsoluteTimeout() const
Converts the timer to an absolute timeout.
A TimeoutTimer is used by an algorithm to determine when a timeout has expired.
std::map< IdT, LockerInfo, CompareT > IdMap
This class is the implementation of the read/write lock.
#define BLOCXX_ASSERT(CON)
BLOCXX_ASSERT works similar to the assert() macro, but instead of calling abort(), it throws an AssertionException.
NonRecursiveMutex m_guard
GenericRWLockImpl & operator=(const GenericRWLockImpl &)
A timeout can be absolute, which means that it will happen at the specified DateTime.
Condition m_waiting_writers
void releaseReadLock(const IdT id)
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...
Note that descriptions of what exceptions may be thrown assumes that object is used correctly...
Note that descriptions of what exceptions may be thrown assumes that object is used correctly...
Condition m_waiting_readers
The Condition class represents a synchronization device that allows threads to suspend execution and ...