Avoid dead-lock if other = this

This commit is contained in:
Patrick Niklaus 2017-06-23 10:36:23 +00:00 committed by Patrick Niklaus
parent 688b1f8bef
commit 22479ff5d8

View File

@ -30,17 +30,23 @@ struct ConcurrentIDMap
ConcurrentIDMap() = default;
ConcurrentIDMap(ConcurrentIDMap &&other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
if (this != &other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
data = std::move(other.data);
data = std::move(other.data);
}
}
ConcurrentIDMap &operator=(ConcurrentIDMap &&other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
if (this != &other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
data = std::move(other.data);
data = std::move(other.data);
}
return *this;
}