BIND 10 trac2202, updated. 6e3d1a58e4ec1857fc0264e8070ce67f569b7e42 [2202] Don't throw from destructors
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Sep 26 09:47:54 UTC 2012
The branch, trac2202 has been updated
via 6e3d1a58e4ec1857fc0264e8070ce67f569b7e42 (commit)
via 076e5cff040e4da53df8dd60cee37a06e4e557c9 (commit)
via ac98e5dbf31b54eb74917d03e53ac071e8c8c92e (commit)
via 022f55634bf4865a315797abafedfbe43d54603b (commit)
from beccbfe1acb5e6e309d5dee9cbc4461434091520 (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 6e3d1a58e4ec1857fc0264e8070ce67f569b7e42
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Sep 26 11:29:07 2012 +0200
[2202] Don't throw from destructors
The situations are very bad anyway, and that should not happen during
normal operation. So we assert instead.
commit 076e5cff040e4da53df8dd60cee37a06e4e557c9
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Sep 26 11:20:40 2012 +0200
[2202] Cleanup: use better variable name
The previous looked like it should be boolean (there's something good
about lisp's P suffix).
commit ac98e5dbf31b54eb74917d03e53ac071e8c8c92e
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Sep 26 11:16:51 2012 +0200
[2202] Don't use namespace std
Because of fear of possible future collisions.
commit 022f55634bf4865a315797abafedfbe43d54603b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Sep 26 11:11:04 2012 +0200
[2202] Minor cleanups
* Removed an unneeded friend declaration.
* Typo
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/threads/lock.cc | 43 +++++++++++++--------------
src/lib/util/threads/lock.h | 3 +-
src/lib/util/threads/tests/lock_unittest.cc | 1 -
src/lib/util/threads/thread.cc | 14 ++++-----
4 files changed, 28 insertions(+), 33 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/threads/lock.cc b/src/lib/util/threads/lock.cc
index a495199..d5c32d4 100644
--- a/src/lib/util/threads/lock.cc
+++ b/src/lib/util/threads/lock.cc
@@ -23,7 +23,7 @@
#include <pthread.h>
-using namespace std;
+using std::auto_ptr;
namespace isc {
namespace util {
@@ -32,11 +32,11 @@ namespace thread {
class Mutex::Impl {
public:
Impl() :
- locked(0)
+ locked_count(0)
{}
pthread_mutex_t mutex;
// Only in debug mode
- size_t locked;
+ size_t locked_count;
};
namespace {
@@ -47,11 +47,9 @@ struct Deinitializer {
{}
~Deinitializer() {
const int result = pthread_mutexattr_destroy(&attributes_);
- if (result != 0) {
- // This really should not happen. We might as well
- // try to use assert here.
- isc_throw(isc::InvalidOperation, strerror(result));
- }
+ // This should never happen. According to the man page,
+ // if there's error, it's our fault.
+ assert(result == 0);
}
pthread_mutexattr_t& attributes_;
};
@@ -99,18 +97,19 @@ Mutex::Mutex(bool recursive) :
Mutex::~Mutex() {
if (impl_ != NULL) {
const int result = pthread_mutex_destroy(&impl_->mutex);
- const bool locked = impl_->locked != 0;
+ const bool locked = impl_->locked_count != 0;
delete impl_;
- if (result != 0) {
- // Yes, really throwing from the destructor.
- // But the error should not happen during normal
- // operations, this means something is screwed up
- // and must be fixed.
- isc_throw(isc::InvalidOperation, strerror(result));
- }
- if (locked) {
- isc_throw(isc::InvalidOperation, "Destroying locked mutex");
- }
+ // We don't want to throw from the destructor. Also, if this ever
+ // fails, something is really screwed up a lot.
+ assert(result == 0);
+
+ // We should not try to destroy a locked mutex, bad threaded monsters
+ // could get loose if we ever do and it is also forbidden by pthreads.
+
+ // This should not be possible to happen, since the
+ // pthread_mutex_destroy should check for it already. But it seems
+ // there are systems that don't check it.
+ assert(!locked);
}
}
@@ -121,13 +120,13 @@ Mutex::lock() {
if (result != 0) {
isc_throw(isc::InvalidOperation, strerror(result));
}
- ++impl_->locked; // Only in debug mode
+ ++impl_->locked_count; // Only in debug mode
}
void
Mutex::unlock() {
assert(impl_ != NULL);
- --impl_->locked; // Only in debug mode
+ --impl_->locked_count; // Only in debug mode
const int result = pthread_mutex_unlock(&impl_->mutex);
if (result != 0) {
isc_throw(isc::InvalidOperation, strerror(result));
@@ -137,7 +136,7 @@ Mutex::unlock() {
// TODO: Disable in non-debug build
bool
Mutex::locked() const {
- return (impl_->locked != 0);
+ return (impl_->locked_count != 0);
}
}
diff --git a/src/lib/util/threads/lock.h b/src/lib/util/threads/lock.h
index fea105b..dd71474 100644
--- a/src/lib/util/threads/lock.h
+++ b/src/lib/util/threads/lock.h
@@ -75,7 +75,7 @@ public:
/// \brief This holds a lock on a Mutex.
///
- /// To lock a mutex, create a locket. It'll get unlocked when the locker
+ /// To lock a mutex, create a locker. It'll get unlocked when the locker
/// is destroyed.
///
/// If you create the locker on the stack or using some other "garbage
@@ -127,7 +127,6 @@ public:
/// \todo Disable in non-debug build
bool locked() const;
private:
- friend class Locker;
class Impl;
Impl* impl_;
void lock();
diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc
index 3a57012..7ffc654 100644
--- a/src/lib/util/threads/tests/lock_unittest.cc
+++ b/src/lib/util/threads/tests/lock_unittest.cc
@@ -19,7 +19,6 @@
#include <boost/bind.hpp>
-using namespace std;
using namespace isc::util::thread;
namespace {
diff --git a/src/lib/util/threads/thread.cc b/src/lib/util/threads/thread.cc
index 34c9427..bbf7f51 100644
--- a/src/lib/util/threads/thread.cc
+++ b/src/lib/util/threads/thread.cc
@@ -22,7 +22,9 @@
#include <pthread.h>
-using namespace std;
+using std::string;
+using std::exception;
+using std::auto_ptr;
namespace isc {
namespace util {
@@ -111,13 +113,9 @@ Thread::~Thread() {
const int result = pthread_detach(impl_->tid);
Impl::done(impl_);
impl_ = NULL;
- if (result != 0) {
- // Yes, really throwing from destructor. But this would
- // mean someone really messed up the internal state, so
- // we need to do something about it, even if it causes
- // application to terminate.
- isc_throw(isc::InvalidOperation, strerror(result));
- }
+ // If the detach ever fails, something is screwed rather
+ // badly.
+ assert(result == 0);
}
}
More information about the bind10-changes
mailing list