From 22e4f1c59aacfe18790f4bec788d15c028161421 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 10 May 2022 08:33:09 +0800 Subject: [PATCH] sched: Remove start from nxsem_tickwait[_uninterruptible] to simplify both caller and callee Signed-off-by: Xiang Xiao --- drivers/wireless/nrf24l01.c | 3 +-- fs/vfs/fs_poll.c | 2 +- include/nuttx/semaphore.h | 13 ++--------- sched/semaphore/sem_tickwait.c | 42 ++++++++++++---------------------- 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/drivers/wireless/nrf24l01.c b/drivers/wireless/nrf24l01.c index 046d84e1ae..824b5a49c1 100644 --- a/drivers/wireless/nrf24l01.c +++ b/drivers/wireless/nrf24l01.c @@ -847,8 +847,7 @@ static int dosend(FAR struct nrf24l01_dev_s *dev, FAR const uint8_t *data, /* Wait for IRQ (TX_DS or MAX_RT) - but don't hang on lost IRQ */ - ret = nxsem_tickwait(&dev->sem_tx, clock_systime_ticks(), - MSEC2TICK(NRF24L01_MAX_TX_IRQ_WAIT)); + ret = nxsem_tickwait(&dev->sem_tx, MSEC2TICK(NRF24L01_MAX_TX_IRQ_WAIT)); /* Re-acquire the SPI bus */ diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 11a4a4b44d..429addd64e 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -419,7 +419,7 @@ int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout) * will return immediately. */ - ret = nxsem_tickwait(&sem, clock_systime_ticks(), ticks); + ret = nxsem_tickwait(&sem, ticks); if (ret < 0) { if (ret == -ETIMEDOUT) diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 4f24f31761..dcea5ee863 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -348,10 +348,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, * * Input Parameters: * sem - Semaphore object - * start - The system time that the delay is relative to. If the - * current time is not the same as the start time, then the - * delay will be adjust so that the end time will be the same - * in any event. * delay - Ticks to wait from the start time until the semaphore is * posted. If ticks is zero, then this function is equivalent * to sem_trywait(). @@ -366,7 +362,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, * ****************************************************************************/ -int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay); +int nxsem_tickwait(FAR sem_t *sem, uint32_t delay); /**************************************************************************** * Name: nxsem_post @@ -608,10 +604,6 @@ int nxsem_clockwait_uninterruptible(FAR sem_t *sem, clockid_t clockid, * * Input Parameters: * sem - Semaphore object - * start - The system time that the delay is relative to. If the - * current time is not the same as the start time, then the - * delay will be adjust so that the end time will be the same - * in any event. * delay - Ticks to wait from the start time until the semaphore is * posted. If ticks is zero, then this function is equivalent * to sem_trywait(). @@ -632,8 +624,7 @@ int nxsem_clockwait_uninterruptible(FAR sem_t *sem, clockid_t clockid, * ****************************************************************************/ -int nxsem_tickwait_uninterruptible(FAR sem_t *sem, clock_t start, - uint32_t delay); +int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay); #undef EXTERN #ifdef __cplusplus diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index fe30ba562b..2359b415d8 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -52,10 +52,6 @@ * * Input Parameters: * sem - Semaphore object - * start - The system time that the delay is relative to. If the - * current time is not the same as the start time, then the - * delay will be adjust so that the end time will be the same - * in any event. * delay - Ticks to wait from the start time until the semaphore is * posted. If ticks is zero, then this function is equivalent * to nxsem_trywait(). @@ -68,11 +64,10 @@ * ****************************************************************************/ -int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) +int nxsem_tickwait(FAR sem_t *sem, uint32_t delay) { FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; - clock_t elapsed; int ret; DEBUGASSERT(sem != NULL && up_interrupt_context() == false); @@ -108,17 +103,6 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) goto out; } - /* Adjust the delay for any time since the delay was calculated */ - - elapsed = clock_systime_ticks() - start; - if (/* elapsed >= (UINT32_MAX / 2) || */ elapsed >= delay) - { - ret = -ETIMEDOUT; - goto out; - } - - delay -= elapsed; - /* Start the watchdog with interrupts still disabled */ wd_start(&rtcb->waitdog, delay, nxsem_timeout, getpid()); @@ -147,10 +131,6 @@ out: * * Input Parameters: * sem - Semaphore object - * start - The system time that the delay is relative to. If the - * current time is not the same as the start time, then the - * delay will be adjust so that the end time will be the same - * in any event. * delay - Ticks to wait from the start time until the semaphore is * posted. If ticks is zero, then this function is equivalent * to sem_trywait(). @@ -165,19 +145,27 @@ out: * ****************************************************************************/ -int nxsem_tickwait_uninterruptible(FAR sem_t *sem, clock_t start, - uint32_t delay) +int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay) { + clock_t end = clock_systime_ticks() + delay; int ret; - do + for (; ; ) { /* Take the semaphore (perhaps waiting) */ - ret = nxsem_tickwait(sem, start, delay); + ret = nxsem_tickwait(sem, delay); + if (ret != -EINTR) + { + break; + } + + delay = end - clock_systime_ticks(); + if ((int32_t)delay < 0) + { + delay = 0; + } } - while (ret == -EINTR); return ret; } -