读取时间戳(微秒单位)
long get_timestamp(void)
{
struct timeval now;
long now_usec;
gettimeofday(&now, NULL);
now_usec = now.tv_sec * 1000000;
now_usec += now.tv_usec;
//printf("now.tv_sec=%ld now.tv_usec=%ld\n",now.tv_sec,now.tv_usec);
return now_usec;
}
判断是否超时(微秒单位)
bool is_timestamp_after(long last_usec, long timeout)
{
struct timeval now;
long now_usec, elapsed;
gettimeofday(&now, NULL);
now_usec = now.tv_sec * 1000000;
now_usec += now.tv_usec;
if ((last_usec/1000000) > (now_usec/1000000))
{
//printf("@@@ system time refreshed[%ld %ld] @@@\n",last_usec,now_usec);
return TRUE;
}
else
{
elapsed = now_usec - last_usec;
if (elapsed > timeout) return TRUE;
else return FALSE;
}
}
阅读(1422) | 评论(0) | 转发(0) |