From 28ef6e147eafa0bb397cf683d21bac7d8941b1b0 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Fri, 26 Sep 2014 16:46:03 +0200 Subject: [PATCH] CComponentsTimer: add slot for auto timer start/stop Connection with OnBeforeRestart ensures closing threads. Under certain circumstances, eg. running thread, a restart could fail. --- src/gui/components/cc_timer.cpp | 7 +++++++ src/gui/components/cc_timer.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/gui/components/cc_timer.cpp b/src/gui/components/cc_timer.cpp index d056e0932..d95d299bc 100644 --- a/src/gui/components/cc_timer.cpp +++ b/src/gui/components/cc_timer.cpp @@ -40,6 +40,8 @@ CComponentsTimer::CComponentsTimer( const int& interval) { tm_thread = 0; tm_interval = interval; + + sl = sigc::mem_fun(*this, &CComponentsTimer::stopTimer); startTimer(); } @@ -81,6 +83,9 @@ bool CComponentsTimer::startTimer() } } dprintf(DEBUG_INFO,"[CComponentsTimer] [%s] timer thread [%lu] created with interval = %d\n", __func__, tm_thread, tm_interval); + + //ensure kill of thread on any restart of neutrino + CNeutrinoApp::getInstance()->OnBeforeRestart.connect(sl); return true; } @@ -99,6 +104,8 @@ bool CComponentsTimer::stopTimer() } if (thres == 0){ tm_thread = 0; + //ensure disconnect of unused slot + sl.disconnect(); return true; } diff --git a/src/gui/components/cc_timer.h b/src/gui/components/cc_timer.h index 4151b298c..62992c5aa 100644 --- a/src/gui/components/cc_timer.h +++ b/src/gui/components/cc_timer.h @@ -50,6 +50,8 @@ class CComponentsTimer : public sigc::trackable static void* initTimerThread(void *arg); ///mutex for timer OpenThreads::Mutex mutex; + ///slot for signals + sigc::slot0 sl; public: ///class constructor, parameter interval sets the interval in seconds, default value=1 (1 sec)