mirror-chatterino2/src/common/Atomic.hpp
pajlada 877a4e05fa
Remove boost::noncopyable use & boost::random dependency (#4776)
The use has been removed from the following files:
* Atomic.hpp
* SignalVector.hpp
* Benchmark.hpp
* IvrApi
* LoggingChannel.hpp
* Singleton.hpp
* Image.hpp
* PrecompiledHeader.hpp
* Message.hpp
* MessageElement.hpp
* MessageLayout.hpp
* MessageLayoutElement.hpp
* Fonts.hpp (just include)
2023-09-09 10:23:20 +00:00

50 lines
804 B
C++

#pragma once
#include <mutex>
namespace chatterino {
template <typename T>
class Atomic
{
public:
Atomic() = default;
Atomic(T &&val)
: value_(val)
{
}
Atomic(const Atomic &) = delete;
Atomic &operator=(const Atomic &) = delete;
Atomic(Atomic &&) = delete;
Atomic &operator=(Atomic &&) = delete;
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