prevent timer overflow on 32 bit systems
This commit is contained in:
parent
e8e469729a
commit
eb49f93e99
14
CppTimer.cpp
14
CppTimer.cpp
@ -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;
|
||||
|
@ -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
|
||||
|
2
main.cpp
2
main.cpp
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user