// 读锁
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_;
};
C++读写锁的托管包装器
最新推荐文章于 2022-05-26 15:30:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)