diff --git a/include/nuttx/hrtimer.h b/include/nuttx/hrtimer.h index e6c617b6b29..c59064a9e59 100644 --- a/include/nuttx/hrtimer.h +++ b/include/nuttx/hrtimer.h @@ -118,12 +118,7 @@ extern "C" * None ****************************************************************************/ -static inline_function -void hrtimer_init(FAR hrtimer_t *hrtimer, hrtimer_cb func) -{ - memset(hrtimer, 0, sizeof(hrtimer_t)); - hrtimer->func = func; -} +#define hrtimer_init(hrtimer) memset(hrtimer, 0, sizeof(hrtimer_t)) /**************************************************************************** * Name: hrtimer_cancel @@ -184,6 +179,7 @@ int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer); * * Input Parameters: * hrtimer - Timer instance to start + * func - Expiration callback function * expired - Expiration time in nanoseconds * mode - HRTIMER_MODE_ABS or HRTIMER_MODE_REL * @@ -191,7 +187,7 @@ int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer); * OK on success; a negated errno value on failure. ****************************************************************************/ -int hrtimer_start(FAR hrtimer_t *hrtimer, +int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func, uint64_t expired, enum hrtimer_mode_e mode); diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h index 99858415d29..92e932ac947 100644 --- a/sched/hrtimer/hrtimer.h +++ b/sched/hrtimer/hrtimer.h @@ -198,10 +198,7 @@ RB_PROTOTYPE(hrtimer_tree_s, hrtimer_node_s, entry, hrtimer_compare); static inline_function bool hrtimer_is_armed(FAR hrtimer_t *hrtimer) { - /* RB-tree root has NULL parent, so root must be checked explicitly */ - - return RB_PARENT(&hrtimer->node, entry) != NULL || - RB_ROOT(&g_hrtimer_tree) == &hrtimer->node; + return hrtimer->func != NULL; } /**************************************************************************** @@ -217,7 +214,7 @@ static inline_function void hrtimer_remove(FAR hrtimer_t *hrtimer) /* Explicitly clear parent to mark the timer as unarmed */ - RB_PARENT(&hrtimer->node, entry) = NULL; + hrtimer->func = NULL; } /**************************************************************************** diff --git a/sched/hrtimer/hrtimer_process.c b/sched/hrtimer/hrtimer_process.c index f94f699aa9e..c7a40fd2511 100644 --- a/sched/hrtimer/hrtimer_process.c +++ b/sched/hrtimer/hrtimer_process.c @@ -139,6 +139,7 @@ void hrtimer_process(uint64_t now) DEBUGASSERT(hrtimer->expired > period); + hrtimer->func = func; hrtimer_insert(hrtimer); } diff --git a/sched/hrtimer/hrtimer_start.c b/sched/hrtimer/hrtimer_start.c index caba6fc50f8..0f24e0952c9 100644 --- a/sched/hrtimer/hrtimer_start.c +++ b/sched/hrtimer/hrtimer_start.c @@ -44,6 +44,7 @@ * * Input Parameters: * hrtimer - Pointer to the hrtimer structure. + * func - Expiration callback function. * expired - Expiration time in nanoseconds. Interpretation * depends on mode. * mode - Timer mode (HRTIMER_MODE_ABS or HRTIMER_MODE_REL). @@ -59,7 +60,7 @@ * nanoseconds from the current time. ****************************************************************************/ -int hrtimer_start(FAR hrtimer_t *hrtimer, +int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func, uint64_t expired, enum hrtimer_mode_e mode) { @@ -77,6 +78,8 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_remove(hrtimer); } + hrtimer->func = func; + /* Compute absolute expiration time */ if (mode == HRTIMER_MODE_ABS)