From 686093886a4c69c54ec03200c3a8cf7f53cc844b Mon Sep 17 00:00:00 2001 From: Danila Klimenko Date: Fri, 22 May 2015 15:01:00 +0200 Subject: [PATCH] UniqueLock class: fixed documentation; updated unit test for the "Swap" method --- base_cpp/include/embb/base/mutex.h | 2 +- base_cpp/test/mutex_test.cc | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/base_cpp/include/embb/base/mutex.h b/base_cpp/include/embb/base/mutex.h index 5844ac3..1d63027 100644 --- a/base_cpp/include/embb/base/mutex.h +++ b/base_cpp/include/embb/base/mutex.h @@ -439,7 +439,7 @@ class UniqueLock { void Unlock(); /** - * Exchanges ownership of the wrapped mutexes with another lock. + * Exchanges ownership of the wrapped mutex with another lock. */ void Swap( UniqueLock& other diff --git a/base_cpp/test/mutex_test.cc b/base_cpp/test/mutex_test.cc index 7364670..48cc0a9 100644 --- a/base_cpp/test/mutex_test.cc +++ b/base_cpp/test/mutex_test.cc @@ -191,29 +191,21 @@ void MutexTest::TestUniqueLock() { } { // Test lock swapping - // Create a second mutex to swap with - Mutex another_mutex; - UniqueLock<> lock1(another_mutex); + UniqueLock<> lock1(mutex_); PT_EXPECT_EQ(lock1.OwnsLock(), true); { - UniqueLock<> lock2(mutex_); - PT_EXPECT_EQ(lock2.OwnsLock(), true); + UniqueLock<> lock2; + PT_EXPECT_EQ(lock2.OwnsLock(), false); lock1.Swap(lock2); - PT_EXPECT_EQ(lock1.OwnsLock(), true); + PT_EXPECT_EQ(lock1.OwnsLock(), false); PT_EXPECT_EQ(lock2.OwnsLock(), true); } - // At this point, lock2 was destroyed and "another_mutex" must be unlocked - UniqueLock<> lock3(another_mutex, embb::base::try_lock); + // At this point, "lock2" was destroyed and "mutex_" must be unlocked. + UniqueLock<> lock3(mutex_, embb::base::try_lock); 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); } } -- libgit2 0.26.0