From 967f8fb602aa5c0329c678719a2809718d32201f Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 23 May 2016 11:17:37 +0300 Subject: [PATCH] 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 --- include/nanokernel.h | 5 +++++ kernel/nanokernel/include/timeout_q.h | 12 ++++++++++-- kernel/nanokernel/nano_timer.c | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/nanokernel.h b/include/nanokernel.h index d79bde67ef..68857ad1fb 100644 --- a/include/nanokernel.h +++ b/include/nanokernel.h @@ -59,11 +59,16 @@ struct _nano_queue { #include +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 diff --git a/kernel/nanokernel/include/timeout_q.h b/kernel/nanokernel/include/timeout_q.h index 2ae5cf161d..619728ffbe 100644 --- a/kernel/nanokernel/include/timeout_q.h +++ b/kernel/nanokernel/include/timeout_q.h @@ -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; diff --git a/kernel/nanokernel/nano_timer.c b/kernel/nanokernel/nano_timer.c index 06c89ec99e..14a23bcd3f 100644 --- a/kernel/nanokernel/nano_timer.c +++ b/kernel/nanokernel/nano_timer.c @@ -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;