Skip to content

Commit 23750ac

Browse files
authored
Merge pull request #5490 from GorgonMeducer/master
move some __on_rt_xxxxx_hook from rtdef.h to dedicated c soure files
2 parents 5206f65 + 844f2ef commit 23750ac

File tree

9 files changed

+91
-56
lines changed

9 files changed

+91
-56
lines changed

include/rtdef.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* 2021-11-19 Meco Man change version number to v4.1.0
4040
* 2021-12-21 Meco Man re-implement RT_UNUSED
4141
* 2022-01-01 Gabriel improve hooking method
42+
* 2022-01-07 Gabriel move some __on_rt_xxxxx_hook to dedicated c soure files
4243
*/
4344

4445
#ifndef __RT_DEF_H__
@@ -450,12 +451,6 @@ struct rt_object_information
450451
#endif
451452
#endif
452453

453-
#ifndef __on_rt_interrupt_enter_hook
454-
#define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ())
455-
#endif
456-
#ifndef __on_rt_interrupt_leave_hook
457-
#define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ())
458-
#endif
459454
#ifndef __on_rt_interrupt_switch_hook
460455
#define __on_rt_interrupt_switch_hook() __ON_HOOK_ARGS(rt_interrupt_switch_hook, ())
461456
#endif
@@ -465,48 +460,7 @@ struct rt_object_information
465460
#ifndef __on_rt_free_hook
466461
#define __on_rt_free_hook(rmem) __ON_HOOK_ARGS(rt_free_hook, (rmem))
467462
#endif
468-
#ifndef __on_rt_mp_alloc_hook
469-
#define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block))
470-
#endif
471-
#ifndef __on_rt_mp_free_hook
472-
#define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block))
473-
#endif
474-
#ifndef __on_rt_object_trytake_hook
475-
#define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent))
476-
#endif
477-
#ifndef __on_rt_object_take_hook
478-
#define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
479-
#endif
480-
#ifndef __on_rt_object_put_hook
481-
#define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
482-
#endif
483-
#ifndef __on_rt_scheduler_hook
484-
#define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to))
485-
#endif
486-
#ifndef __on_rt_scheduler_switch_hook
487-
#define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid))
488-
#endif
489-
#ifndef __on_rt_object_attach_hook
490-
#define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj))
491-
#endif
492-
#ifndef __on_rt_object_detach_hook
493-
#define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj))
494-
#endif
495-
#ifndef __on_rt_thread_inited_hook
496-
#define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread))
497-
#endif
498-
#ifndef __on_rt_thread_suspend_hook
499-
#define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread))
500-
#endif
501-
#ifndef __on_rt_thread_resume_hook
502-
#define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread))
503-
#endif
504-
#ifndef __on_rt_timer_enter_hook
505-
#define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t))
506-
#endif
507-
#ifndef __on_rt_timer_exit_hook
508-
#define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t))
509-
#endif
463+
510464

511465
/**@}*/
512466

src/ipc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@
3939
* 2020-10-11 Meco Man add value overflow-check code
4040
* 2021-01-03 Meco Man implement rt_mb_urgent()
4141
* 2021-05-30 Meco Man implement rt_mutex_trytake()
42+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to ipc.c
4243
*/
4344

4445
#include <rtthread.h>
4546
#include <rthw.h>
4647

47-
#ifdef RT_USING_HOOK
48+
#ifndef __on_rt_object_trytake_hook
49+
#define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent))
50+
#endif
51+
#ifndef __on_rt_object_take_hook
52+
#define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
53+
#endif
54+
#ifndef __on_rt_object_put_hook
55+
#define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
56+
#endif
57+
58+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
4859
extern void (*rt_object_trytake_hook)(struct rt_object *object);
4960
extern void (*rt_object_take_hook)(struct rt_object *object);
5061
extern void (*rt_object_put_hook)(struct rt_object *object);

src/irq.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
* 2016-08-09 ArdaFu add interrupt enter and leave hook.
1111
* 2018-11-22 Jesven rt_interrupt_get_nest function add disable irq
1212
* 2021-08-15 Supperthomas fix the comment
13+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to irq.c
1314
*/
1415

1516
#include <rthw.h>
1617
#include <rtthread.h>
1718

18-
#ifdef RT_USING_HOOK
19+
#ifndef __on_rt_interrupt_enter_hook
20+
#define __on_rt_interrupt_enter_hook() __ON_HOOK_ARGS(rt_interrupt_enter_hook, ())
21+
#endif
22+
#ifndef __on_rt_interrupt_leave_hook
23+
#define __on_rt_interrupt_leave_hook() __ON_HOOK_ARGS(rt_interrupt_leave_hook, ())
24+
#endif
25+
26+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
1927

2028
static void (*rt_interrupt_enter_hook)(void);
2129
static void (*rt_interrupt_leave_hook)(void);

src/kservice.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* 2015-07-06 Bernard Add rt_assert_handler routine.
2020
* 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
2121
* 2021-12-20 Meco Man implement rt_strcpy()
22+
* 2022-01-07 Gabriel add __on_rt_assert_hook
2223
*/
2324

2425
#include <rtthread.h>
@@ -1745,6 +1746,10 @@ int __rt_ffs(int value)
17451746
#endif /* RT_USING_TINY_FFS */
17461747
#endif /* RT_USING_CPU_FFS */
17471748

1749+
#ifndef __on_rt_assert_hook
1750+
#define __on_rt_assert_hook(ex, func, line) __ON_HOOK_ARGS(rt_assert_hook, (ex, func, line))
1751+
#endif
1752+
17481753
#ifdef RT_DEBUG
17491754
/* RT_ASSERT(EX)'s hook */
17501755

src/mempool.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414
* 2010-10-26 yi.qiu add module support in rt_mp_delete
1515
* 2011-01-24 Bernard add object allocation check.
1616
* 2012-03-22 Bernard fix align issue in rt_mp_init and rt_mp_create.
17+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to mempool.c
1718
*/
1819

1920
#include <rthw.h>
2021
#include <rtthread.h>
2122

2223
#ifdef RT_USING_MEMPOOL
2324

24-
#ifdef RT_USING_HOOK
25+
#ifndef __on_rt_mp_alloc_hook
26+
#define __on_rt_mp_alloc_hook(mp, block) __ON_HOOK_ARGS(rt_mp_alloc_hook, (mp, block))
27+
#endif
28+
#ifndef __on_rt_mp_free_hook
29+
#define __on_rt_mp_free_hook(mp, block) __ON_HOOK_ARGS(rt_mp_free_hook, (mp, block))
30+
#endif
31+
32+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
2533
static void (*rt_mp_alloc_hook)(struct rt_mempool *mp, void *block);
2634
static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block);
2735

src/object.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* 2010-10-26 yi.qiu add module support in rt_object_allocate and rt_object_free
1414
* 2017-12-10 Bernard Add object_info enum.
1515
* 2018-01-25 Bernard Fix the object find issue when enable MODULE.
16+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to object.c
1617
*/
1718

1819
#include <rtthread.h>
@@ -113,7 +114,23 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] =
113114
#endif
114115
};
115116

116-
#ifdef RT_USING_HOOK
117+
#ifndef __on_rt_object_attach_hook
118+
#define __on_rt_object_attach_hook(obj) __ON_HOOK_ARGS(rt_object_attach_hook, (obj))
119+
#endif
120+
#ifndef __on_rt_object_detach_hook
121+
#define __on_rt_object_detach_hook(obj) __ON_HOOK_ARGS(rt_object_detach_hook, (obj))
122+
#endif
123+
#ifndef __on_rt_object_trytake_hook
124+
#define __on_rt_object_trytake_hook(parent) __ON_HOOK_ARGS(rt_object_trytake_hook, (parent))
125+
#endif
126+
#ifndef __on_rt_object_take_hook
127+
#define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
128+
#endif
129+
#ifndef __on_rt_object_put_hook
130+
#define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
131+
#endif
132+
133+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
117134
static void (*rt_object_attach_hook)(struct rt_object *object);
118135
static void (*rt_object_detach_hook)(struct rt_object *object);
119136
void (*rt_object_trytake_hook)(struct rt_object *object);

src/scheduler.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* rt_schedule_insert_thread won't insert current task to ready queue
2828
* in smp version, rt_hw_context_switch_interrupt maybe switch to
2929
* new task directly
30-
*
30+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to scheduler.c
3131
*/
3232

3333
#include <rtthread.h>
@@ -47,7 +47,14 @@ struct rt_thread *rt_current_thread = RT_NULL;
4747
rt_uint8_t rt_current_priority;
4848
#endif /* RT_USING_SMP */
4949

50-
#ifdef RT_USING_HOOK
50+
#ifndef __on_rt_scheduler_hook
51+
#define __on_rt_scheduler_hook(from, to) __ON_HOOK_ARGS(rt_scheduler_hook, (from, to))
52+
#endif
53+
#ifndef __on_rt_scheduler_switch_hook
54+
#define __on_rt_scheduler_switch_hook(tid) __ON_HOOK_ARGS(rt_scheduler_switch_hook, (tid))
55+
#endif
56+
57+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
5158
static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
5259
static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
5360

src/thread.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@
2828
* add support for tasks bound to cpu
2929
* 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it
3030
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
31+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to thread.c
3132
*/
3233

3334
#include <rthw.h>
3435
#include <rtthread.h>
3536
#include <stddef.h>
3637

37-
#ifdef RT_USING_HOOK
38+
#ifndef __on_rt_thread_inited_hook
39+
#define __on_rt_thread_inited_hook(thread) __ON_HOOK_ARGS(rt_thread_inited_hook, (thread))
40+
#endif
41+
#ifndef __on_rt_thread_suspend_hook
42+
#define __on_rt_thread_suspend_hook(thread) __ON_HOOK_ARGS(rt_thread_suspend_hook, (thread))
43+
#endif
44+
#ifndef __on_rt_thread_resume_hook
45+
#define __on_rt_thread_resume_hook(thread) __ON_HOOK_ARGS(rt_thread_resume_hook, (thread))
46+
#endif
47+
48+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
3849
static void (*rt_thread_suspend_hook)(rt_thread_t thread);
3950
static void (*rt_thread_resume_hook) (rt_thread_t thread);
4051
static void (*rt_thread_inited_hook) (rt_thread_t thread);

src/timer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
1818
* timeout function.
1919
* 2021-08-15 supperthomas add the comment
20+
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to timer.c
2021
*/
2122

2223
#include <rtthread.h>
@@ -47,7 +48,20 @@ ALIGN(RT_ALIGN_SIZE)
4748
static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
4849
#endif /* RT_USING_TIMER_SOFT */
4950

50-
#ifdef RT_USING_HOOK
51+
#ifndef __on_rt_object_take_hook
52+
#define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
53+
#endif
54+
#ifndef __on_rt_object_put_hook
55+
#define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
56+
#endif
57+
#ifndef __on_rt_timer_enter_hook
58+
#define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t))
59+
#endif
60+
#ifndef __on_rt_timer_exit_hook
61+
#define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t))
62+
#endif
63+
64+
#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
5165
extern void (*rt_object_take_hook)(struct rt_object *object);
5266
extern void (*rt_object_put_hook)(struct rt_object *object);
5367
static void (*rt_timer_enter_hook)(struct rt_timer *timer);

0 commit comments

Comments
 (0)