mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
41 lines
617 B
C++
41 lines
617 B
C++
#pragma once
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
#include <mutex>
|
|
|
|
namespace chatterino {
|
|
|
|
template <typename T>
|
|
class MutexValue : boost::noncopyable
|
|
{
|
|
public:
|
|
MutexValue()
|
|
{
|
|
}
|
|
|
|
MutexValue(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;
|
|
}
|
|
|
|
private:
|
|
mutable std::mutex mutex_;
|
|
T value_;
|
|
};
|
|
|
|
} // namespace chatterino
|