Skip to content

Commit 0ae82b7

Browse files
committed
clock: take clock_abstime2ticks() as MARCO
Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent e83480a commit 0ae82b7

File tree

9 files changed

+36
-130
lines changed

9 files changed

+36
-130
lines changed

include/nuttx/clock.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,36 @@ EXTERN volatile clock_t g_system_ticks;
445445
((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \
446446
(ts1)->tv_nsec - (ts2)->tv_nsec)
447447

448+
/****************************************************************************
449+
* Name: clock_abstime2ticks
450+
*
451+
* Description:
452+
* Convert an absolute timespec delay to system timer ticks.
453+
*
454+
* Input Parameters:
455+
* clockid - The timing source to use in the conversion
456+
* abstime - Convert this absolute time to ticks
457+
* ticks - Return the converted number of ticks here.
458+
*
459+
* Returned Value:
460+
* None
461+
*
462+
* Assumptions:
463+
* Interrupts should be disabled so that the time is not changing during
464+
* the calculation
465+
*
466+
****************************************************************************/
467+
468+
#define clock_abstime2ticks(clockid, abstime, ticks) \
469+
do \
470+
{ \
471+
struct timespec _reltime; \
472+
nxclock_gettime(clockid, &_reltime); \
473+
clock_timespec_subtract(abstime, &_reltime, &_reltime); \
474+
*(ticks) = clock_time2ticks(&_reltime); \
475+
} \
476+
while (0)
477+
448478
/****************************************************************************
449479
* Name: clock_isleapyear
450480
*

sched/clock/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ set(SRCS
2424
clock_initialize.c
2525
clock_settime.c
2626
clock_gettime.c
27-
clock_abstime2ticks.c
2827
clock_systime_ticks.c
2928
clock_systime_timespec.c)
3029

sched/clock/Make.defs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
############################################################################
2020

2121
CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c
22-
CSRCS += clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c
22+
CSRCS += clock_systime_ticks.c clock_systime_timespec.c
2323
CSRCS += clock_perf.c
2424

2525
ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y)

sched/clock/clock.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ void clock_timer(void);
7979
# define clock_timer()
8080
#endif
8181

82-
int clock_abstime2ticks(clockid_t clockid,
83-
FAR const struct timespec *abstime,
84-
FAR sclock_t *ticks);
85-
8682
/****************************************************************************
8783
* perf_init
8884
****************************************************************************/

sched/clock/clock_abstime2ticks.c

Lines changed: 0 additions & 104 deletions
This file was deleted.

sched/mqueue/mq_timedreceive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg,
177177
* this time stays valid until the wait begins.
178178
*/
179179

180-
ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
180+
clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
181181
}
182182

183183
/* Handle any time-related errors */

sched/mqueue/mq_timedsend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ file_mq_timedsend_internal(FAR struct file *mq, FAR const char *msg,
217217
* begins.
218218
*/
219219

220-
ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
220+
clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
221221
}
222222

223223
/* Handle any time-related errors */

sched/semaphore/sem_clockwait.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
9393
FAR struct tcb_s *rtcb = this_task();
9494
irqstate_t flags;
9595
sclock_t ticks;
96-
int status;
9796
int ret = ERROR;
9897

9998
DEBUGASSERT(sem != NULL && abstime != NULL);
@@ -138,24 +137,16 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
138137
* value on failure.
139138
*/
140139

141-
status = clock_abstime2ticks(clockid, abstime, &ticks);
140+
clock_abstime2ticks(clockid, abstime, &ticks);
142141

143142
/* If the time has already expired return immediately. */
144143

145-
if (status == OK && ticks <= 0)
144+
if (ticks <= 0)
146145
{
147146
ret = -ETIMEDOUT;
148147
goto out;
149148
}
150149

151-
/* Handle any time-related errors */
152-
153-
if (status != OK)
154-
{
155-
ret = -status;
156-
goto out;
157-
}
158-
159150
/* Start the watchdog */
160151

161152
wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid());

sched/timer/timer_settime.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int timer_settime(timer_t timerid, int flags,
292292
{
293293
/* Calculate a delay corresponding to the absolute time in 'value' */
294294

295-
ret = clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay);
295+
clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay);
296296
}
297297
else
298298
{
@@ -304,11 +304,6 @@ int timer_settime(timer_t timerid, int flags,
304304
delay = clock_time2ticks(&value->it_value);
305305
}
306306

307-
if (ret < 0)
308-
{
309-
goto errout;
310-
}
311-
312307
/* If the specified time has already passed, the function shall succeed
313308
* and the expiration notification shall be made.
314309
*/
@@ -325,7 +320,6 @@ int timer_settime(timer_t timerid, int flags,
325320
ret = wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer);
326321
}
327322

328-
errout:
329323
leave_critical_section(intflags);
330324

331325
if (ret < 0)

0 commit comments

Comments
 (0)