CComponentsTimer: add support for nano seconds

To enable nano mode, parameter is_nano must set to true.
This commit is contained in:
2016-10-20 23:49:09 +02:00
parent 542de648f5
commit d0dd14040f
2 changed files with 20 additions and 10 deletions

View File

@@ -36,10 +36,11 @@
using namespace std;
CComponentsTimer::CComponentsTimer(const int& interval)
CComponentsTimer::CComponentsTimer(const int& interval, bool is_nano)
{
tm_thread = 0;
tm_interval = interval;
tm_enable_nano = is_nano;
sl_stop_timer = sigc::mem_fun(*this, &CComponentsTimer::stopTimer);
@@ -59,7 +60,10 @@ void CComponentsTimer::runSharedTimerAction()
while(tm_enable && tm_interval > 0) {
tm_mutex.lock();
OnTimer();
mySleep(tm_interval);
if (!tm_enable_nano)
mySleep(tm_interval);
else
usleep((useconds_t)tm_interval);
tm_mutex.unlock();
}
@@ -142,10 +146,11 @@ bool CComponentsTimer::stopTimer()
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;
tm_interval = seconds;
tm_enable_nano = is_nano;
tm_interval = interval;
}