forked from nuttx/nuttx-update
usleep: use div_const to optimize the usleep
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
62047aa3d0
commit
f0d3c8ab2b
7 changed files with 23 additions and 10 deletions
|
@ -206,10 +206,22 @@
|
|||
#define TICK2HSEC(tick) div_const_roundnearest(tick, TICK_PER_HSEC)
|
||||
#define TICK2SEC(tick) div_const_roundnearest(tick, TICK_PER_SEC)
|
||||
|
||||
/* MSEC2SEC */
|
||||
|
||||
#define MSEC2SEC(usec) div_const(msec, MSEC_PER_SEC)
|
||||
|
||||
/* USEC2SEC */
|
||||
|
||||
#define USEC2SEC(usec) div_const(usec, USEC_PER_SEC)
|
||||
|
||||
/* NSEC2USEC */
|
||||
|
||||
#define NSEC2USEC(nsec) div_const(nsec, NSEC_PER_USEC)
|
||||
|
||||
/* NSEC2MSEC */
|
||||
|
||||
#define NSEC2MSEC(nsec) div_const(nsec, NSEC_PER_MSEC)
|
||||
|
||||
#if defined(CONFIG_DEBUG_SCHED) && defined(CONFIG_SYSTEM_TIME64) && \
|
||||
!defined(CONFIG_SCHED_TICKLESS)
|
||||
/* Initial system timer ticks value close to maximum 32-bit value, to test
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ static void nxsched_oneshot_start(void)
|
|||
|
||||
/* Then re-start the oneshot timer */
|
||||
|
||||
secs = usecs / 1000000;
|
||||
secs = USEC2SEC(usecs);
|
||||
usecs -= 100000 * secs;
|
||||
|
||||
ts.tv_sec = secs;
|
||||
|
@ -304,7 +304,7 @@ void nxsched_oneshot_extclk(FAR struct oneshot_lowerhalf_s *lower)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_sched_oneshot.maxdelay = ts.tv_nsec / 1000;
|
||||
g_sched_oneshot.maxdelay = NSEC2USEC(ts.tv_nsec);
|
||||
}
|
||||
|
||||
tmrinfo("madelay = %ld usec\n", (long)g_sched_oneshot.maxdelay);
|
||||
|
|
|
@ -117,8 +117,8 @@ int ppoll(FAR struct pollfd *fds, nfds_t nfds,
|
|||
|
||||
if (timeout_ts)
|
||||
{
|
||||
timeout = timeout_ts->tv_sec * 1000 +
|
||||
timeout_ts->tv_nsec / 1000000;
|
||||
timeout = timeout_ts->tv_sec * MSEC_PER_SEC +
|
||||
NSEC2MSEC(timeout_ts->tv_nsec);
|
||||
}
|
||||
|
||||
ret = poll(fds, nfds, timeout);
|
||||
|
|
|
@ -116,7 +116,7 @@ int pselect(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
|
|||
if (timeout)
|
||||
{
|
||||
timeval_buf.tv_sec = timeout->tv_sec;
|
||||
timeval_buf.tv_usec = timeout->tv_nsec / 1000;
|
||||
timeval_buf.tv_usec = NSEC2USEC(timeout->tv_nsec);
|
||||
timeval = &timeval_buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,9 +77,9 @@ int nxsig_usleep(useconds_t usec)
|
|||
{
|
||||
/* Let nxsig_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 = nxsig_nanosleep(&rqtp, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue