mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 17:01:15 +02:00
CComponentsTimer: add support for nano seconds
To enable nano mode, parameter is_nano must set to true.
This commit is contained in:
@@ -36,10 +36,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
CComponentsTimer::CComponentsTimer(const int& interval)
|
CComponentsTimer::CComponentsTimer(const int& interval, bool is_nano)
|
||||||
{
|
{
|
||||||
tm_thread = 0;
|
tm_thread = 0;
|
||||||
tm_interval = interval;
|
tm_interval = interval;
|
||||||
|
tm_enable_nano = is_nano;
|
||||||
|
|
||||||
sl_stop_timer = sigc::mem_fun(*this, &CComponentsTimer::stopTimer);
|
sl_stop_timer = sigc::mem_fun(*this, &CComponentsTimer::stopTimer);
|
||||||
|
|
||||||
@@ -59,7 +60,10 @@ void CComponentsTimer::runSharedTimerAction()
|
|||||||
while(tm_enable && tm_interval > 0) {
|
while(tm_enable && tm_interval > 0) {
|
||||||
tm_mutex.lock();
|
tm_mutex.lock();
|
||||||
OnTimer();
|
OnTimer();
|
||||||
mySleep(tm_interval);
|
if (!tm_enable_nano)
|
||||||
|
mySleep(tm_interval);
|
||||||
|
else
|
||||||
|
usleep((useconds_t)tm_interval);
|
||||||
tm_mutex.unlock();
|
tm_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,10 +146,11 @@ bool CComponentsTimer::stopTimer()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentsTimer::setTimerInterval(const int& seconds)
|
void CComponentsTimer::setTimerInterval(const int& interval, bool is_nano)
|
||||||
{
|
{
|
||||||
if (tm_interval == seconds)
|
if (tm_interval == interval && tm_enable_nano == is_nano)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tm_interval = seconds;
|
tm_enable_nano = is_nano;
|
||||||
|
tm_interval = interval;
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,8 @@ class CComponentsTimer : public sigc::trackable
|
|||||||
|
|
||||||
///refresh interval in seconds
|
///refresh interval in seconds
|
||||||
int tm_interval;
|
int tm_interval;
|
||||||
|
|
||||||
|
bool tm_enable_nano;
|
||||||
|
|
||||||
///init function to init shared timer action
|
///init function to init shared timer action
|
||||||
static void* initThreadAction(void *arg);
|
static void* initThreadAction(void *arg);
|
||||||
@@ -71,10 +73,12 @@ class CComponentsTimer : public sigc::trackable
|
|||||||
* @param[in] interval
|
* @param[in] interval
|
||||||
* @li int interval in seconds, default value=1 (1 sec)
|
* @li int interval in seconds, default value=1 (1 sec)
|
||||||
* If init value for interval > 0, timer starts immediately
|
* If init value for interval > 0, timer starts immediately
|
||||||
|
* @li bool default = false as seconds mode, true = nano seconds mode
|
||||||
* @see
|
* @see
|
||||||
* setTimerInterval();
|
* setTimerInterval();
|
||||||
*/
|
*/
|
||||||
CComponentsTimer(const int& interval = 1);
|
CComponentsTimer(const int& interval = 1, bool is_nano = false);
|
||||||
|
|
||||||
~CComponentsTimer();
|
~CComponentsTimer();
|
||||||
|
|
||||||
/**Starts timer thread
|
/**Starts timer thread
|
||||||
@@ -105,15 +109,16 @@ class CComponentsTimer : public sigc::trackable
|
|||||||
*/
|
*/
|
||||||
bool isRun() const {return tm_thread;};
|
bool isRun() const {return tm_thread;};
|
||||||
|
|
||||||
/**set interval in seconds
|
/**set timer interval
|
||||||
* @param[in] seconds
|
* @param[in] interval
|
||||||
* @li int
|
* @li int default interval in seconds, if second parameter = true interval is used as nano seconds
|
||||||
|
* @li bool default = false as seconds mode, true = nano seconds mode
|
||||||
* @return
|
* @return
|
||||||
* void
|
* void
|
||||||
* @see
|
* @see
|
||||||
* tm_interval
|
* tm_interval
|
||||||
*/
|
*/
|
||||||
void setTimerInterval(const int& seconds);
|
void setTimerInterval(const int& interval, bool is_nano = false);
|
||||||
|
|
||||||
/**Provides a signal handler to receive any function or methode.
|
/**Provides a signal handler to receive any function or methode.
|
||||||
* Use this in your class where ever you need time controled actions.
|
* Use this in your class where ever you need time controled actions.
|
||||||
|
Reference in New Issue
Block a user