mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
bytevector: do not deadlock in self-assignment
Not that this is a particularly useful use case, but it will lock up, and it should not. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
b699325a77
commit
148cc03060
@ -60,11 +60,15 @@ namespace crucible {
|
|||||||
ByteVector&
|
ByteVector&
|
||||||
ByteVector::operator=(const ByteVector &that)
|
ByteVector::operator=(const ByteVector &that)
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lock_this(m_mutex, defer_lock);
|
// If &that == this, there's no need to do anything, but
|
||||||
unique_lock<mutex> lock_that(that.m_mutex, defer_lock);
|
// especially don't try to lock the same mutex twice.
|
||||||
lock(lock_this, lock_that);
|
if (&m_mutex != &that.m_mutex) {
|
||||||
m_ptr = that.m_ptr;
|
unique_lock<mutex> lock_this(m_mutex, defer_lock);
|
||||||
m_size = that.m_size;
|
unique_lock<mutex> lock_that(that.m_mutex, defer_lock);
|
||||||
|
lock(lock_this, lock_that);
|
||||||
|
m_ptr = that.m_ptr;
|
||||||
|
m_size = that.m_size;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user