From: Gunnar Beutner Date: Wed, 12 Nov 2014 07:00:56 +0000 (+0100) Subject: Fix static initializers for Utility::AddDeferredInitializer X-Git-Tag: v2.2.0~56 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4bfb5f9221de85ae2bf3e2d3cc53a1928b9193e;p=icinga2 Fix static initializers for Utility::AddDeferredInitializer fixes #7646 --- diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 1f6847cd9..0745e1265 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -56,8 +56,6 @@ using namespace icinga; boost::thread_specific_ptr Utility::m_ThreadName; boost::thread_specific_ptr Utility::m_RandSeed; -boost::thread_specific_ptr Utility::m_LoadingLibrary; -boost::thread_specific_ptr > > Utility::m_DeferredInitializers; /** * Demangles a symbol name. @@ -343,23 +341,29 @@ Utility::LoadExtensionLibrary(const String& library) return hModule; } +boost::thread_specific_ptr > >& Utility::GetDeferredInitializers(void) +{ + static boost::thread_specific_ptr > > initializers; + return initializers; +} + void Utility::ExecuteDeferredInitializers(void) { - if (!m_DeferredInitializers.get()) + if (!GetDeferredInitializers().get()) return; - BOOST_FOREACH(const boost::function& callback, *m_DeferredInitializers.get()) + BOOST_FOREACH(const boost::function& callback, *GetDeferredInitializers().get()) callback(); - m_DeferredInitializers.reset(); + GetDeferredInitializers().reset(); } void Utility::AddDeferredInitializer(const boost::function& callback) { - if (!m_DeferredInitializers.get()) - m_DeferredInitializers.reset(new std::vector >()); + if (!GetDeferredInitializers().get()) + GetDeferredInitializers().reset(new std::vector >()); - m_DeferredInitializers.get()->push_back(callback); + GetDeferredInitializers().get()->push_back(callback); } /** diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index a944c0498..680594a77 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -141,8 +141,9 @@ private: static boost::thread_specific_ptr m_ThreadName; static boost::thread_specific_ptr m_RandSeed; - static boost::thread_specific_ptr m_LoadingLibrary; - static boost::thread_specific_ptr > > m_DeferredInitializers; + + static boost::thread_specific_ptr > >& GetDeferredInitializers(void); + }; }