From d343c6578a0c12c4bdc98e7634907fb9779ba0d7 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 13 Nov 2018 11:32:01 +0800 Subject: [PATCH] [kernel]Change 'rt_timer_timeout_hook' function to 'rt_timer_enter_hook' and add 'rt_timer_exit_hook' hook function. --- include/rtthread.h | 3 ++- src/timer.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/rtthread.h b/include/rtthread.h index fc5029a22..96ebe1940 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -100,7 +100,8 @@ rt_tick_t rt_timer_next_timeout_tick(void); void rt_timer_check(void); #ifdef RT_USING_HOOK -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)); #endif /**@}*/ diff --git a/src/timer.c b/src/timer.c index dc489a2d0..fd938065d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -43,7 +43,8 @@ static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #ifdef RT_USING_HOOK extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); -static void (*rt_timer_timeout_hook)(struct rt_timer *timer); +static void (*rt_timer_enter_hook)(struct rt_timer *timer); +static void (*rt_timer_exit_hook)(struct rt_timer *timer); /** * @addtogroup Hook @@ -52,14 +53,25 @@ static void (*rt_timer_timeout_hook)(struct rt_timer *timer); /**@{*/ /** - * This function will set a hook function, which will be invoked when timer - * is timeout. + * This function will set a hook function, which will be invoked when enter + * timer timeout callback function. * * @param hook the hook function */ -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)) +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { - rt_timer_timeout_hook = hook; + rt_timer_enter_hook = hook; +} + +/** + * This function will set a hook function, which will be invoked when exit + * timer timeout callback function. + * + * @param hook the hook function + */ +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) +{ + rt_timer_exit_hook = hook; } /**@}*/ @@ -503,7 +515,7 @@ void rt_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ _rt_timer_remove(t); @@ -514,6 +526,7 @@ void rt_timer_check(void) /* re-get tick */ current_tick = rt_tick_get(); + RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && @@ -578,7 +591,7 @@ void rt_soft_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* move node to the next */ n = n->next; @@ -594,6 +607,7 @@ void rt_soft_timer_check(void) /* re-get tick */ current_tick = rt_tick_get(); + RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); /* lock scheduler */ -- GitLab