Skip to content

Commit d343c65

Browse files
committed
[kernel]Change 'rt_timer_timeout_hook' function to 'rt_timer_enter_hook' and add 'rt_timer_exit_hook' hook function.
1 parent f6783c6 commit d343c65

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

include/rtthread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ rt_tick_t rt_timer_next_timeout_tick(void);
100100
void rt_timer_check(void);
101101

102102
#ifdef RT_USING_HOOK
103-
void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer));
103+
void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer));
104+
void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer));
104105
#endif
105106

106107
/**@}*/

src/timer.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
4343
#ifdef RT_USING_HOOK
4444
extern void (*rt_object_take_hook)(struct rt_object *object);
4545
extern void (*rt_object_put_hook)(struct rt_object *object);
46-
static void (*rt_timer_timeout_hook)(struct rt_timer *timer);
46+
static void (*rt_timer_enter_hook)(struct rt_timer *timer);
47+
static void (*rt_timer_exit_hook)(struct rt_timer *timer);
4748

4849
/**
4950
* @addtogroup Hook
@@ -52,14 +53,25 @@ static void (*rt_timer_timeout_hook)(struct rt_timer *timer);
5253
/**@{*/
5354

5455
/**
55-
* This function will set a hook function, which will be invoked when timer
56-
* is timeout.
56+
* This function will set a hook function, which will be invoked when enter
57+
* timer timeout callback function.
5758
*
5859
* @param hook the hook function
5960
*/
60-
void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer))
61+
void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer))
6162
{
62-
rt_timer_timeout_hook = hook;
63+
rt_timer_enter_hook = hook;
64+
}
65+
66+
/**
67+
* This function will set a hook function, which will be invoked when exit
68+
* timer timeout callback function.
69+
*
70+
* @param hook the hook function
71+
*/
72+
void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
73+
{
74+
rt_timer_exit_hook = hook;
6375
}
6476

6577
/**@}*/
@@ -503,7 +515,7 @@ void rt_timer_check(void)
503515
*/
504516
if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
505517
{
506-
RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
518+
RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t));
507519

508520
/* remove timer from timer list firstly */
509521
_rt_timer_remove(t);
@@ -514,6 +526,7 @@ void rt_timer_check(void)
514526
/* re-get tick */
515527
current_tick = rt_tick_get();
516528

529+
RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t));
517530
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
518531

519532
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
@@ -578,7 +591,7 @@ void rt_soft_timer_check(void)
578591
*/
579592
if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
580593
{
581-
RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
594+
RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t));
582595

583596
/* move node to the next */
584597
n = n->next;
@@ -594,6 +607,7 @@ void rt_soft_timer_check(void)
594607
/* re-get tick */
595608
current_tick = rt_tick_get();
596609

610+
RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t));
597611
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
598612

599613
/* lock scheduler */

0 commit comments

Comments
 (0)