summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-03-31 10:21:18 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-31 21:15:44 +0200
commitdd49e09e4a96635638ad674a337f8f95928ae277 (patch)
treed10e4bfd0774df91a3c6332dbebfad521354afe4
parentb3ed57f43d0fc18de5ac2610eabc5a97d9eea4a8 (diff)
Added explicit cpy/mv assign operators to be sure about thread-safety of Group<T>
-rw-r--r--src/syncedsettings.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/syncedsettings.h b/src/syncedsettings.h
index e60eb78..4991627 100644
--- a/src/syncedsettings.h
+++ b/src/syncedsettings.h
@@ -76,7 +76,6 @@ public:
: mutex{}
, data{}
{
- std::lock_guard<std::mutex> lock{mutex};
std::lock_guard<std::mutex> lock{other.mutex};
data = other.data;
}
@@ -85,11 +84,32 @@ public:
: mutex{}
, data{}
{
- std::lock_guard<std::mutex> lock{mutex};
std::lock_guard<std::mutex> lock{other.mutex};
std::swap(data, other.data);
}
+ Group<T>& operator=(const Group<T>& other)
+ {
+ if (*this != &other)
+ {
+ std::lock_guard<std::mutex> lock{mutex};
+ std::lock_guard<std::mutex> lock{other.mutex};
+ data = other.data;
+ }
+ return *this;
+ }
+
+ Group<T>& operator=(Group<T>&& other)
+ {
+ if (*this != &other)
+ {
+ std::lock_guard<std::mutex> lock{mutex};
+ std::lock_guard<std::mutex> lock{other.mutex};
+ std::swap(data, tmp.data);
+ }
+ return *this;
+ }
+
operator T() const
{
std::lock_guard<std::mutex> lock{mutex};