fs/poll: Compute tick from millisecond by MSEC2TICK
reduce duplicate code Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
94e34d0020
commit
56b2e7254a
@ -75,7 +75,7 @@ struct epoll_head_s
|
|||||||
struct list_node oneshot; /* The oneshot list, store all the epoll
|
struct list_node oneshot; /* The oneshot list, store all the epoll
|
||||||
* node notified after epoll_wait and with
|
* node notified after epoll_wait and with
|
||||||
* EPOLLONESHOT events, these oneshot epoll
|
* EPOLLONESHOT events, these oneshot epoll
|
||||||
* nodes can be reset by epoll_ctl (Move
|
* nodes can be reset by epoll_ctl (move
|
||||||
* from oneshot list to the setup list).
|
* from oneshot list to the setup list).
|
||||||
*/
|
*/
|
||||||
struct list_node free; /* The free list, store all the freed epoll
|
struct list_node free; /* The free list, store all the freed epoll
|
||||||
@ -733,18 +733,7 @@ retry:
|
|||||||
}
|
}
|
||||||
else if (timeout > 0)
|
else if (timeout > 0)
|
||||||
{
|
{
|
||||||
clock_t ticks;
|
ret = nxsem_tickwait(&eph->sem, MSEC2TICK(timeout));
|
||||||
#if (MSEC_PER_TICK * USEC_PER_MSEC) != USEC_PER_TICK && \
|
|
||||||
defined(CONFIG_HAVE_LONG_LONG)
|
|
||||||
ticks = (((unsigned long long)timeout * USEC_PER_MSEC) +
|
|
||||||
(USEC_PER_TICK - 1)) /
|
|
||||||
USEC_PER_TICK;
|
|
||||||
#else
|
|
||||||
ticks = ((unsigned int)timeout + (MSEC_PER_TICK - 1)) /
|
|
||||||
MSEC_PER_TICK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = nxsem_tickwait(&eph->sem, ticks);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -812,18 +801,7 @@ retry:
|
|||||||
}
|
}
|
||||||
else if (timeout > 0)
|
else if (timeout > 0)
|
||||||
{
|
{
|
||||||
clock_t ticks;
|
ret = nxsem_tickwait(&eph->sem, MSEC2TICK(timeout));
|
||||||
#if (MSEC_PER_TICK * USEC_PER_MSEC) != USEC_PER_TICK && \
|
|
||||||
defined(CONFIG_HAVE_LONG_LONG)
|
|
||||||
ticks = (((unsigned long long)timeout * USEC_PER_MSEC) +
|
|
||||||
(USEC_PER_TICK - 1)) /
|
|
||||||
USEC_PER_TICK;
|
|
||||||
#else
|
|
||||||
ticks = ((unsigned int)timeout + (MSEC_PER_TICK - 1)) /
|
|
||||||
MSEC_PER_TICK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = nxsem_tickwait(&eph->sem, ticks);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -426,8 +426,6 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
|||||||
}
|
}
|
||||||
else if (timeout > 0)
|
else if (timeout > 0)
|
||||||
{
|
{
|
||||||
clock_t ticks;
|
|
||||||
|
|
||||||
/* "Implementations may place limitations on the granularity of
|
/* "Implementations may place limitations on the granularity of
|
||||||
* timeout intervals. If the requested timeout interval requires
|
* timeout intervals. If the requested timeout interval requires
|
||||||
* a finer granularity than the implementation supports, the
|
* a finer granularity than the implementation supports, the
|
||||||
@ -437,16 +435,6 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
|||||||
* Round timeout up to next full tick.
|
* Round timeout up to next full tick.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (MSEC_PER_TICK * USEC_PER_MSEC) != USEC_PER_TICK && \
|
|
||||||
defined(CONFIG_HAVE_LONG_LONG)
|
|
||||||
ticks = (((unsigned long long)timeout * USEC_PER_MSEC) +
|
|
||||||
(USEC_PER_TICK - 1)) /
|
|
||||||
USEC_PER_TICK;
|
|
||||||
#else
|
|
||||||
ticks = ((unsigned int)timeout + (MSEC_PER_TICK - 1)) /
|
|
||||||
MSEC_PER_TICK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Either wait for either a poll event(s), for a signal to occur,
|
/* Either wait for either a poll event(s), for a signal to occur,
|
||||||
* or for the specified timeout to elapse with no event.
|
* or for the specified timeout to elapse with no event.
|
||||||
*
|
*
|
||||||
@ -455,7 +443,7 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
|||||||
* will return immediately.
|
* will return immediately.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = nxsem_tickwait(&sem, ticks);
|
ret = nxsem_tickwait(&sem, MSEC2TICK(timeout));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (ret == -ETIMEDOUT)
|
if (ret == -ETIMEDOUT)
|
||||||
|
Loading…
Reference in New Issue
Block a user