Skip to content

Commit

Permalink
[ctime]解决clock_gettime计算出来的nsec超过1sec的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
guoguozi123456 authored Jun 1, 2023
1 parent 1638241 commit e88a194
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/libc/compilers/common/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,13 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
level = rt_hw_interrupt_disable();
tick = rt_tick_get(); /* get tick */
tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND;
tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000;
tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000U;
rt_hw_interrupt_enable(level);
if (tp->tv_nsec > 1000000000ULL)
{
tp->tv_nsec %= 1000000000ULL;
tp->tv_sec += 1;
}
}
break;
#endif
Expand Down

0 comments on commit e88a194

Please sign in to comment.