]> granicus.if.org Git - icinga2/commitdiff
Fix static initializers for Utility::AddDeferredInitializer
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 07:00:56 +0000 (08:00 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 07:00:56 +0000 (08:00 +0100)
fixes #7646

lib/base/utility.cpp
lib/base/utility.hpp

index 1f6847cd96f877fdbd74d4e42f80bbb9a1d63436..0745e1265c0b8eb85211b7d817324f35a548c76b 100644 (file)
@@ -56,8 +56,6 @@ using namespace icinga;
 
 boost::thread_specific_ptr<String> Utility::m_ThreadName;
 boost::thread_specific_ptr<unsigned int> Utility::m_RandSeed;
-boost::thread_specific_ptr<bool> Utility::m_LoadingLibrary;
-boost::thread_specific_ptr<std::vector<boost::function<void(void)> > > Utility::m_DeferredInitializers;
 
 /**
  * Demangles a symbol name.
@@ -343,23 +341,29 @@ Utility::LoadExtensionLibrary(const String& library)
        return hModule;
 }
 
+boost::thread_specific_ptr<std::vector<boost::function<void(void)> > >& Utility::GetDeferredInitializers(void)
+{
+       static boost::thread_specific_ptr<std::vector<boost::function<void(void)> > > initializers;
+       return initializers;
+}
+
 void Utility::ExecuteDeferredInitializers(void)
 {
-       if (!m_DeferredInitializers.get())
+       if (!GetDeferredInitializers().get())
                return;
 
-       BOOST_FOREACH(const boost::function<void(void)>& callback, *m_DeferredInitializers.get())
+       BOOST_FOREACH(const boost::function<void(void)>& callback, *GetDeferredInitializers().get())
                callback();
 
-       m_DeferredInitializers.reset();
+       GetDeferredInitializers().reset();
 }
 
 void Utility::AddDeferredInitializer(const boost::function<void(void)>& callback)
 {
-       if (!m_DeferredInitializers.get())
-               m_DeferredInitializers.reset(new std::vector<boost::function<void(void)> >());
+       if (!GetDeferredInitializers().get())
+               GetDeferredInitializers().reset(new std::vector<boost::function<void(void)> >());
 
-       m_DeferredInitializers.get()->push_back(callback);
+       GetDeferredInitializers().get()->push_back(callback);
 }
 
 /**
index a944c049800b297511f461cf1c7cc95ac6aecba4..680594a77064d23c1682bd0c84feff4db9f0eec7 100644 (file)
@@ -141,8 +141,9 @@ private:
 
        static boost::thread_specific_ptr<String> m_ThreadName;
        static boost::thread_specific_ptr<unsigned int> m_RandSeed;
-       static boost::thread_specific_ptr<bool> m_LoadingLibrary;
-       static boost::thread_specific_ptr<std::vector<boost::function<void(void)> > > m_DeferredInitializers;
+
+       static boost::thread_specific_ptr<std::vector<boost::function<void(void)> > >& GetDeferredInitializers(void);
+
 };
 
 }