how to implement delay (microseconds) with real timer ticking at 100ms.
hi all,
In my application i implemented one timer(ITIMER_REAL) ticking @ 100ms. Code given below: struct timeval my_value={0,100000}; struct timeval my_interval={0,100000}; struct itimerval my_timer={my_interval,my_value}; setitimer(ITIMER_REAL, &my_timer, NULL); signal(SIGALRM,TimerHandler ); TimerHandler is the event executing @ every 100ms. It works absolutly fine. The problem is, i already implemented various usleep in application, which gets terminated because of SIGALRM signal from ITIMER_REAL. So now how do i implement delay(micro seconds) without effecting ITIMER_REAL?. I tried to write own delay by reading microseconds. Code given below: void delay_1ms(long int ms) { struct timeval tv; ms= ms*1000; gettimeofday(&tv, NULL); ms +=tv.tv_usec; while(ms!=tv.tv_usec) { gettimeofday(&tv, NULL); } } but for value 1ms it goes for couple of seconds waiting. I m doubting is gettimeofday is 'real time read'? whats the way out friends? Thanks in advance -Mayank parasher. |
Code:
void delay_1ms(long int ms) |
All times are GMT -5. The time now is 05:39 AM. |