[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
timing ?
Can anyone see anything wrong with doing this for a simple
delay between up dates, outside of non-portability ?
/* for a least 1/20 pause */
#define USEC_DELAY 50000
void tick(void)
{
struct timeval nt;
static int64_t old;
static int64_t new;
long long t_delta;
for(;;) {
gettimeofday(&nt, NULL);
new=(int64_t) nt.tv_usec + (int64_t)\
(1000000 * (int64_t) nt.tv_sec);
t_delta = new - old;
if(t_delta > (int64_t) USEC_DELAY)
{ old = new;
return;
}
/* has system time gone backwards ?*/
if(t_delta < 0)
{ old = new;
continue;
}
usleep(1); /* works very nicely on my machine. Where HZ = 1024 */
}
}