]> granicus.if.org Git - icinga2/commitdiff
Re-introduce Timer::Initialize()
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Thu, 19 Jul 2018 10:49:27 +0000 (12:49 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 19 Jul 2018 11:22:37 +0000 (13:22 +0200)
refs #6445

lib/base/application.cpp
lib/base/timer.cpp
lib/base/timer.hpp

index dec962e088aa66e1526d9117eb25f3c7c715cf5e..cfa728caabe2661c1b358875132b86fcd68a7864 100644 (file)
@@ -140,6 +140,8 @@ void Application::InitializeBase()
 
        /* make sure the thread pool gets initialized */
        GetTP().Start();
+
+       Timer::Initialize();
 }
 
 void Application::UninitializeBase()
index 0eb03f754174192c5b722ea13bd277761d375056..95e3f5b6de21bfd7527425b91e4f96fce498560d 100644 (file)
@@ -71,7 +71,6 @@ static boost::condition_variable l_TimerCV;
 static std::thread l_TimerThread;
 static bool l_StopTimerThread;
 static TimerSet l_Timers;
-static int l_AliveTimers;
 
 /**
  * Destructor for the Timer class.
@@ -81,6 +80,13 @@ Timer::~Timer()
        Stop(true);
 }
 
+void Timer::Initialize()
+{
+       boost::mutex::scoped_lock lock(l_TimerMutex);
+       l_StopTimerThread = false;
+       l_TimerThread = std::thread(&Timer::TimerThreadProc);
+}
+
 void Timer::Uninitialize()
 {
        {
@@ -139,11 +145,6 @@ void Timer::Start()
        {
                boost::mutex::scoped_lock lock(l_TimerMutex);
                m_Started = true;
-
-               if (l_AliveTimers++ == 0) {
-                       l_StopTimerThread = false;
-                       l_TimerThread = std::thread(&Timer::TimerThreadProc);
-               }
        }
 
        InternalReschedule(false);
@@ -159,18 +160,6 @@ void Timer::Stop(bool wait)
 
        boost::mutex::scoped_lock lock(l_TimerMutex);
 
-       if (m_Started && --l_AliveTimers == 0) {
-               l_StopTimerThread = true;
-               l_TimerCV.notify_all();
-
-               lock.unlock();
-
-               if (l_TimerThread.joinable() && l_TimerThread.get_id() != std::this_thread::get_id())
-                       l_TimerThread.join();
-
-               lock.lock();
-       }
-
        m_Started = false;
        l_Timers.erase(this);
 
index 6d5e115ef77f88eaae2ed7f9bc245cd875bf8552..0c661593de12874d9895534e8791f002dc6fa033 100644 (file)
@@ -40,6 +40,7 @@ public:
 
        ~Timer() override;
 
+       static void Initialize();
        static void Uninitialize();
 
        void SetInterval(double interval);