]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2332] Make sure preUnlockAction() doesn't throw when it shouldn't.
authorJINMEI Tatuya <jinmei@isc.org>
Mon, 15 Oct 2012 20:31:04 +0000 (13:31 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Mon, 15 Oct 2012 20:31:04 +0000 (13:31 -0700)
adding a parameter to control that.

src/lib/util/threads/lock.cc
src/lib/util/threads/lock.h

index 13d0a0d6712ac7aa725d0c6ab15142785871412f..3f4d92ada68316244c83d951586790ee12f79162 100644 (file)
@@ -128,9 +128,14 @@ Mutex::lock() {
 }
 
 void
-Mutex::preUnlockAction() {
+Mutex::preUnlockAction(bool throw_ok) {
     if (impl_->locked_count == 0) {
-        isc_throw(isc::InvalidOperation, "Unlock attempt for unlocked mutex");
+        if (throw_ok) {
+            isc_throw(isc::InvalidOperation,
+                      "Unlock attempt for unlocked mutex");
+        } else {
+            assert(false);
+        }
     }
     --impl_->locked_count;
 }
@@ -138,7 +143,7 @@ Mutex::preUnlockAction() {
 void
 Mutex::unlock() {
     assert(impl_ != NULL);
-    preUnlockAction();          // Only in debug mode
+    preUnlockAction(false);     // Only in debug mode.  Ensure no throw.
     const int result = pthread_mutex_unlock(&impl_->mutex);
     assert(result == 0); // This should never be possible
 }
@@ -181,7 +186,7 @@ CondVar::~CondVar() {
 
 void
 CondVar::wait(Mutex& mutex) {
-    mutex.preUnlockAction();    // Only in debug mode
+    mutex.preUnlockAction(true);    // Only in debug mode
     const int result = pthread_cond_wait(&impl_->cond_, &mutex.impl_->mutex);
     mutex.postLockAction();     // Only in debug mode
 
index 16b386fb7d3d0d50d816864f6273c33b49ea74e7..25247c17f8c0f180a1d6bb2fcffb0f6467eacaff 100644 (file)
@@ -116,7 +116,12 @@ private:
 
     // Commonly called before releasing the lock, checking and updating
     // internal state for debug.
-    void preUnlockAction();
+    //
+    // If throw_ok is true, it throws \c isc::InvalidOperation when the check
+    // fails; otherwise it aborts the process.  This parameter must be set
+    // to false if the call to this shouldn't result in an exception (e.g.
+    // when called from a destructor).
+    void preUnlockAction(bool throw_ok);
 
     class Impl;
     Impl* impl_;