prevent timer overflow on 32 bit systems
This commit is contained in:
		
							parent
							
								
									e8e469729a
								
							
						
					
					
						commit
						eb49f93e99
					
				
					 3 changed files with 9 additions and 9 deletions
				
			
		
							
								
								
									
										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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue