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