mirror-chatterino2/src/lockedobject.hpp
2017-06-15 23:13:01 +02:00

39 lines
555 B
C++

#pragma once
#include <mutex>
namespace chatterino {
template <typename Type>
class LockedObject
{
public:
LockedObject &operator=(const LockedObject<Type> &other)
{
this->mutex.lock();
this->data = other.getValue();
this->mutex.unlock();
return *this;
}
LockedObject &operator=(const Type &other)
{
this->mutex.lock();
this->data = other;
this->mutex.unlock();
return *this;
}
private:
Type value;
std::mutex mutex;
};
} // namespace chatterino