unified: remaining timeout cleanup

Rename remaining functions to fit with kernel naming convention for
internal interfaces. Use struct k_thread instead of struct tcs.

Change-Id: I28cd7f6f4d7ddaeb825c8d2999242d8d2dd93f31
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
Benjamin Walsh 2016-10-05 17:16:01 -04:00
commit 055262c159
8 changed files with 51 additions and 57 deletions

View file

@ -142,7 +142,7 @@ extern void k_thread_abort(k_tid_t thread);
#define _THREAD_TIMEOUT_INIT(obj) \ #define _THREAD_TIMEOUT_INIT(obj) \
(obj).nano_timeout = { \ (obj).nano_timeout = { \
.node = { {0}, {0} }, \ .node = { {0}, {0} }, \
.tcs = NULL, \ .thread = NULL, \
.wait_q = NULL, \ .wait_q = NULL, \
.delta_ticks_from_prev = -1, \ .delta_ticks_from_prev = -1, \
}, },
@ -256,7 +256,7 @@ typedef void (*_timeout_func_t)(struct _timeout *t);
struct _timeout { struct _timeout {
sys_dlist_t node; sys_dlist_t node;
struct tcs *tcs; struct k_thread *thread;
sys_dlist_t *wait_q; sys_dlist_t *wait_q;
int32_t delta_ticks_from_prev; int32_t delta_ticks_from_prev;
_timeout_func_t func; _timeout_func_t func;

View file

@ -132,7 +132,7 @@ void idle(void *unused1, void *unused2, void *unused3)
ARG_UNUSED(unused3); ARG_UNUSED(unused3);
for (;;) { for (;;) {
_sys_power_save_idle(_timeout_get_next_expiry()); _sys_power_save_idle(_get_next_timeout_expiry());
k_yield(); k_yield();
} }

View file

@ -30,9 +30,9 @@ extern "C" {
#endif #endif
#if defined(CONFIG_NANO_TIMEOUTS) #if defined(CONFIG_NANO_TIMEOUTS)
/* initialize the nano timeouts part of TCS when enabled in the kernel */ /* initialize the nano timeouts part of k_thread when enabled in the kernel */
static inline void _timeout_init(struct _timeout *t, _timeout_func_t func) static inline void _init_timeout(struct _timeout *t, _timeout_func_t func)
{ {
/* /*
* Must be initialized here and when dequeueing a timeout so that code * Must be initialized here and when dequeueing a timeout so that code
@ -48,10 +48,10 @@ static inline void _timeout_init(struct _timeout *t, _timeout_func_t func)
t->wait_q = NULL; t->wait_q = NULL;
/* /*
* Must be initialized here, so the _timeout_handle_one_timeout() * Must be initialized here, so the _handle_one_timeout()
* routine can check if there is a fiber waiting on this timeout * routine can check if there is a fiber waiting on this timeout
*/ */
t->tcs = NULL; t->thread = NULL;
/* /*
* Function must be initialized before being potentially called. * Function must be initialized before being potentially called.
@ -61,36 +61,27 @@ static inline void _timeout_init(struct _timeout *t, _timeout_func_t func)
/* /*
* These are initialized when enqueing on the timeout queue: * These are initialized when enqueing on the timeout queue:
* *
* tcs->timeout.node.next * thread->timeout.node.next
* tcs->timeout.node.prev * thread->timeout.node.prev
*/ */
} }
static inline void _timeout_tcs_init(struct tcs *tcs) static inline void _init_thread_timeout(struct k_thread *thread)
{ {
_timeout_init(&tcs->timeout, NULL); _init_timeout(&thread->timeout, NULL);
} }
/* /*
* XXX - backwards compatibility until the arch part is updated to call * XXX - backwards compatibility until the arch part is updated to call
* _timeout_tcs_init() * _init_thread_timeout()
*/ */
static inline void _nano_timeout_tcs_init(struct tcs *tcs) static inline void _nano_timeout_tcs_init(struct tcs *tcs)
{ {
_timeout_tcs_init(tcs); _init_thread_timeout(tcs);
} }
/** /* remove a thread timing out from kernel object's wait queue */
* @brief Remove the thread from nanokernel object wait queue
*
* If a thread waits on a nanokernel object with timeout,
* remove the thread from the wait queue
*
* @param tcs Waiting thread
* @param t nano timer
*
* @return N/A
*/
static inline void _unpend_thread_timing_out(struct k_thread *thread, static inline void _unpend_thread_timing_out(struct k_thread *thread,
struct _timeout *timeout_obj) struct _timeout *timeout_obj)
{ {
@ -101,27 +92,29 @@ static inline void _unpend_thread_timing_out(struct k_thread *thread,
} }
#else #else
#define _unpend_thread_timing_out(tcs, timeout_obj) do { } while (0) #define _unpend_thread_timing_out(thread, timeout_obj) do { } while (0)
#endif /* CONFIG_NANO_TIMEOUTS */ #endif /* CONFIG_NANO_TIMEOUTS */
/* /*
* Handle one expired timeout. * Handle one expired timeout.
* This removes the fiber from the timeout queue head, and also removes it *
* from the wait queue it is on if waiting for an object. In that case, it * This removes the thread from the timeout queue head, and also removes it
* also sets the return value to 0/NULL. * from the wait queue it is on if waiting for an object. In that case,
* the return value is kept as -EAGAIN, set previously in _Swap().
*
* Must be called with interrupts locked.
*/ */
/* must be called with interrupts locked */ static inline struct _timeout *_handle_one_timeout(
static inline struct _timeout *_timeout_handle_one_timeout(
sys_dlist_t *timeout_q) sys_dlist_t *timeout_q)
{ {
struct _timeout *t = (void *)sys_dlist_get(timeout_q); struct _timeout *t = (void *)sys_dlist_get(timeout_q);
struct tcs *tcs = t->tcs; struct k_thread *thread = t->thread;
K_DEBUG("timeout %p\n", t); K_DEBUG("timeout %p\n", t);
if (tcs != NULL) { if (thread != NULL) {
_unpend_thread_timing_out(tcs, t); _unpend_thread_timing_out(thread, t);
_ready_thread(tcs); _ready_thread(thread);
} else if (t->func) { } else if (t->func) {
t->func(t); t->func(t);
} }
@ -137,27 +130,24 @@ static inline struct _timeout *_timeout_handle_one_timeout(
return (struct _timeout *)sys_dlist_peek_head(timeout_q); return (struct _timeout *)sys_dlist_peek_head(timeout_q);
} }
/* loop over all expired timeouts and handle them one by one */ /*
/* must be called with interrupts locked */ * Loop over all expired timeouts and handle them one by one.
static inline void _timeout_handle_timeouts(void) * Must be called with interrupts locked.
*/
static inline void _handle_timeouts(void)
{ {
sys_dlist_t *timeout_q = &_nanokernel.timeout_q; sys_dlist_t *timeout_q = &_nanokernel.timeout_q;
struct _timeout *next; struct _timeout *next;
next = (struct _timeout *)sys_dlist_peek_head(timeout_q); next = (struct _timeout *)sys_dlist_peek_head(timeout_q);
while (next && next->delta_ticks_from_prev == 0) { while (next && next->delta_ticks_from_prev == 0) {
next = _timeout_handle_one_timeout(timeout_q); next = _handle_one_timeout(timeout_q);
} }
} }
/** /* returns 0 in success and -1 if the timer has expired */
*
* @brief abort a timeout
*
* @param t Timeout to abort
*
* @return 0 in success and -1 if the timer has expired
*/
static inline int _abort_timeout(struct _timeout *t) static inline int _abort_timeout(struct _timeout *t)
{ {
sys_dlist_t *timeout_q = &_nanokernel.timeout_q; sys_dlist_t *timeout_q = &_nanokernel.timeout_q;
@ -195,7 +185,8 @@ static inline int _abort_thread_timeout(struct k_thread *thread)
* the timeout of the insert point to update its delta queue value, since the * the timeout of the insert point to update its delta queue value, since the
* current timeout will be inserted before it. * current timeout will be inserted before it.
*/ */
static int _timeout_insert_point_test(sys_dnode_t *test, void *timeout)
static int _is_timeout_insert_point(sys_dnode_t *test, void *timeout)
{ {
struct _timeout *t = (void *)test; struct _timeout *t = (void *)test;
int32_t *timeout_to_insert = timeout; int32_t *timeout_to_insert = timeout;
@ -214,6 +205,7 @@ static int _timeout_insert_point_test(sys_dnode_t *test, void *timeout)
* *
* Cannot handle timeout == 0 and timeout == K_FOREVER. * Cannot handle timeout == 0 and timeout == K_FOREVER.
*/ */
static inline void _add_timeout(struct k_thread *thread, static inline void _add_timeout(struct k_thread *thread,
struct _timeout *timeout_obj, struct _timeout *timeout_obj,
_wait_q_t *wait_q, int32_t timeout) _wait_q_t *wait_q, int32_t timeout)
@ -233,11 +225,11 @@ static inline void _add_timeout(struct k_thread *thread,
K_DEBUG("timeout %p before: next: %p, prev: %p\n", K_DEBUG("timeout %p before: next: %p, prev: %p\n",
timeout_obj, timeout_obj->node.next, timeout_obj->node.prev); timeout_obj, timeout_obj->node.next, timeout_obj->node.prev);
timeout_obj->tcs = thread; timeout_obj->thread = thread;
timeout_obj->delta_ticks_from_prev = timeout; timeout_obj->delta_ticks_from_prev = timeout;
timeout_obj->wait_q = (sys_dlist_t *)wait_q; timeout_obj->wait_q = (sys_dlist_t *)wait_q;
sys_dlist_insert_at(timeout_q, (void *)timeout_obj, sys_dlist_insert_at(timeout_q, (void *)timeout_obj,
_timeout_insert_point_test, _is_timeout_insert_point,
&timeout_obj->delta_ticks_from_prev); &timeout_obj->delta_ticks_from_prev);
K_DEBUG("timeout_q %p after: head: %p, tail: %p\n", K_DEBUG("timeout_q %p after: head: %p, tail: %p\n",
@ -254,6 +246,7 @@ static inline void _add_timeout(struct k_thread *thread,
* *
* Cannot handle timeout == 0 and timeout == K_FOREVER. * Cannot handle timeout == 0 and timeout == K_FOREVER.
*/ */
static inline void _add_thread_timeout(struct k_thread *thread, static inline void _add_thread_timeout(struct k_thread *thread,
_wait_q_t *wait_q, int32_t timeout) _wait_q_t *wait_q, int32_t timeout)
{ {
@ -261,7 +254,8 @@ static inline void _add_thread_timeout(struct k_thread *thread,
} }
/* find the closest deadline in the timeout queue */ /* find the closest deadline in the timeout queue */
static inline int32_t _timeout_get_next_expiry(void)
static inline int32_t _get_next_timeout_expiry(void)
{ {
struct _timeout *t = (struct _timeout *) struct _timeout *t = (struct _timeout *)
sys_dlist_peek_head(&_timeout_q); sys_dlist_peek_head(&_timeout_q);

View file

@ -35,14 +35,14 @@ extern "C" {
#elif defined(CONFIG_NANO_TIMERS) #elif defined(CONFIG_NANO_TIMERS)
#include <timeout_q.h> #include <timeout_q.h>
#define _timeout_tcs_init(tcs) do { } while ((0)) #define _init_thread_timeout(tcs) do { } while ((0))
#define _abort_thread_timeout(tcs) do { } while ((0)) #define _abort_thread_timeout(tcs) do { } while ((0))
#define _add_thread_timeout(thread, pq, ticks) do { } while (0) #define _add_thread_timeout(thread, pq, ticks) do { } while (0)
#else #else
#define _timeout_tcs_init(tcs) do { } while ((0)) #define _init_thread_timeout(tcs) do { } while ((0))
#define _abort_thread_timeout(tcs) do { } while ((0)) #define _abort_thread_timeout(tcs) do { } while ((0))
#define _timeout_get_next_expiry() (K_FOREVER) #define _get_next_timeout_expiry() (K_FOREVER)
#define _add_thread_timeout(thread, pq, ticks) do { } while (0) #define _add_thread_timeout(thread, pq, ticks) do { } while (0)
#endif #endif

View file

@ -99,7 +99,7 @@ int k_sem_group_take(struct k_sem *sem_array[], struct k_sem **sem,
wait_objects[i].dummy.flags = K_DUMMY; wait_objects[i].dummy.flags = K_DUMMY;
wait_objects[i].dummy.prio = priority; wait_objects[i].dummy.prio = priority;
_timeout_tcs_init((struct k_thread *) &wait_objects[i].dummy); _init_thread_timeout((struct k_thread *)&wait_objects[i].dummy);
sys_dlist_append(&list, &wait_objects[i].desc.semg_node); sys_dlist_append(&list, &wait_objects[i].desc.semg_node);
wait_objects[i].desc.thread = _current; wait_objects[i].desc.thread = _current;

View file

@ -186,7 +186,7 @@ static inline void handle_expired_timeouts(int32_t ticks)
if (head) { if (head) {
head->delta_ticks_from_prev -= ticks; head->delta_ticks_from_prev -= ticks;
_timeout_handle_timeouts(); _handle_timeouts();
} }
} }
#else #else

View file

@ -75,7 +75,7 @@ void k_timer_init(struct k_timer *timer, void *data)
timer->user_data_internal = data; timer->user_data_internal = data;
timer->period = 0; timer->period = 0;
sys_dlist_init(&timer->wait_q); sys_dlist_init(&timer->wait_q);
_timeout_init(&timer->timeout, timer_expiration_handler); _init_timeout(&timer->timeout, timer_expiration_handler);
SYS_TRACING_OBJ_INIT(micro_timer, timer); SYS_TRACING_OBJ_INIT(micro_timer, timer);
} }

View file

@ -75,7 +75,7 @@ static void work_timeout(struct _timeout *t)
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
{ {
k_work_init(&work->work, handler); k_work_init(&work->work, handler);
_timeout_init(&work->timeout, work_timeout); _init_timeout(&work->timeout, work_timeout);
work->work_q = NULL; work->work_q = NULL;
} }