// 读锁
template<class T>
class CReadLock
{
public:
explicit CReadLock(T& rwmutex)
: m_rwmutex_(rwmutex)
{
m_rwmutex_.LockRead();
}
virtual ~CReadLock()
{
m_rwmutex_.UnLockRead();
}
private:
CReadLock() = delete;
CReadLock(const T&) = delete;
CReadLock& operator=(const T&) = delete;
private:
T& m_rwmutex_;
};
// 写锁
template<class T>
class CWriteLock
{
public:
explicit CWriteLock(T& rwmutex)
: m_rwmutex_(rwmutex)
{
m_rwmutex_.LockWrite();
}
virtual ~CWriteLock()
{
m_rwmutex_.UnLockWrite();
}
private:
CWriteLock() = delete;
CWriteLock(const CWriteLock&) = delete;
CWriteLock& operator=(const CWriteLock&) = delete;
private:
T& m_rwmutex_;
};
|