2018-05-25 13:53:55 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-22 23:24:45 +02:00
|
|
|
#include <boost/noncopyable.hpp>
|
2018-05-25 13:53:55 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
template <typename T>
|
2018-06-22 23:24:45 +02:00
|
|
|
class MutexValue : boost::noncopyable
|
2018-05-25 13:53:55 +02:00
|
|
|
{
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
T value;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|