prevent timer overflow on 32 bit systems
This commit is contained in:
14
CppTimer.cpp
14
CppTimer.cpp
@ -32,19 +32,19 @@ CppTimer::CppTimer() {
|
|||||||
throw("Could not create timer");
|
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){
|
switch(type){
|
||||||
case(PERIODIC):
|
case(PERIODIC):
|
||||||
//starts after specified period of nanoseconds
|
//starts after specified period of nanoseconds
|
||||||
its.it_value.tv_sec = nanosecs / 1000000000;
|
its.it_value.tv_sec = secs;
|
||||||
its.it_value.tv_nsec = nanosecs % 1000000000;
|
its.it_value.tv_nsec = nanosecs;
|
||||||
its.it_interval.tv_sec = nanosecs / 1000000000;
|
its.it_interval.tv_sec = secs;
|
||||||
its.it_interval.tv_nsec = nanosecs % 1000000000;
|
its.it_interval.tv_nsec = nanosecs;
|
||||||
break;
|
break;
|
||||||
case(ONESHOT):
|
case(ONESHOT):
|
||||||
//fires once after specified period of nanoseconds
|
//fires once after specified period of nanoseconds
|
||||||
its.it_value.tv_sec = nanosecs / 1000000000;
|
its.it_value.tv_sec = secs;
|
||||||
its.it_value.tv_nsec = nanosecs % 1000000000;
|
its.it_value.tv_nsec = nanosecs;
|
||||||
its.it_interval.tv_sec = 0;
|
its.it_interval.tv_sec = 0;
|
||||||
its.it_interval.tv_nsec = 0;
|
its.it_interval.tv_nsec = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
* the timer fires once after the specified time in
|
* the timer fires once after the specified time in
|
||||||
* nanoseconds.
|
* 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
|
* Stops the timer by disarming it. It can be re-started
|
||||||
|
2
main.cpp
2
main.cpp
@ -284,7 +284,7 @@ int main(int argc, char* argv[])
|
|||||||
timer.block();
|
timer.block();
|
||||||
std::cout<<"Will stop pid: "<<prevProcess.getPid()<<" name: "<<prevProcess.getName()<<'\n';
|
std::cout<<"Will stop pid: "<<prevProcess.getPid()<<" name: "<<prevProcess.getName()<<'\n';
|
||||||
qeuedToStop = prevProcess;
|
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);
|
stoppedProcs.push_back(prevProcess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user