From dd49e09e4a96635638ad674a337f8f95928ae277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Thu, 31 Mar 2016 10:21:18 +0200 Subject: Added explicit cpy/mv assign operators to be sure about thread-safety of Group --- src/syncedsettings.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/syncedsettings.h') 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 lock{mutex}; std::lock_guard lock{other.mutex}; data = other.data; } @@ -85,11 +84,32 @@ public: : mutex{} , data{} { - std::lock_guard lock{mutex}; std::lock_guard lock{other.mutex}; std::swap(data, other.data); } + Group& operator=(const Group& other) + { + if (*this != &other) + { + std::lock_guard lock{mutex}; + std::lock_guard lock{other.mutex}; + data = other.data; + } + return *this; + } + + Group& operator=(Group&& other) + { + if (*this != &other) + { + std::lock_guard lock{mutex}; + std::lock_guard lock{other.mutex}; + std::swap(data, tmp.data); + } + return *this; + } + operator T() const { std::lock_guard lock{mutex}; -- cgit v1.2.3