Commit 68609388 by Danila Klimenko

UniqueLock class: fixed documentation; updated unit test for the "Swap" method

parent 256a0f82
...@@ -439,7 +439,7 @@ class UniqueLock { ...@@ -439,7 +439,7 @@ class UniqueLock {
void Unlock(); void Unlock();
/** /**
* Exchanges ownership of the wrapped mutexes with another lock. * Exchanges ownership of the wrapped mutex with another lock.
*/ */
void Swap( void Swap(
UniqueLock<Mutex>& other UniqueLock<Mutex>& other
......
...@@ -191,29 +191,21 @@ void MutexTest::TestUniqueLock() { ...@@ -191,29 +191,21 @@ void MutexTest::TestUniqueLock() {
} }
{ // Test lock swapping { // Test lock swapping
// Create a second mutex to swap with UniqueLock<> lock1(mutex_);
Mutex another_mutex;
UniqueLock<> lock1(another_mutex);
PT_EXPECT_EQ(lock1.OwnsLock(), true); PT_EXPECT_EQ(lock1.OwnsLock(), true);
{ {
UniqueLock<> lock2(mutex_); UniqueLock<> lock2;
PT_EXPECT_EQ(lock2.OwnsLock(), true); PT_EXPECT_EQ(lock2.OwnsLock(), false);
lock1.Swap(lock2); lock1.Swap(lock2);
PT_EXPECT_EQ(lock1.OwnsLock(), true); PT_EXPECT_EQ(lock1.OwnsLock(), false);
PT_EXPECT_EQ(lock2.OwnsLock(), true); PT_EXPECT_EQ(lock2.OwnsLock(), true);
} }
// At this point, lock2 was destroyed and "another_mutex" must be unlocked // At this point, "lock2" was destroyed and "mutex_" must be unlocked.
UniqueLock<> lock3(another_mutex, embb::base::try_lock); UniqueLock<> lock3(mutex_, embb::base::try_lock);
PT_EXPECT_EQ(lock3.OwnsLock(), true); PT_EXPECT_EQ(lock3.OwnsLock(), true);
// But lock1 must still be locking "mutex_"
PT_EXPECT_EQ(lock1.OwnsLock(), true);
lock1.Release()->Unlock();
PT_EXPECT_EQ(lock1.OwnsLock(), false);
} }
} }
......
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 sign in to comment