From d15e1006f385eb4f297b14b7df618c033d7d76ca Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 19 Jul 2018 12:49:27 +0200 Subject: [PATCH] Re-introduce Timer::Initialize() refs #6445 --- lib/base/application.cpp | 2 ++ lib/base/timer.cpp | 25 +++++++------------------ lib/base/timer.hpp | 1 + 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index dec962e08..cfa728caa 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -140,6 +140,8 @@ void Application::InitializeBase() /* make sure the thread pool gets initialized */ GetTP().Start(); + + Timer::Initialize(); } void Application::UninitializeBase() diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 0eb03f754..95e3f5b6d 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -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); diff --git a/lib/base/timer.hpp b/lib/base/timer.hpp index 6d5e115ef..0c661593d 100644 --- a/lib/base/timer.hpp +++ b/lib/base/timer.hpp @@ -40,6 +40,7 @@ public: ~Timer() override; + static void Initialize(); static void Uninitialize(); void SetInterval(double interval);