BIND 10 trac2202, updated. abd88f16af1295f2ff67f5e9593e61d1539ef6e4 [2202] some editorial/style fixes

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Sep 7 07:09:36 UTC 2012


The branch, trac2202 has been updated
       via  abd88f16af1295f2ff67f5e9593e61d1539ef6e4 (commit)
      from  a3e7cc6cf85981ed5a8a5e63589dfe1767b01e64 (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 abd88f16af1295f2ff67f5e9593e61d1539ef6e4
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Fri Sep 7 16:08:03 2012 +0900

    [2202] some editorial/style fixes
    
    - spacing
    - new lines for readability
    - const
    - brace position for catch
    - position of ++/--

-----------------------------------------------------------------------

Summary of changes:
 src/lib/util/threads/lock.cc   |   18 +++++++++---------
 src/lib/util/threads/lock.h    |    7 +++++--
 src/lib/util/threads/thread.cc |   20 ++++++++++----------
 src/lib/util/threads/thread.h  |    9 ++++++---
 4 files changed, 30 insertions(+), 24 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/util/threads/lock.cc b/src/lib/util/threads/lock.cc
index e3e9f7e..a495199 100644
--- a/src/lib/util/threads/lock.cc
+++ b/src/lib/util/threads/lock.cc
@@ -45,8 +45,8 @@ struct Deinitializer {
     Deinitializer(pthread_mutexattr_t& attributes):
         attributes_(attributes)
     {}
-    ~ Deinitializer() {
-        int result = pthread_mutexattr_destroy(&attributes_);
+    ~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.
@@ -96,10 +96,10 @@ Mutex::Mutex(bool recursive) :
     }
 }
 
-Mutex::~ Mutex() {
+Mutex::~Mutex() {
     if (impl_ != NULL) {
-        int result = pthread_mutex_destroy(&impl_->mutex);
-        bool locked = impl_->locked != 0;
+        const int result = pthread_mutex_destroy(&impl_->mutex);
+        const bool locked = impl_->locked != 0;
         delete impl_;
         if (result != 0) {
             // Yes, really throwing from the destructor.
@@ -117,18 +117,18 @@ Mutex::~ Mutex() {
 void
 Mutex::lock() {
     assert(impl_ != NULL);
-    int result = pthread_mutex_lock(&impl_->mutex);
+    const int result = pthread_mutex_lock(&impl_->mutex);
     if (result != 0) {
         isc_throw(isc::InvalidOperation, strerror(result));
     }
-    impl_->locked ++; // Only in debug mode
+    ++impl_->locked; // Only in debug mode
 }
 
 void
 Mutex::unlock() {
     assert(impl_ != NULL);
-    impl_->locked --; // Only in debug mode
-    int result = pthread_mutex_unlock(&impl_->mutex);
+    --impl_->locked; // Only in debug mode
+    const int result = pthread_mutex_unlock(&impl_->mutex);
     if (result != 0) {
         isc_throw(isc::InvalidOperation, strerror(result));
     }
diff --git a/src/lib/util/threads/lock.h b/src/lib/util/threads/lock.h
index 2c2dab8..fea105b 100644
--- a/src/lib/util/threads/lock.h
+++ b/src/lib/util/threads/lock.h
@@ -61,6 +61,7 @@ public:
     /// \throw isc::InvalidOperation Other unspecified errors around the mutex.
     ///     This should be rare.
     Mutex(bool recursive = false);
+
     /// \brief Destructor.
     ///
     /// Destroyes the mutex. It is not allowed to destroy a mutex which is
@@ -70,7 +71,8 @@ public:
     /// \throw isc::InvalidOperation when the OS reports an error. This should
     ///     generally happen only when the Mutex was used in a wrong way,
     ///     meaning programmer error.
-    ~ Mutex();
+    ~Mutex();
+
     /// \brief This holds a lock on a Mutex.
     ///
     /// To lock a mutex, create a locket. It'll get unlocked when the locker
@@ -100,6 +102,7 @@ public:
             mutex.lock();
             mutex_ = &mutex;
         }
+
         /// \brief Destructor.
         ///
         /// Unlocks the mutex.
@@ -107,7 +110,7 @@ public:
         /// \throw isc::InvalidOperation when OS repotrs error. This usually
         ///     means an attempt to use the mutex in a wrong way (unlocking
         ///     a mutex belonging to a differen thread).
-        ~ Locker() {
+        ~Locker() {
             if (mutex_ != NULL) {
                 mutex_->unlock();
             }
diff --git a/src/lib/util/threads/thread.cc b/src/lib/util/threads/thread.cc
index 1393c9a..34c9427 100644
--- a/src/lib/util/threads/thread.cc
+++ b/src/lib/util/threads/thread.cc
@@ -49,7 +49,7 @@ public:
         bool should_delete(false);
         { // We need to make sure the mutex is unlocked before it is deleted
             Mutex::Locker locker(impl->mutex);
-            if (-- impl->waiting_ == 0) {
+            if (--impl->waiting_ == 0) {
                 should_delete = true;
             }
         }
@@ -62,13 +62,11 @@ public:
         Impl* impl = reinterpret_cast<Impl*>(impl_raw);
         try {
             impl->main_();
-        }
-        catch (const exception& e) {
+        } catch (const exception& e) {
             Mutex::Locker locker(impl->mutex);
             impl->exception_ = true;
             impl->exception_text_ = e.what();
-        }
-        catch (...) {
+        } catch (...) {
             Mutex::Locker locker(impl->mutex);
             impl->exception_ = true;
         }
@@ -93,7 +91,8 @@ Thread::Thread(const boost::function<void ()>& main) :
     impl_(NULL)
 {
     auto_ptr<Impl> impl(new Impl(main));
-    int result = pthread_create(&impl->tid, NULL, &Impl::run, impl.get());
+    const int result = pthread_create(&impl->tid, NULL, &Impl::run,
+                                      impl.get());
     // Any error here?
     switch (result) {
         case 0: // All 0K
@@ -106,10 +105,10 @@ Thread::Thread(const boost::function<void ()>& main) :
     }
 }
 
-Thread::~ Thread() {
+Thread::~Thread() {
     if (impl_ != NULL) {
         // In case we didn't call wait yet
-        int result = pthread_detach(impl_->tid);
+        const int result = pthread_detach(impl_->tid);
         Impl::done(impl_);
         impl_ = NULL;
         if (result != 0) {
@@ -125,10 +124,11 @@ Thread::~ Thread() {
 void
 Thread::wait() {
     if (impl_ == NULL) {
-        isc_throw(isc::InvalidOperation, "Wait called and no thread to wait for");
+        isc_throw(isc::InvalidOperation,
+                  "Wait called and no thread to wait for");
     }
 
-    int result = pthread_join(impl_->tid, NULL);
+    const int result = pthread_join(impl_->tid, NULL);
     if (result != 0) {
         isc_throw(isc::InvalidOperation, strerror(result));
     }
diff --git a/src/lib/util/threads/thread.h b/src/lib/util/threads/thread.h
index 0ddae72..4d14859 100644
--- a/src/lib/util/threads/thread.h
+++ b/src/lib/util/threads/thread.h
@@ -49,6 +49,7 @@ public:
             Exception(file, line, what)
         {}
     };
+
     /// \brief Create and start a thread.
     ///
     /// Create a new thread and run body inside it.
@@ -63,10 +64,11 @@ public:
     ///
     /// \param main The code to run inside the thread.
     ///
-    /// \throw std::bad_alloc if allocation of the new thread or other resources
-    ///     fails.
+    /// \throw std::bad_alloc if allocation of the new thread or other
+    /// resources fails.
     /// \throw isc::InvalidOperation for other errors (should not happen).
     Thread(const boost::function<void()>& main);
+
     /// \brief Destructor.
     ///
     /// It is completely legitimate to destroy the thread without calling
@@ -77,7 +79,8 @@ public:
     /// \throw isc::InvalidOperation in the rare case of OS reporting a
     ///     problem. This should not happen unless you messed up with the raw
     ///     thread by the low-level API.
-    ~ Thread();
+    ~Thread();
+
     /// \brief Wait for the thread to terminate.
     ///
     /// Waits until the thread terminates. Must be called at most once.



More information about the bind10-changes mailing list