summaryrefslogtreecommitdiff
path: root/include/rtdef.h
diff options
context:
space:
mode:
authorGabriel Wang <[email protected]>2022-01-01 16:37:41 +0000
committerBernard Xiong <[email protected]>2022-01-05 15:48:42 +0800
commitb627414f67cef4fff44faefac61c512fa19ecbe4 (patch)
treef06bc4eafd04be29f85b4e5d0eb71aaee5ceb166 /include/rtdef.h
parent5e24acf7fac6524ac5e103480f669a9ac7406265 (diff)
Improving hooking methods
- Backward compatible with existing function-pointer based hooking method - Using RT_USING_HOOK as an on/off switch - Introducing a new low-overhead macro-based hooking method
Diffstat (limited to 'include/rtdef.h')
-rw-r--r--include/rtdef.h72
1 files changed, 68 insertions, 4 deletions
diff --git a/include/rtdef.h b/include/rtdef.h
index bc133d4271..a018ceb21d 100644
--- a/include/rtdef.h
+++ b/include/rtdef.h
@@ -38,6 +38,7 @@
* 2021-05-10 armink change version number to v4.0.4
* 2021-11-19 Meco Man change version number to v4.1.0
* 2021-12-21 Meco Man re-implement RT_UNUSED
+ * 2022-01-01 Gabriel improve hooking method
*/
#ifndef __RT_DEF_H__
@@ -437,11 +438,74 @@ struct rt_object_information
/**
* The hook function call macro
*/
-#ifdef RT_USING_HOOK
-#define RT_OBJECT_HOOK_CALL(func, argv) \
- do { if ((func) != RT_NULL) func argv; } while (0)
+#ifndef RT_USING_HOOK
+ #define __ON_HOOK_ARGS(__hook, argv)
+ #define RT_OBJECT_HOOK_CALL(func, argv)
#else
-#define RT_OBJECT_HOOK_CALL(func, argv)
+ #define RT_OBJECT_HOOK_CALL(func, argv) __on_##func argv
+ #ifdef RT_HOOK_USING_FUNC_PTR
+ #define __ON_HOOK_ARGS(__hook, argv) do {if ((__hook) != RT_NULL) __hook argv; } while (0)
+ #else
+ #define __ON_HOOK_ARGS(__hook, argv)
+ #endif
+#endif
+
+#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
+#ifndef __on_rt_interrupt_switch_hook
+ #define __on_rt_interrupt_switch_hook() __ON_HOOK_ARGS(rt_interrupt_switch_hook, ())
+#endif
+#ifndef __on_rt_malloc_hook
+ #define __on_rt_malloc_hook(addr, size) __ON_HOOK_ARGS(rt_malloc_hook, (addr, size))
+#endif
+#ifndef __on_rt_free_hook
+ #define __on_rt_free_hook(rmem) __ON_HOOK_ARGS(rt_free_hook, (rmem))
+#endif
+#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
+#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
+#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
+#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_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
+#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
/**@}*/