BIND 10 trac2198_2, updated. 4ed683ce42d061905a4e5b06fcc1a38c64136e7a [2198] Test the non-blocking variant of Mutex::Locker
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Oct 15 04:30:03 UTC 2012
The branch, trac2198_2 has been updated
via 4ed683ce42d061905a4e5b06fcc1a38c64136e7a (commit)
from e6ac5ef47d9885e20e247697c8c3d1fe55fd2500 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4ed683ce42d061905a4e5b06fcc1a38c64136e7a
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Oct 15 09:59:22 2012 +0530
[2198] Test the non-blocking variant of Mutex::Locker
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/threads/tests/lock_unittest.cc | 39 +++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc
index 0b4d3ce..feabe3f 100644
--- a/src/lib/util/threads/tests/lock_unittest.cc
+++ b/src/lib/util/threads/tests/lock_unittest.cc
@@ -37,6 +37,45 @@ TEST(MutexTest, lockMultiple) {
Mutex::Locker l2(mutex); // Attempt to lock again.
}, isc::InvalidOperation);
EXPECT_TRUE(mutex.locked()); // Debug-only build
+
+ // block=true explicitly.
+ Mutex mutex2;
+ EXPECT_FALSE(mutex2.locked()); // Debug-only build
+ Mutex::Locker l12(mutex2, true);
+ EXPECT_TRUE(mutex2.locked()); // Debug-only build
+}
+
+void*
+testThread(Mutex* mutex)
+{
+ // This should not block indefinitely, but throw AlreadyLocked.
+ // block=false (tryLock).
+ EXPECT_THROW({
+ Mutex::Locker l3(*mutex, false);
+ }, Mutex::Locker::AlreadyLocked);
+
+ EXPECT_TRUE(mutex->locked()); // Debug-only build
+
+ return NULL;
+}
+
+// Test the non-blocking variant using a second thread.
+TEST(MutexTest, lockNonBlocking) {
+ // block=false (tryLock).
+ Mutex mutex;
+ Mutex::Locker l1(mutex, false);
+ EXPECT_TRUE(mutex.locked()); // Debug-only build
+
+ // First, try another locker from the same thread.
+ EXPECT_THROW({
+ Mutex::Locker l2(mutex, false);
+ }, Mutex::Locker::AlreadyLocked);
+
+ EXPECT_TRUE(mutex.locked()); // Debug-only build
+
+ // Now try another locker from a different thread.
+ Thread thread(boost::bind(&testThread, &mutex));
+ thread.wait();
}
// Destroying a locked mutex is a bad idea as well
More information about the bind10-changes
mailing list