[asterisk-scf-commits] asterisk-scf/release/logger.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jan 3 16:00:44 UTC 2011


branch "master" has been updated
       via  d2dd67b7a2e5e77eb83a2c7bee65c7f8d6a2b6bf (commit)
      from  296b0194c1b37f5b54db610716d20553cef9564f (commit)

Summary of changes:
 client/src/Logger.cpp |   12 +++++++-----
 client/src/logger.h   |   10 +++++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)


- Log -----------------------------------------------------------------
commit d2dd67b7a2e5e77eb83a2c7bee65c7f8d6a2b6bf
Author: David M. Lee <dlee at digium.com>
Date:   Mon Jan 3 09:58:04 2011 -0600

    Fixed thread safety issues in Logger client.
    
    * Added a shared_mutex around mLogLevel and mInheritedLevel.  This
      should make it thread safe, and keep read contention very low.
    * Since Ice didn't offer a shared_mutex, switched the existing
      mChildrenMutex from an Ice mutex to a Boost mutex, for consistency.
    See CR-ASTSCF-4.

diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index 15b4d50..54b6c74 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -77,7 +77,6 @@ Logger::Logger(const Logger& parent, const std::string& name) :
 
 Logger::~Logger()
 {
-    IceUtil::Mutex::Lock childLock(mChildrenMutex);
 }
 
 CondStream Logger::operator()(Level level) const
@@ -122,7 +121,7 @@ void Logger::vlogf(Level level, char const *fmt, va_list ap) const
 void Logger::setOutput(LogOut& out)
 {
     this->mOut = &out;
-    IceUtil::Mutex::Lock childLock(mChildrenMutex);
+    boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
     for (Children::const_iterator i = mChildren.begin();
          i != mChildren.end();
          ++i)
@@ -134,18 +133,21 @@ void Logger::setOutput(LogOut& out)
 
 void Logger::setLevel(Level logLevel)
 {
-    this->mLogLevel = logLevel;
+    boost::unique_lock<boost::shared_mutex> lock(mLevelMutex);
+    mLogLevel = logLevel;
     mInheritedLevel = false;
 }
 
 void Logger::unsetLevel()
 {
+    boost::unique_lock<boost::shared_mutex> lock(mLevelMutex);
     mInheritedLevel = true;
     mLogLevel = Off;
 }
 
 Level Logger::getEffectiveLevel() const
 {
+    boost::shared_lock<boost::shared_mutex> lock(mLevelMutex);
     // if our level is unset, inherit level from our parent.
     if (mInheritedLevel == true && mParent != 0)
     {
@@ -159,7 +161,7 @@ Level Logger::getEffectiveLevel() const
 
 Logger& Logger::getChild(const std::string& childName)
 {
-    IceUtil::Mutex::Lock childLock(mChildrenMutex);
+    boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
 
     // ref to ptr allows us to update the map in-place
     boost::shared_ptr<Logger>& child = mChildren[childName];
@@ -175,7 +177,7 @@ Logger& Logger::getChild(const std::string& childName)
 std::vector<boost::shared_ptr<const Logger> > Logger::getChildren() const
 {
     std::vector<boost::shared_ptr<const Logger> > r;
-    IceUtil::Mutex::Lock childLock(mChildrenMutex);
+    boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
     for (Children::const_iterator i = mChildren.begin();
          i != mChildren.end();
          ++i)
diff --git a/client/src/logger.h b/client/src/logger.h
index 88e375a..1e94b62 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -20,6 +20,8 @@
 #include <cstdarg>
 
 #include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
 
 #include "System/Logger/LoggerIf.h"
 #include "Level.h"
@@ -231,7 +233,7 @@ private:
     /**
      * Mutex for access to the children field.
      */
-    IceUtil::Mutex mChildrenMutex;
+    mutable boost::mutex mChildrenMutex;
 
     /**
      * Parent pointer.  We cannot change which parent we have, nor can we change
@@ -252,6 +254,12 @@ private:
      * Output for log messages.
      */
     LogOut *mOut;
+
+    /**
+     * Mutex for accessing mLogLevel and mInheritedLevel.  It's a shared_mutext
+     * to reduce read contention on the mutex.
+     */
+    mutable boost::shared_mutex mLevelMutex;
     /**
      * Current level of this Logger.  Only applicable if inheritedLevel == false.
      */

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


-- 
asterisk-scf/release/logger.git



More information about the asterisk-scf-commits mailing list