kernel: Move timeout_remaining API

_timeout_remaining_get() was a function on a struct _timeout, doing
iteration on the timeout list, but it was defined in timer.c (the
higher level abstraction).

Move it to where it belongs.  Also have it return ticks instead of ms
to conform to scheme in the rest of the timeout API.  And rename it to
a more standard zephyr name.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2018-09-28 09:06:37 -07:00 committed by Anas Nashif
commit 52e444bc05
5 changed files with 35 additions and 31 deletions

View file

@ -1483,6 +1483,8 @@ __syscall u32_t k_timer_status_get(struct k_timer *timer);
*/
__syscall u32_t k_timer_status_sync(struct k_timer *timer);
extern s32_t z_timeout_remaining(struct _timeout *timeout);
/**
* @brief Get time remaining before a timer next expires.
*
@ -1497,7 +1499,7 @@ __syscall s32_t k_timer_remaining_get(struct k_timer *timer);
static inline s32_t _impl_k_timer_remaining_get(struct k_timer *timer)
{
return _timeout_remaining_get(&timer->timeout);
return __ticks_to_ms(z_timeout_remaining(&timer->timeout));
}
/**
@ -2730,7 +2732,7 @@ static inline int k_delayed_work_submit(struct k_delayed_work *work,
*/
static inline s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
{
return _timeout_remaining_get(&work->timeout);
return __ticks_to_ms(z_timeout_remaining(&work->timeout));
}
/** @} */

View file

@ -220,8 +220,6 @@ struct _timeout {
_timeout_func_t func;
};
extern s32_t _timeout_remaining_get(struct _timeout *timeout);
/*
* Number of ticks for x seconds. NOTE: With MSEC() or USEC(),
* since it does an integer division, x must be greater or equal to

View file

@ -20,6 +20,8 @@ extern "C" {
#ifdef CONFIG_SYS_CLOCK_EXISTS
struct _thread_base;
extern u64_t z_last_tick_announced;
void _init_timeout(struct _timeout *t, _timeout_func_t fn);
@ -37,6 +39,8 @@ int _abort_thread_timeout(struct k_thread *thread);
s32_t _get_next_timeout_expiry(void);
s32_t z_timeout_remaining(struct _timeout *timeout);
#else
/* Stubs when !CONFIG_SYS_CLOCK_EXISTS */

View file

@ -574,4 +574,31 @@ void _add_thread_timeout(struct k_thread *thread, s32_t timeout_in_ticks)
_add_timeout(&thread->base.timeout, NULL, timeout_in_ticks);
}
s32_t z_timeout_remaining(struct _timeout *timeout)
{
unsigned int key = irq_lock();
s32_t remaining_ticks;
if (timeout->delta_ticks_from_prev == _INACTIVE) {
remaining_ticks = 0;
} else {
/*
* compute remaining ticks by walking the timeout list
* and summing up the various tick deltas involved
*/
struct _timeout *t =
(struct _timeout *)sys_dlist_peek_head(&_timeout_q);
remaining_ticks = t->delta_ticks_from_prev;
while (t != timeout) {
t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q,
&t->node);
remaining_ticks += t->delta_ticks_from_prev;
}
}
irq_unlock(key);
return remaining_ticks;
}
#endif /* CONFIG_SYS_CLOCK_EXISTS */

View file

@ -226,33 +226,6 @@ u32_t _impl_k_timer_status_sync(struct k_timer *timer)
Z_SYSCALL_HANDLER1_SIMPLE(k_timer_status_sync, K_OBJ_TIMER, struct k_timer *);
#endif
s32_t _timeout_remaining_get(struct _timeout *timeout)
{
unsigned int key = irq_lock();
s32_t remaining_ticks;
if (timeout->delta_ticks_from_prev == _INACTIVE) {
remaining_ticks = 0;
} else {
/*
* compute remaining ticks by walking the timeout list
* and summing up the various tick deltas involved
*/
struct _timeout *t =
(struct _timeout *)sys_dlist_peek_head(&_timeout_q);
remaining_ticks = t->delta_ticks_from_prev;
while (t != timeout) {
t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q,
&t->node);
remaining_ticks += t->delta_ticks_from_prev;
}
}
irq_unlock(key);
return __ticks_to_ms(remaining_ticks);
}
#ifdef CONFIG_USERSPACE
Z_SYSCALL_HANDLER1_SIMPLE(k_timer_remaining_get, K_OBJ_TIMER, struct k_timer *);
Z_SYSCALL_HANDLER1_SIMPLE(k_timer_user_data_get, K_OBJ_TIMER, struct k_timer *);