usleep: use div_const to optimize the usleep

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2024-07-29 17:07:46 +08:00
committed by Xiang Xiao
parent 62047aa3d0
commit f0d3c8ab2b
7 changed files with 23 additions and 10 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ int gettimeofday(FAR struct timeval *tv, FAR struct timezone *tz)
/* Convert the struct timespec to a struct timeval */
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
tv->tv_usec = NSEC2USEC(ts.tv_nsec);
}
return ret;
+3 -2
View File
@@ -27,6 +27,7 @@
#include <signal.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/clock.h>
/****************************************************************************
* Public Functions
@@ -101,9 +102,9 @@ int usleep(useconds_t usec)
{
/* Let clock_nanosleep() do all of the work. */
sec = usec / 1000000;
sec = USEC2SEC(usec);
rqtp.tv_sec = sec;
rqtp.tv_nsec = (usec - (sec * 1000000)) * 1000;
rqtp.tv_nsec = (usec - (sec * USEC_PER_SEC)) * NSEC_PER_USEC;
ret = clock_nanosleep(CLOCK_REALTIME, 0, &rqtp, NULL);
}