You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ts...@apache.org on 2014/03/14 12:40:28 UTC

svn commit: r1577488 - in /incubator/log4cxx/trunk/src: changes/changes.xml main/cpp/logmanager.cpp main/include/log4cxx/logmanager.h

Author: tschoening
Date: Fri Mar 14 11:40:27 2014
New Revision: 1577488

URL: http://svn.apache.org/r1577488
Log:
LOGCXX-430: LogManager::getRootLogger is not thread-safe

Modified:
    incubator/log4cxx/trunk/src/changes/changes.xml
    incubator/log4cxx/trunk/src/main/cpp/logmanager.cpp
    incubator/log4cxx/trunk/src/main/include/log4cxx/logmanager.h

Modified: incubator/log4cxx/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/changes/changes.xml?rev=1577488&r1=1577487&r2=1577488&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/changes/changes.xml (original)
+++ incubator/log4cxx/trunk/src/changes/changes.xml Fri Mar 14 11:40:27 2014
@@ -87,6 +87,7 @@
 			<action issue="LOGCXX-423" type="fix">Repair autogen script warnings</action>
 			<action issue="LOGCXX-424" type="fix">liblog4cxx.pc.in should reflect dependency on apr-1, apr-1-util</action>
 			<action issue="LOGCXX-425" type="fix">exceptions in CachedDateFormatTestCase after LOGCXX-420</action>
+			<action issue="LOGCXX-430" type="fix">LogManager::getRootLogger is not thread-safe</action>
 
 			<action type="change">Behavior of StringHelper::startsWith and endsWith synced</action>
 			<action type="change">Documented C (class) and M (method) log format keywords.</action>

Modified: incubator/log4cxx/trunk/src/main/cpp/logmanager.cpp
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/logmanager.cpp?rev=1577488&r1=1577487&r2=1577488&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/cpp/logmanager.cpp (original)
+++ incubator/log4cxx/trunk/src/main/cpp/logmanager.cpp Fri Mar 14 11:40:27 2014
@@ -49,15 +49,19 @@ using namespace log4cxx::helpers;
 IMPLEMENT_LOG4CXX_OBJECT(DefaultRepositorySelector)
 
 void * LogManager::guard = 0;
+spi::RepositorySelectorPtr LogManager::repoSelector(LogManager::getDefaultRepositorySelector());
 
 
 
-RepositorySelectorPtr& LogManager::getRepositorySelector() {
+RepositorySelectorPtr LogManager::getDefaultRepositorySelector() {
    //
    //     call to initialize APR and trigger "start" of logging clock
    //
    APRInitializer::initialize();
-   static spi::RepositorySelectorPtr selector;
+
+   LoggerRepositoryPtr hierarchy(new Hierarchy());
+   RepositorySelectorPtr selector(new DefaultRepositorySelector(hierarchy));
+
    return selector;
 }
 
@@ -75,21 +79,14 @@ void LogManager::setRepositorySelector(s
         }
 
         LogManager::guard = guard1;
-        LogManager::getRepositorySelector() = selector;
+        LogManager::repoSelector = selector;
 }
 
 
 
 LoggerRepositoryPtr& LogManager::getLoggerRepository()
 {
-        if (getRepositorySelector() == 0)
-        {
-                LoggerRepositoryPtr hierarchy(new Hierarchy());
-                RepositorySelectorPtr selector(new DefaultRepositorySelector(hierarchy));
-                getRepositorySelector() = selector;
-        }
-
-        return getRepositorySelector()->getLoggerRepository();
+        return LogManager::repoSelector->getLoggerRepository();
 }
 
 LoggerPtr LogManager::getRootLogger()

Modified: incubator/log4cxx/trunk/src/main/include/log4cxx/logmanager.h
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/include/log4cxx/logmanager.h?rev=1577488&r1=1577487&r2=1577488&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/include/log4cxx/logmanager.h (original)
+++ incubator/log4cxx/trunk/src/main/include/log4cxx/logmanager.h Fri Mar 14 11:40:27 2014
@@ -40,8 +40,8 @@ namespace log4cxx
 
     /**
     * Use the <code>LogManager</code> class to retreive Logger
-    * instances or to operate on the current 
-    * {@link log4cxx::spi::LoggerRepository LoggerRepository}. 
+    * instances or to operate on the current
+    * {@link log4cxx::spi::LoggerRepository LoggerRepository}.
     * When the <code>LogManager</code> class is loaded
     * into memory the default initialization procedure is inititated.
         */
@@ -49,7 +49,8 @@ namespace log4cxx
     {
     private:
         static void * guard;
-        static spi::RepositorySelectorPtr& getRepositorySelector();
+        static spi::RepositorySelectorPtr repoSelector;
+        static spi::RepositorySelectorPtr getDefaultRepositorySelector();
 
     public:
         /**