]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2332] (unrelated) cleanup: removed unnecesary failure case in Locker.
authorJINMEI Tatuya <jinmei@isc.org>
Thu, 11 Oct 2012 05:58:39 +0000 (22:58 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Thu, 11 Oct 2012 06:01:59 +0000 (23:01 -0700)
We don't have to worry about the case lock() throws in the constructor.
In that case the destructor won't be called.
This simplification will make the code simpler, and we can also make
mutex_ member variable a const.

src/lib/util/threads/lock.h

index c219abbdff96b7ae3287771bd1a511040612028c..8a072f10d3ddba7739c343fcc7afdc2ed0737936 100644 (file)
@@ -85,26 +85,19 @@ public:
         ///     means an attempt to use the mutex in a wrong way (locking
         ///     a mutex second time from the same thread, for example).
         Locker(Mutex& mutex) :
-            mutex_(NULL)
+            mutex_(&mutex)
         {
-            // Set the mutex_ after we acquire the lock. This is because of
-            // exception safety. If lock() throws, it didn't work, so we must
-            // not unlock when we are destroyed. In such case, mutex_ is
-            // NULL and checked in the destructor.
             mutex.lock();
-            mutex_ = &mutex;
         }
 
         /// \brief Destructor.
         ///
         /// Unlocks the mutex.
         ~Locker() {
-            if (mutex_ != NULL) {
-                mutex_->unlock();
-            }
+            mutex_->unlock();
         }
     private:
-        Mutex* mutex_;
+        Mutex* const mutex_;
     };
     /// \brief If the mutex is currently locked
     ///