Commit 7f94f671 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2332] Make sure preUnlockAction() doesn't throw when it shouldn't.

adding a parameter to control that.
parent 671005ee
......@@ -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
......
......@@ -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_;
......
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 to comment