BIND 10 trac2202, updated. 7cd33029c63a0cd0889dba94709cf6cadaea48ab [2202] Debug-only method Mutex::locked

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Sep 5 08:15:06 UTC 2012


The branch, trac2202 has been updated
       via  7cd33029c63a0cd0889dba94709cf6cadaea48ab (commit)
      from  c0128e80648ec83fb9f4e3cbf3bb7bba2ef0bbb5 (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 7cd33029c63a0cd0889dba94709cf6cadaea48ab
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Sep 5 10:14:32 2012 +0200

    [2202] Debug-only method Mutex::locked
    
    It can be used to check the thing is locked.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/util/threads/lock.cc                |    6 ++++++
 src/lib/util/threads/lock.h                 |    8 ++++++++
 src/lib/util/threads/tests/lock_unittest.cc |    5 +++++
 3 files changed, 19 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/util/threads/lock.cc b/src/lib/util/threads/lock.cc
index 86c4463..16e59bd 100644
--- a/src/lib/util/threads/lock.cc
+++ b/src/lib/util/threads/lock.cc
@@ -136,6 +136,12 @@ Mutex::unlock() {
     }
 }
 
+// TODO: Disable in non-debug build
+bool
+Mutex::locked() const {
+    return (impl_->locked != 0);
+}
+
 }
 }
 }
diff --git a/src/lib/util/threads/lock.h b/src/lib/util/threads/lock.h
index 60ab5db..10a7878 100644
--- a/src/lib/util/threads/lock.h
+++ b/src/lib/util/threads/lock.h
@@ -115,6 +115,14 @@ public:
     private:
         Mutex* mutex_;
     };
+    /// \brief If the mutex is currently locked
+    ///
+    /// This is debug aiding method only. And it might be unavailable in
+    /// non-debug build (because keeping the state might be needlesly
+    /// slow).
+    ///
+    /// \todo Disable in non-debug build
+    bool locked() const;
 private:
     friend class Locker;
     struct Impl;
diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc
index 19c1074..3a57012 100644
--- a/src/lib/util/threads/tests/lock_unittest.cc
+++ b/src/lib/util/threads/tests/lock_unittest.cc
@@ -27,7 +27,9 @@ namespace {
 // Test a recursive mutex can be locked multiple times
 TEST(MutexTest, recursiveLockMultiple) {
     Mutex mutex(true);
+    EXPECT_FALSE(mutex.locked()); // Debug-only build
     Mutex::Locker l1(mutex);
+    EXPECT_TRUE(mutex.locked()); // Debug-only build
     Mutex::Locker l2(mutex);
     Mutex::Locker l3(mutex);
     Mutex::Locker l4(mutex);
@@ -39,10 +41,13 @@ TEST(MutexTest, lockMultiple) {
     // TODO: Once we support non-debug mutexes, disable the test if we compile
     // with them.
     Mutex mutex;
+    EXPECT_FALSE(mutex.locked()); // Debug-only build
     Mutex::Locker l1(mutex);
+    EXPECT_TRUE(mutex.locked()); // Debug-only build
     EXPECT_THROW({
         Mutex::Locker l2(mutex); // Attempt to lock again.
     }, isc::InvalidOperation);
+    EXPECT_TRUE(mutex.locked()); // Debug-only build
 }
 
 // Destroying a locked mutex is a bad idea as well



More information about the bind10-changes mailing list