// 通用库
namespace Common
{
namespace Thread
{
// 线程安全通用数值类型
template <typename Type>
class CThreadNum : public CThreadData<Type>
{
public:
CThreadNum() {}
~CThreadNum() {}
// 重载+=操作符
CThreadNum& operator +=(const Type& data)
{
pthread_mutex_lock(&this->m_lock);
this->m_data = this->m_data + data;
pthread_mutex_unlock(&this->m_lock);
return *this;
}
// 重载-=操作符
CThreadNum& operator -=(const Type& data)
{
pthread_mutex_lock(&this->m_lock);
this->m_data = this->m_data - data;
pthread_mutex_unlock(&this->m_lock);
return *this;
}
};
}
}
线程安全通用数值类型类
最新推荐文章于 2023-06-24 11:37:23 发布