clock: take clock_abstime2ticks() as MACRO

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2024-06-05 11:34:59 +08:00 committed by Xiang Xiao
parent 07a4233d1d
commit 76e807560e
8 changed files with 36 additions and 26 deletions

View File

@ -445,6 +445,36 @@ EXTERN volatile clock_t g_system_ticks;
((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \ ((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \
(ts1)->tv_nsec - (ts2)->tv_nsec) (ts1)->tv_nsec - (ts2)->tv_nsec)
/****************************************************************************
* Name: clock_abstime2ticks
*
* Description:
* Convert an absolute timespec delay to system timer ticks.
*
* Input Parameters:
* clockid - The timing source to use in the conversion
* abstime - Convert this absolute time to ticks
* ticks - Return the converted number of ticks here.
*
* Returned Value:
* None
*
* Assumptions:
* Interrupts should be disabled so that the time is not changing during
* the calculation
*
****************************************************************************/
#define clock_abstime2ticks(clockid, abstime, ticks) \
do \
{ \
struct timespec _reltime; \
nxclock_gettime(clockid, &_reltime); \
clock_timespec_subtract(abstime, &_reltime, &_reltime); \
*(ticks) = clock_time2ticks(&_reltime); \
} \
while (0)
/**************************************************************************** /****************************************************************************
* Name: clock_compare * Name: clock_compare
* *

View File

@ -26,7 +26,6 @@ set(SRCS
clock_initialize.c clock_initialize.c
clock_settime.c clock_settime.c
clock_gettime.c clock_gettime.c
clock_abstime2ticks.c
clock_systime_ticks.c clock_systime_ticks.c
clock_systime_timespec.c) clock_systime_timespec.c)

View File

@ -21,7 +21,7 @@
############################################################################ ############################################################################
CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c
CSRCS += clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c CSRCS += clock_systime_ticks.c clock_systime_timespec.c
CSRCS += clock_perf.c CSRCS += clock_perf.c
ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y) ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y)

View File

@ -81,10 +81,6 @@ void clock_timer(void);
# define clock_timer() # define clock_timer()
#endif #endif
int clock_abstime2ticks(clockid_t clockid,
FAR const struct timespec *abstime,
FAR sclock_t *ticks);
/**************************************************************************** /****************************************************************************
* perf_init * perf_init
****************************************************************************/ ****************************************************************************/

View File

@ -179,7 +179,7 @@ file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg,
* this time stays valid until the wait begins. * this time stays valid until the wait begins.
*/ */
ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
} }
/* Handle any time-related errors */ /* Handle any time-related errors */

View File

@ -217,7 +217,7 @@ file_mq_timedsend_internal(FAR struct file *mq, FAR const char *msg,
* begins. * begins.
*/ */
ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks); clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
} }
/* Handle any time-related errors */ /* Handle any time-related errors */

View File

@ -95,7 +95,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *rtcb = this_task();
irqstate_t flags; irqstate_t flags;
sclock_t ticks; sclock_t ticks;
int status;
int ret = ERROR; int ret = ERROR;
DEBUGASSERT(sem != NULL && abstime != NULL); DEBUGASSERT(sem != NULL && abstime != NULL);
@ -140,24 +139,16 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
* value on failure. * value on failure.
*/ */
status = clock_abstime2ticks(clockid, abstime, &ticks); clock_abstime2ticks(clockid, abstime, &ticks);
/* If the time has already expired return immediately. */ /* If the time has already expired return immediately. */
if (status == OK && ticks <= 0) if (ticks <= 0)
{ {
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
goto out; goto out;
} }
/* Handle any time-related errors */
if (status != OK)
{
ret = -status;
goto out;
}
/* Start the watchdog */ /* Start the watchdog */
wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid()); wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid());

View File

@ -294,7 +294,7 @@ int timer_settime(timer_t timerid, int flags,
{ {
/* Calculate a delay corresponding to the absolute time in 'value' */ /* Calculate a delay corresponding to the absolute time in 'value' */
ret = clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay); clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay);
} }
else else
{ {
@ -306,11 +306,6 @@ int timer_settime(timer_t timerid, int flags,
delay = clock_time2ticks(&value->it_value); delay = clock_time2ticks(&value->it_value);
} }
if (ret < 0)
{
goto errout;
}
/* If the specified time has already passed, the function shall succeed /* If the specified time has already passed, the function shall succeed
* and the expiration notification shall be made. * and the expiration notification shall be made.
*/ */
@ -327,7 +322,6 @@ int timer_settime(timer_t timerid, int flags,
ret = wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer); ret = wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer);
} }
errout:
leave_critical_section(intflags); leave_critical_section(intflags);
if (ret < 0) if (ret < 0)