prevent timer overflow on 32 bit systems

This commit is contained in:
uvos 2020-07-04 11:50:46 +02:00
parent e8e469729a
commit eb49f93e99
3 changed files with 9 additions and 9 deletions

View File

@ -32,19 +32,19 @@ CppTimer::CppTimer() {
throw("Could not create timer");
};
void CppTimer::start(long nanosecs,std::function<void()> callbackIn, int type) {
void CppTimer::start(long secs, long nanosecs,std::function<void()> callbackIn, int type) {
switch(type){
case(PERIODIC):
//starts after specified period of nanoseconds
its.it_value.tv_sec = nanosecs / 1000000000;
its.it_value.tv_nsec = nanosecs % 1000000000;
its.it_interval.tv_sec = nanosecs / 1000000000;
its.it_interval.tv_nsec = nanosecs % 1000000000;
its.it_value.tv_sec = secs;
its.it_value.tv_nsec = nanosecs;
its.it_interval.tv_sec = secs;
its.it_interval.tv_nsec = nanosecs;
break;
case(ONESHOT):
//fires once after specified period of nanoseconds
its.it_value.tv_sec = nanosecs / 1000000000;
its.it_value.tv_nsec = nanosecs % 1000000000;
its.it_value.tv_sec = secs;
its.it_value.tv_nsec = nanosecs;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
break;

View File

@ -44,7 +44,7 @@ public:
* the timer fires once after the specified time in
* nanoseconds.
**/
virtual void start(long nanosecs, std::function<void()> callbackIn, int type = PERIODIC);
virtual void start(long secs, long nanosecs, std::function<void()> callbackIn, int type = PERIODIC);
/**
* Stops the timer by disarming it. It can be re-started

View File

@ -284,7 +284,7 @@ int main(int argc, char* argv[])
timer.block();
std::cout<<"Will stop pid: "<<prevProcess.getPid()<<" name: "<<prevProcess.getName()<<'\n';
qeuedToStop = prevProcess;
timer.start(config.timeoutSecs*1000*CppTimer::MS_TO_NS, sendEventProcStop, CppTimer::ONESHOT);
timer.start(config.timeoutSecs, 0, sendEventProcStop, CppTimer::ONESHOT);
stoppedProcs.push_back(prevProcess);
}
}