diff options
| author | Shell <[email protected]> | 2023-12-23 17:59:18 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2024-01-02 19:42:46 +0800 |
| commit | e7880a9713ef3efed9ad133231981761bcc3e4eb (patch) | |
| tree | 14909d6f79c1c39c89aa462a58779542e6f415d2 /src | |
| parent | 3a7903b799c9f379048368df029cac3e42c28be4 (diff) | |
[kernel] support for hook list
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/Kconfig | 7 | ||||
| -rw-r--r-- | src/clock.c | 4 | ||||
| -rw-r--r-- | src/ipc.c | 10 | ||||
| -rw-r--r-- | src/irq.c | 7 | ||||
| -rw-r--r-- | src/kservice.c | 6 | ||||
| -rw-r--r-- | src/mempool.c | 7 | ||||
| -rw-r--r-- | src/object.c | 16 | ||||
| -rw-r--r-- | src/scheduler_mp.c | 7 | ||||
| -rw-r--r-- | src/scheduler_up.c | 7 | ||||
| -rw-r--r-- | src/thread.c | 23 | ||||
| -rw-r--r-- | src/timer.c | 13 |
11 files changed, 10 insertions, 97 deletions
diff --git a/src/Kconfig b/src/Kconfig index 2d1387b14d..75e19744e2 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -132,6 +132,13 @@ config RT_USING_HOOK default y endif +config RT_USING_HOOKLIST + bool "Enable hook list" + default n + help + Enable the hook list feature for rt-thread packages. With this, they can + plug in to the system on run-time. + config RT_USING_IDLE_HOOK bool "Enable IDLE Task hook" default y if RT_USING_HOOK diff --git a/src/clock.c b/src/clock.c index a029e19110..9dd447f3f2 100644 --- a/src/clock.c +++ b/src/clock.c @@ -29,10 +29,6 @@ static volatile rt_atomic_t rt_tick = 0; #endif /* RT_USING_SMP */ -#ifndef __on_rt_tick_hook - #define __on_rt_tick_hook() __ON_HOOK_ARGS(rt_tick_hook, ()) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_tick_hook)(void); @@ -55,16 +55,6 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> -#ifndef __on_rt_object_trytake_hook - #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent)) -#endif -#ifndef __on_rt_object_take_hook - #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) -#endif -#ifndef __on_rt_object_put_hook - #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) -#endif - #define GET_MESSAGEBYTE_ADDR(msg) ((struct rt_mq_message *) msg + 1) #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) extern void (*rt_object_trytake_hook)(struct rt_object *object); @@ -22,13 +22,6 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> -#ifndef __on_rt_interrupt_enter_hook - #define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ()) -#endif -#ifndef __on_rt_interrupt_leave_hook - #define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ()) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_interrupt_enter_hook)(void); diff --git a/src/kservice.c b/src/kservice.c index c6e39730ef..3a42b65410 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1579,7 +1579,7 @@ rt_err_t rt_backtrace_frame(struct rt_hw_backtrace_frame *frame) { long nesting = 0; - rt_kprintf("please use: addr2line -e rtthread.elf -a -f\n"); + rt_kprintf("please use: addr2line -e rtthread.elf -a -f"); while (nesting < RT_BACKTRACE_LEVEL_MAX_NR) { @@ -2177,10 +2177,6 @@ int __rt_ffs(int value) #endif /* RT_USING_TINY_FFS */ #endif /* RT_USING_CPU_FFS */ -#ifndef __on_rt_assert_hook - #define __on_rt_assert_hook(ex, func, line) __ON_HOOK_ARGS(rt_assert_hook, (ex, func, line)) -#endif - #ifdef RT_USING_DEBUG /* RT_ASSERT(EX)'s hook */ diff --git a/src/mempool.c b/src/mempool.c index 4fdba42715..accc18e6d4 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -24,13 +24,6 @@ #ifdef RT_USING_MEMPOOL -#ifndef __on_rt_mp_alloc_hook - #define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block)) -#endif -#ifndef __on_rt_mp_free_hook - #define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_mp_alloc_hook)(struct rt_mempool *mp, void *block); static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block); diff --git a/src/object.c b/src/object.c index 791e183d5c..2d9f5c2f51 100644 --- a/src/object.c +++ b/src/object.c @@ -137,22 +137,6 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] = #endif }; -#ifndef __on_rt_object_attach_hook - #define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj)) -#endif -#ifndef __on_rt_object_detach_hook - #define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj)) -#endif -#ifndef __on_rt_object_trytake_hook - #define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent)) -#endif -#ifndef __on_rt_object_take_hook - #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) -#endif -#ifndef __on_rt_object_put_hook - #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_object_attach_hook)(struct rt_object *object); static void (*rt_object_detach_hook)(struct rt_object *object); diff --git a/src/scheduler_mp.c b/src/scheduler_mp.c index 9b72011963..06193c388e 100644 --- a/src/scheduler_mp.c +++ b/src/scheduler_mp.c @@ -48,13 +48,6 @@ rt_uint32_t rt_thread_ready_priority_group; rt_uint8_t rt_thread_ready_table[32]; #endif /* RT_THREAD_PRIORITY_MAX > 32 */ -#ifndef __on_rt_scheduler_hook - #define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to)) -#endif -#ifndef __on_rt_scheduler_switch_hook - #define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); diff --git a/src/scheduler_up.c b/src/scheduler_up.c index 34193b0acc..635b55f7d9 100644 --- a/src/scheduler_up.c +++ b/src/scheduler_up.c @@ -51,13 +51,6 @@ static rt_int16_t rt_scheduler_lock_nest; struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; -#ifndef __on_rt_scheduler_hook - #define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to)) -#endif -#ifndef __on_rt_scheduler_switch_hook - #define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); diff --git a/src/thread.c b/src/thread.c index 9f2a89ee4f..9f1a9f3cfb 100644 --- a/src/thread.c +++ b/src/thread.c @@ -45,20 +45,9 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> -#ifndef __on_rt_thread_inited_hook - #define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread)) -#endif -#ifndef __on_rt_thread_suspend_hook - #define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread)) -#endif -#ifndef __on_rt_thread_resume_hook - #define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_thread_suspend_hook)(rt_thread_t thread); static void (*rt_thread_resume_hook) (rt_thread_t thread); -static void (*rt_thread_inited_hook) (rt_thread_t thread); /** * @brief This function sets a hook function when the system suspend a thread. @@ -84,15 +73,7 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread)) rt_thread_resume_hook = hook; } -/** - * @brief This function sets a hook function when a thread is initialized. - * - * @param hook is the specified hook function. - */ -void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread)) -{ - rt_thread_inited_hook = hook; -} +RT_OBJECT_HOOKLIST_DEFINE(rt_thread_inited); #endif /* defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) */ static void _thread_exit(void) @@ -313,7 +294,7 @@ static rt_err_t _thread_init(struct rt_thread *thread, rt_atomic_store(&thread->ref_count, 0); rt_spin_lock_init(&thread->spinlock); - RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread)); + RT_OBJECT_HOOKLIST_CALL(rt_thread_inited, (thread)); return RT_EOK; } diff --git a/src/timer.c b/src/timer.c index 82eee31e7b..2f1ad9c718 100644 --- a/src/timer.c +++ b/src/timer.c @@ -57,19 +57,6 @@ rt_align(RT_ALIGN_SIZE) static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #endif /* RT_USING_TIMER_SOFT */ -#ifndef __on_rt_object_take_hook - #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent)) -#endif -#ifndef __on_rt_object_put_hook - #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent)) -#endif -#ifndef __on_rt_timer_enter_hook - #define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t)) -#endif -#ifndef __on_rt_timer_exit_hook - #define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t)) -#endif - #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); |
