Author: carnold
Date: Tue May  9 13:49:05 2006
New Revision: 405530

URL: http://svn.apache.org/viewcvs?rev=405530&view=rev
Log:
LOGCXX-132: Tweaking hierarchy to hopefully avoid seg faults in ThreadTest

Modified:
    logging/log4cxx/trunk/include/log4cxx/helpers/objectptr.h
    logging/log4cxx/trunk/include/log4cxx/hierarchy.h
    logging/log4cxx/trunk/src/hierarchy.cpp

Modified: logging/log4cxx/trunk/include/log4cxx/helpers/objectptr.h
URL: 
http://svn.apache.org/viewcvs/logging/log4cxx/trunk/include/log4cxx/helpers/objectptr.h?rev=405530&r1=405529&r2=405530&view=diff
==============================================================================
--- logging/log4cxx/trunk/include/log4cxx/helpers/objectptr.h (original)
+++ logging/log4cxx/trunk/include/log4cxx/helpers/objectptr.h Tue May  9 
13:49:05 2006
@@ -70,11 +70,10 @@
 
             ~ObjectPtrT()
             {
-                if (this->p != 0)
-                {
-                    this->p->releaseRef();
-                }
-                this->p = 0;
+              void* oldPtr = ObjectPtrBase::exchange((volatile void**) 
&this->p, 0);
+              if (oldPtr != 0) {
+                  ((T*) oldPtr)->releaseRef();
+              }
             }
 
             // Operators

Modified: logging/log4cxx/trunk/include/log4cxx/hierarchy.h
URL: 
http://svn.apache.org/viewcvs/logging/log4cxx/trunk/include/log4cxx/hierarchy.h?rev=405530&r1=405529&r2=405530&view=diff
==============================================================================
--- logging/log4cxx/trunk/include/log4cxx/hierarchy.h (original)
+++ logging/log4cxx/trunk/include/log4cxx/hierarchy.h Tue May  9 13:49:05 2006
@@ -256,7 +256,7 @@
 
             We add 'cat' to the list of children for this potential parent.
             */
-            void updateParents(LoggerPtr& logger);
+            void updateParents(LoggerPtr logger);
 
             /**
             We update the links for all the children that placed themselves
@@ -275,7 +275,7 @@
             Hierarchy(const Hierarchy&);
             Hierarchy& operator=(const Hierarchy&);
 
-            void updateChildren(ProvisionNode& pn, LoggerPtr& logger);
+            void updateChildren(ProvisionNode& pn, LoggerPtr logger);
             log4cxx::helpers::Mutex mutex;
             volatile log4cxx_uint32_t configured;
         };

Modified: logging/log4cxx/trunk/src/hierarchy.cpp
URL: 
http://svn.apache.org/viewcvs/logging/log4cxx/trunk/src/hierarchy.cpp?rev=405530&r1=405529&r2=405530&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/hierarchy.cpp (original)
+++ logging/log4cxx/trunk/src/hierarchy.cpp Tue May  9 13:49:05 2006
@@ -29,6 +29,7 @@
 #include <log4cxx/helpers/aprinitializer.h>
 #include <log4cxx/defaultconfigurator.h>
 #include <apr_atomic.h>
+#include "assert.h"
 
 
 using namespace log4cxx;
@@ -160,23 +161,17 @@
 LoggerPtr Hierarchy::getLogger(const LogString& name,
      const spi::LoggerFactoryPtr& factory)
 {
-        // Synchronize to prevent write conflicts. Read conflicts (in
-        // getEffectiveLevel method) are possible only if variable
-        // assignments are non-atomic.
-        LoggerPtr logger;
-
         synchronized sync(mutex);
 
         LoggerMap::iterator it = loggers.find(name);
 
         if (it != loggers.end())
         {
-                logger = it->second;
+                return it->second;
         }
         else
         {
-                logger = factory->makeNewLoggerInstance(name);
-
+                LoggerPtr logger(factory->makeNewLoggerInstance(name));
                 logger->setHierarchy(this);
                 loggers.insert(LoggerMap::value_type(name, logger));
 
@@ -188,10 +183,9 @@
                 }
 
                 updateParents(logger);
+                return logger;
         }
 
-
-        return logger;
 }
 
 LoggerList Hierarchy::getCurrentLoggers() const
@@ -284,8 +278,9 @@
 }
 
 
-void Hierarchy::updateParents(LoggerPtr& logger)
+void Hierarchy::updateParents(LoggerPtr logger)
 {
+        synchronized sync(mutex);
         const LogString name(logger->getName());
         int length = name.size();
         bool parentFound = false;
@@ -331,7 +326,7 @@
         }
 }
 
-void Hierarchy::updateChildren(ProvisionNode& pn, LoggerPtr& logger)
+void Hierarchy::updateChildren(ProvisionNode& pn, LoggerPtr logger)
 {
         //tcout << _T("updateChildren called for ") << logger->name << 
std::endl;
 


Reply via email to