Browse Source

[2202] Assert instead of throw

So we don't throw from a destructor. This should never happen anyway.
Michal 'vorner' Vaner 12 years ago
parent
commit
408728e451
2 changed files with 6 additions and 11 deletions
  1. 1 3
      src/lib/util/threads/lock.cc
  2. 5 8
      src/lib/util/threads/lock.h

+ 1 - 3
src/lib/util/threads/lock.cc

@@ -124,9 +124,7 @@ Mutex::unlock() {
     assert(impl_ != NULL);
     --impl_->locked_count; // Only in debug mode
     const int result = pthread_mutex_unlock(&impl_->mutex);
-    if (result != 0) {
-        isc_throw(isc::InvalidOperation, strerror(result));
-    }
+    assert(result == 0); // This should never be possible
 }
 
 // TODO: Disable in non-debug build

+ 5 - 8
src/lib/util/threads/lock.h

@@ -33,10 +33,11 @@ namespace thread {
 ///
 /// Also, as mutex is a low-level system object, an error might happen at any
 /// operation with it. We convert many errors to the isc::InvalidOperation,
-/// since the errors usually happen only when used in a wrong way. Any methods,
-/// constructors or even destructors in this class can throw. Allocation errors
-/// are converted to std::bad_alloc (for example when OS-dependant limit of
-/// mutexes is exceeded).
+/// since the errors usually happen only when used in a wrong way. Any methods
+/// or constructors in this class can throw. Allocation errors are converted
+/// to std::bad_alloc (for example when OS-dependant limit of mutexes is
+/// exceeded). Some errors which usually mean a programmer error abort the
+/// program, since there could be no safe way to recover from them.
 ///
 /// The current interface is somewhat minimalistic. If we ever need more, we
 /// can add it later.
@@ -96,10 +97,6 @@ public:
         /// \brief Destructor.
         ///
         /// Unlocks the mutex.
-        ///
-        /// \throw isc::InvalidOperation when OS reports error. This usually
-        ///     means an attempt to use the mutex in a wrong way (unlocking
-        ///     a mutex belonging to a differen thread).
         ~Locker() {
             if (mutex_ != NULL) {
                 mutex_->unlock();