nanokernel: Add callback to _nano_timeout once again

It is now safe to introduce the callback since nano_timer_init now
calls _nano_timeout_init which does takes care of initializing all
the fields properly.

Change-Id: I5735eeebef233a0a541ec8b2a354b65da98082fc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2016-05-23 11:17:37 +03:00 committed by Anas Nashif
parent 4afb4e4150
commit 967f8fb602
3 changed files with 16 additions and 3 deletions

View file

@ -59,11 +59,16 @@ struct _nano_queue {
#include <misc/dlist.h>
struct _nano_timeout;
typedef void (*_nano_timeout_func_t)(struct _nano_timeout *t);
struct _nano_timeout {
sys_dlist_t node;
struct tcs *tcs;
struct _nano_queue *wait_q;
int32_t delta_ticks_from_prev;
_nano_timeout_func_t func;
};
/**
* @endcond

View file

@ -35,7 +35,8 @@ static inline void _do_nano_timeout_add(struct tcs *tcs,
struct _nano_queue *wait_q,
int32_t timeout);
static inline void _nano_timeout_init(struct _nano_timeout *t)
static inline void _nano_timeout_init(struct _nano_timeout *t,
_nano_timeout_func_t func)
{
/*
* Must be initialized here and when dequeueing a timeout so that code
@ -55,6 +56,11 @@ static inline void _nano_timeout_init(struct _nano_timeout *t)
* routine can check if there is a fiber waiting on this timeout
*/
t->tcs = NULL;
/*
* Set callback function
*/
t->func = func;
}
#if defined(CONFIG_NANO_TIMEOUTS)
@ -63,7 +69,7 @@ static inline void _nano_timeout_init(struct _nano_timeout *t)
static inline void _nano_timeout_tcs_init(struct tcs *tcs)
{
_nano_timeout_init(&tcs->nano_timeout);
_nano_timeout_init(&tcs->nano_timeout, NULL);
/*
* These are initialized when enqueing on the timeout queue:
@ -131,6 +137,8 @@ static inline struct _nano_timeout *_nano_timeout_handle_one_timeout(
} else {
_nano_fiber_ready(tcs);
}
} else if (t->func) {
t->func(t);
}
t->delta_ticks_from_prev = -1;

View file

@ -23,7 +23,7 @@
void nano_timer_init(struct nano_timer *timer, void *data)
{
/* initialize timeout_data */
_nano_timeout_init(&timer->timeout_data);
_nano_timeout_init(&timer->timeout_data, NULL);
/* nano_timer_test() returns NULL on timer that was not started */
timer->user_data = NULL;