mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
48 lines
697 B
C++
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
|