Commit e1393143 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

fix unique_lock<DistributedMutex>::operator=

Summary: It is required to unlock a held lock, if it owns one.

Reviewed By: aary

Differential Revision: D28704148

fbshipit-source-id: c329a3045fa27985fdec4142f00fe11c95394779
parent bf8f5e1c
......@@ -76,6 +76,9 @@ ProxyLockableUniqueLock<Mutex>::ProxyLockableUniqueLock(
template <typename Mutex>
ProxyLockableUniqueLock<Mutex>& ProxyLockableUniqueLock<Mutex>::operator=(
ProxyLockableUniqueLock&& other) noexcept {
if (owns_lock()) {
unlock();
}
proxy_ = std::move(other.proxy_);
mutex_ = std::exchange(other.mutex_, nullptr);
return *this;
......
......@@ -125,6 +125,16 @@ TEST_F(ProxyLockableTest, UniqueLockConstructMoveConstructAssign) {
EXPECT_FALSE(one.proxy());
EXPECT_EQ(mutex.locked_, 1);
four = std::move(three);
EXPECT_EQ(mutex.locked_, 0);
EXPECT_FALSE(four.mutex());
EXPECT_FALSE(four.proxy());
four = ProxyLockableUniqueLock<MockMutex>{mutex};
EXPECT_EQ(mutex.locked_, 1);
EXPECT_TRUE(four.mutex());
EXPECT_TRUE(four.proxy());
}
TEST_F(ProxyLockableTest, UniqueLockDeferLock) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment