kernel: Refactor remaining time evaluation for timeouts
Factor out the code for evaluating the remaining time for _timeout structs so that it can also be used for other objects besides k_timer structs (like k_delayed_work, coming in a subsequent patch). Change-Id: I243a7b29fb2831f06e95086a31f0d3a6c37dad67 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
142c0024de
commit
f99ad3f0e2
2 changed files with 9 additions and 5 deletions
|
@ -654,6 +654,8 @@ struct _timeout {
|
||||||
_timeout_func_t func;
|
_timeout_func_t func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int32_t _timeout_remaining_get(struct _timeout *timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL_HIDDEN @endcond
|
* INTERNAL_HIDDEN @endcond
|
||||||
*/
|
*/
|
||||||
|
@ -852,7 +854,10 @@ extern uint32_t k_timer_status_sync(struct k_timer *timer);
|
||||||
*
|
*
|
||||||
* @return Remaining time (in milliseconds).
|
* @return Remaining time (in milliseconds).
|
||||||
*/
|
*/
|
||||||
extern int32_t k_timer_remaining_get(struct k_timer *timer);
|
static inline int32_t k_timer_remaining_get(struct k_timer *timer)
|
||||||
|
{
|
||||||
|
return _timeout_remaining_get(&timer->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @} end defgroup timer_apis
|
* @} end defgroup timer_apis
|
||||||
|
|
|
@ -196,13 +196,12 @@ uint32_t k_timer_status_sync(struct k_timer *timer)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t _timeout_remaining_get(struct _timeout *timeout)
|
||||||
int32_t k_timer_remaining_get(struct k_timer *timer)
|
|
||||||
{
|
{
|
||||||
unsigned int key = irq_lock();
|
unsigned int key = irq_lock();
|
||||||
int32_t remaining_ticks;
|
int32_t remaining_ticks;
|
||||||
|
|
||||||
if (timer->timeout.delta_ticks_from_prev == -1) {
|
if (timeout->delta_ticks_from_prev == -1) {
|
||||||
remaining_ticks = 0;
|
remaining_ticks = 0;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -213,7 +212,7 @@ int32_t k_timer_remaining_get(struct k_timer *timer)
|
||||||
(struct _timeout *)sys_dlist_peek_head(&_timeout_q);
|
(struct _timeout *)sys_dlist_peek_head(&_timeout_q);
|
||||||
|
|
||||||
remaining_ticks = t->delta_ticks_from_prev;
|
remaining_ticks = t->delta_ticks_from_prev;
|
||||||
while (t != &timer->timeout) {
|
while (t != timeout) {
|
||||||
t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q,
|
t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q,
|
||||||
&t->node);
|
&t->node);
|
||||||
remaining_ticks += t->delta_ticks_from_prev;
|
remaining_ticks += t->delta_ticks_from_prev;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue