Skip to content

Commit 76e8075

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
clock: take clock_abstime2ticks() as MACRO
Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent 07a4233 commit 76e8075

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
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_compare
450480
*

sched/clock/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ set(SRCS
2626
clock_initialize.c
2727
clock_settime.c
2828
clock_gettime.c
29-
clock_abstime2ticks.c
3029
clock_systime_ticks.c
3130
clock_systime_timespec.c)
3231

sched/clock/Make.defs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
############################################################################
2222

2323
CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c
24-
CSRCS += clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c
24+
CSRCS += clock_systime_ticks.c clock_systime_timespec.c
2525
CSRCS += clock_perf.c
2626

2727
ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y)

sched/clock/clock.h

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

84-
int clock_abstime2ticks(clockid_t clockid,
85-
FAR const struct timespec *abstime,
86-
FAR sclock_t *ticks);
87-
8884
/****************************************************************************
8985
* perf_init
9086
****************************************************************************/

sched/mqueue/mq_timedreceive.c

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

182-
ret = clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
182+
clock_abstime2ticks(CLOCK_REALTIME, abstime, &ticks);
183183
}
184184

185185
/* 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
@@ -95,7 +95,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
9595
FAR struct tcb_s *rtcb = this_task();
9696
irqstate_t flags;
9797
sclock_t ticks;
98-
int status;
9998
int ret = ERROR;
10099

101100
DEBUGASSERT(sem != NULL && abstime != NULL);
@@ -140,24 +139,16 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
140139
* value on failure.
141140
*/
142141

143-
status = clock_abstime2ticks(clockid, abstime, &ticks);
142+
clock_abstime2ticks(clockid, abstime, &ticks);
144143

145144
/* If the time has already expired return immediately. */
146145

147-
if (status == OK && ticks <= 0)
146+
if (ticks <= 0)
148147
{
149148
ret = -ETIMEDOUT;
150149
goto out;
151150
}
152151

153-
/* Handle any time-related errors */
154-
155-
if (status != OK)
156-
{
157-
ret = -status;
158-
goto out;
159-
}
160-
161152
/* Start the watchdog */
162153

163154
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
@@ -294,7 +294,7 @@ int timer_settime(timer_t timerid, int flags,
294294
{
295295
/* Calculate a delay corresponding to the absolute time in 'value' */
296296

297-
ret = clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay);
297+
clock_abstime2ticks(timer->pt_clock, &value->it_value, &delay);
298298
}
299299
else
300300
{
@@ -306,11 +306,6 @@ int timer_settime(timer_t timerid, int flags,
306306
delay = clock_time2ticks(&value->it_value);
307307
}
308308

309-
if (ret < 0)
310-
{
311-
goto errout;
312-
}
313-
314309
/* If the specified time has already passed, the function shall succeed
315310
* and the expiration notification shall be made.
316311
*/
@@ -327,7 +322,6 @@ int timer_settime(timer_t timerid, int flags,
327322
ret = wd_start(&timer->pt_wdog, delay, timer_timeout, (wdparm_t)timer);
328323
}
329324

330-
errout:
331325
leave_critical_section(intflags);
332326

333327
if (ret < 0)

0 commit comments

Comments
 (0)