Re-introduce Timer::Initialize()

refs #6445
This commit is contained in:
Alexander A. Klimov 2018-07-19 12:49:27 +02:00 committed by Michael Friedrich
parent 75947c96d5
commit d15e1006f3
3 changed files with 10 additions and 18 deletions

View File

@ -140,6 +140,8 @@ void Application::InitializeBase()
/* make sure the thread pool gets initialized */
GetTP().Start();
Timer::Initialize();
}
void Application::UninitializeBase()

View 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);

View File

@ -40,6 +40,7 @@ public:
~Timer() override;
static void Initialize();
static void Uninitialize();
void SetInterval(double interval);