Merge pull request #1973 from Guozhanxin/master

[kernel]修改定时器 hook 函数
This commit is contained in:
Bernard Xiong 2018-11-13 13:09:31 +08:00 committed by GitHub
commit 420478a052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -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
/**@}*/

View File

@ -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 */