mirror-chatterino2/src/common/Atomic.hpp
2019-09-08 22:27:57 +02:00

48 lines
697 B
C++

#pragma once
#include <boost/noncopyable.hpp>
#include <mutex>
namespace chatterino {
template <typename T>
class Atomic : boost::noncopyable
{
public:
Atomic()
{
}
Atomic(T &&val)
: value_(val)
{
}
T get() const
{
std::lock_guard<std::mutex> guard(this->mutex_);
return this->value_;
}
void set(const T &val)
{
std::lock_guard<std::mutex> guard(this->mutex_);
this->value_ = val;
}
void set(T &&val)
{
std::lock_guard<std::mutex> guard(this->mutex_);
this->value_ = std::move(val);
}
private:
mutable std::mutex mutex_;
T value_;
};
} // namespace chatterino