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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Sep 30 22:18:37 CDT 2010


branch "master" has been updated
       via  68e5ffd82711321f62dea4da1f3d9d57ea46a13d (commit)
      from  32343f16ab3c739233a4017bb8e726cedfa96525 (commit)

Summary of changes:
 client/src/Logger.cpp |   20 ++++++++++++++++++--
 client/src/logger.h   |    7 +++++++
 2 files changed, 25 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit 68e5ffd82711321f62dea4da1f3d9d57ea46a13d
Author: David M. Lee <dlee at digium.com>
Date:   Thu Sep 30 21:58:25 2010 -0500

    Adding thread safety to the client library.

diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index 84447d9..41a420c 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -67,6 +67,18 @@ Logger::Logger(Logger const &parent, std::string const &name) :
    assert(name.find(parent.name) == 0);
 }
 
+Logger::~Logger()
+{
+   IceUtil::Mutex::Lock childLock(childrenMutex);
+   for (std::map<std::string, Logger *>::iterator i = children.begin();
+        i != children.end();
+        ++i)
+   {
+      delete i->second;
+      i->second = 0;
+   }
+}
+
 CondStream Logger::operator()(Level level) const
 {
    return CondStream(*out, name, level, isEnabledFor(level));
@@ -103,6 +115,7 @@ void Logger::vlogf(Level level, char const *fmt, va_list ap) const
 void Logger::setOutput(LogOut &out)
 {
    this->out = &out;
+   IceUtil::Mutex::Lock childLock(childrenMutex);
    for (std::map<std::string, Logger *>::const_iterator i = children.begin(); i
       != children.end(); ++i)
    {
@@ -139,6 +152,7 @@ Level Logger::getEffectiveLevel() const
 Logger &Logger::getChild(std::string const &childName)
 {
    // ref to ptr allows us to update the map in-place
+   IceUtil::Mutex::Lock childLock(childrenMutex);
    Logger *&child = children[childName];
    if (child == 0)
    {
@@ -152,8 +166,10 @@ Logger &Logger::getChild(std::string const &childName)
 std::vector<Logger const *> Logger::getChildren() const
 {
    std::vector<Logger const *> r;
-   for (std::map<std::string, Logger *>::const_iterator i = children.begin(); i
-      != children.end(); ++i)
+   IceUtil::Mutex::Lock childLock(childrenMutex);
+   for (std::map<std::string, Logger *>::const_iterator i = children.begin();
+        i != children.end();
+        ++i)
    {
       r.push_back(i->second);
    }
diff --git a/client/src/logger.h b/client/src/logger.h
index 85d3fb4..05f6b5b 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -142,6 +142,8 @@ public:
     */
    HYDRA_ICEBOX_EXPORT Logger(Logger const &parent, std::string const &name);
 
+   HYDRA_ICEBOX_EXPORT ~Logger();
+
    /**
     * If true, this Logger would log messages of the given Level.
     *
@@ -218,6 +220,11 @@ private:
    Logger const &operator=(Logger const &);
 
    /**
+    * Mutex for access to the children field.
+    */
+   IceUtil::Mutex childrenMutex;
+
+   /**
     * Parent pointer.  We cannot change which parent we have, nor can we change
     * our parent.
     */

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


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list