@@ -49,6 +49,7 @@ rt_uint8_t rt_current_priority;
4949
5050#ifdef RT_USING_HOOK
5151static void (* rt_scheduler_hook )(struct rt_thread * from , struct rt_thread * to );
52+ static void (* rt_scheduler_switch_hook )(struct rt_thread * tid );
5253
5354/**
5455 * @addtogroup Hook
@@ -68,6 +69,12 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
6869 rt_scheduler_hook = hook ;
6970}
7071
72+ void
73+ rt_scheduler_switch_sethook (void (* hook )(struct rt_thread * tid ))
74+ {
75+ rt_scheduler_switch_hook = hook ;
76+ }
77+
7178/**@}*/
7279#endif /* RT_USING_HOOK */
7380
@@ -364,6 +371,8 @@ void rt_schedule(void)
364371 _rt_scheduler_stack_check (to_thread );
365372#endif /* RT_USING_OVERFLOW_CHECK */
366373
374+ RT_OBJECT_HOOK_CALL (rt_scheduler_switch_hook , (current_thread ));
375+
367376 rt_hw_context_switch ((rt_ubase_t )& current_thread -> sp ,
368377 (rt_ubase_t )& to_thread -> sp , to_thread );
369378 }
@@ -473,6 +482,8 @@ void rt_schedule(void)
473482 {
474483 extern void rt_thread_handle_sig (rt_bool_t clean_state );
475484
485+ RT_OBJECT_HOOK_CALL (rt_scheduler_switch_hook , (from_thread ));
486+
476487 rt_hw_context_switch ((rt_ubase_t )& from_thread -> sp ,
477488 (rt_ubase_t )& to_thread -> sp );
478489
@@ -609,6 +620,8 @@ void rt_scheduler_do_irq_switch(void *context)
609620 current_thread -> cpus_lock_nest -- ;
610621 current_thread -> scheduler_lock_nest -- ;
611622
623+ RT_OBJECT_HOOK_CALL (rt_scheduler_switch_hook , (current_thread ));
624+
612625 rt_hw_context_switch_interrupt (context , (rt_ubase_t )& current_thread -> sp ,
613626 (rt_ubase_t )& to_thread -> sp , to_thread );
614627 }
0 commit comments