sched: Remove start from nxsem_tickwait[_uninterruptible]

to simplify both caller and callee

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-05-10 08:33:09 +08:00 committed by Petro Karashchenko
parent 08002a0a38
commit 22e4f1c59a
4 changed files with 19 additions and 41 deletions

View File

@ -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 */ /* Wait for IRQ (TX_DS or MAX_RT) - but don't hang on lost IRQ */
ret = nxsem_tickwait(&dev->sem_tx, clock_systime_ticks(), ret = nxsem_tickwait(&dev->sem_tx, MSEC2TICK(NRF24L01_MAX_TX_IRQ_WAIT));
MSEC2TICK(NRF24L01_MAX_TX_IRQ_WAIT));
/* Re-acquire the SPI bus */ /* Re-acquire the SPI bus */

View File

@ -419,7 +419,7 @@ int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout)
* will return immediately. * will return immediately.
*/ */
ret = nxsem_tickwait(&sem, clock_systime_ticks(), ticks); ret = nxsem_tickwait(&sem, ticks);
if (ret < 0) if (ret < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -348,10 +348,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
* *
* Input Parameters: * Input Parameters:
* sem - Semaphore object * 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 * delay - Ticks to wait from the start time until the semaphore is
* posted. If ticks is zero, then this function is equivalent * posted. If ticks is zero, then this function is equivalent
* to sem_trywait(). * 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 * Name: nxsem_post
@ -608,10 +604,6 @@ int nxsem_clockwait_uninterruptible(FAR sem_t *sem, clockid_t clockid,
* *
* Input Parameters: * Input Parameters:
* sem - Semaphore object * 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 * delay - Ticks to wait from the start time until the semaphore is
* posted. If ticks is zero, then this function is equivalent * posted. If ticks is zero, then this function is equivalent
* to sem_trywait(). * 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, int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay);
uint32_t delay);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -52,10 +52,6 @@
* *
* Input Parameters: * Input Parameters:
* sem - Semaphore object * 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 * delay - Ticks to wait from the start time until the semaphore is
* posted. If ticks is zero, then this function is equivalent * posted. If ticks is zero, then this function is equivalent
* to nxsem_trywait(). * 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(); FAR struct tcb_s *rtcb = this_task();
irqstate_t flags; irqstate_t flags;
clock_t elapsed;
int ret; int ret;
DEBUGASSERT(sem != NULL && up_interrupt_context() == false); 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; 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 */ /* Start the watchdog with interrupts still disabled */
wd_start(&rtcb->waitdog, delay, nxsem_timeout, getpid()); wd_start(&rtcb->waitdog, delay, nxsem_timeout, getpid());
@ -147,10 +131,6 @@ out:
* *
* Input Parameters: * Input Parameters:
* sem - Semaphore object * 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 * delay - Ticks to wait from the start time until the semaphore is
* posted. If ticks is zero, then this function is equivalent * posted. If ticks is zero, then this function is equivalent
* to sem_trywait(). * to sem_trywait().
@ -165,19 +145,27 @@ out:
* *
****************************************************************************/ ****************************************************************************/
int nxsem_tickwait_uninterruptible(FAR sem_t *sem, clock_t start, int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay)
uint32_t delay)
{ {
clock_t end = clock_systime_ticks() + delay;
int ret; int ret;
do for (; ; )
{ {
/* Take the semaphore (perhaps waiting) */ /* 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; return ret;
} }