3333 * 2025-06-01 htl5241 fix task miss and performance improvement
3434 */
3535
36+ #include "rttypes.h"
3637#define __RT_IPC_SOURCE__
3738#include <rtthread.h>
3839#include <rthw.h>
@@ -45,8 +46,8 @@ rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
4546rt_uint32_t rt_thread_ready_priority_group ;
4647rt_base_t rt_thread_ready_highest_priority ;
4748#if RT_THREAD_PRIORITY_MAX > 32
48- /* Maximum priority level, 256 */
49- rt_uint8_t rt_thread_ready_table [32 ];
49+ /* Maximum priority level, 256 */
50+ rt_uint8_t rt_thread_ready_table [32 ];
5051#endif /* RT_THREAD_PRIORITY_MAX > 32 */
5152
5253extern volatile rt_atomic_t rt_interrupt_nest ;
@@ -107,7 +108,7 @@ _scheduler_get_priority_thread(rt_ubase_t priority)
107108{
108109 /* get highest ready priority thread */
109110 return RT_THREAD_LIST_NODE_ENTRY (
110- rt_thread_priority_table [priority ].next );
111+ rt_thread_priority_table [priority ].next );
111112}
112113
113114rt_err_t rt_sched_lock (rt_sched_lock_level_t * plvl )
@@ -175,7 +176,7 @@ void rt_system_scheduler_start(void)
175176
176177 _scheduler_update_highest_priority ();
177178 to_thread = _scheduler_get_priority_thread (
178- rt_thread_ready_highest_priority );
179+ rt_thread_ready_highest_priority );
179180
180181 rt_cpu_self ()-> current_thread = to_thread ;
181182
@@ -208,15 +209,15 @@ rt_inline void _rt_sched_insert_thread(struct rt_thread *thread)
208209 {
209210 rt_list_insert_before (
210211 & (rt_thread_priority_table [RT_SCHED_PRIV (thread )
211- .current_priority ]),
212+ .current_priority ]),
212213 & RT_THREAD_LIST_NODE (thread ));
213214 }
214215 /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
215216 else
216217 {
217218 rt_list_insert_after (
218219 & (rt_thread_priority_table [RT_SCHED_PRIV (thread )
219- .current_priority ]),
220+ .current_priority ]),
220221 & RT_THREAD_LIST_NODE (thread ));
221222 }
222223
@@ -248,7 +249,7 @@ rt_inline void _rt_sched_remove_thread(struct rt_thread *thread)
248249 /* remove thread from ready list */
249250 rt_list_remove (& RT_THREAD_LIST_NODE (thread ));
250251 if (rt_list_isempty (
251- & (rt_thread_priority_table [RT_SCHED_PRIV (thread )
252+ & (rt_thread_priority_table [RT_SCHED_PRIV (thread )
252253 .current_priority ])))
253254 {
254255#if RT_THREAD_PRIORITY_MAX > 32
@@ -280,8 +281,6 @@ rt_inline void _rt_sched_remove_thread(struct rt_thread *thread)
280281void rt_schedule (void )
281282{
282283 rt_base_t level ;
283- /* need_insert_from_thread: need to insert from_thread to ready queue */
284- int need_insert_from_thread ;
285284 /* using local variable to avoid unecessary function call */
286285 struct rt_thread * curr_thread ;
287286 struct rt_thread * to_thread ;
@@ -292,6 +291,9 @@ void rt_schedule(void)
292291 /* check the scheduler is enabled or not */
293292 if (rt_scheduler_lock_nest == 0 && rt_thread_ready_priority_group )
294293 {
294+ /* need_insert_from_thread: need to insert from_thread to ready queue */
295+ rt_bool_t need_insert_from_thread = RT_FALSE ;
296+
295297 curr_thread = rt_thread_self ();
296298
297299 if ((RT_SCHED_CTX (curr_thread ).stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
@@ -307,15 +309,14 @@ void rt_schedule(void)
307309 else
308310 {
309311 to_thread = _scheduler_get_priority_thread (
310- rt_thread_ready_highest_priority );
311- need_insert_from_thread = 1 ;
312+ rt_thread_ready_highest_priority );
313+ need_insert_from_thread = RT_TRUE ;
312314 }
313315 }
314316 else
315317 {
316318 to_thread = _scheduler_get_priority_thread (
317- rt_thread_ready_highest_priority );
318- need_insert_from_thread = 0 ;
319+ rt_thread_ready_highest_priority );
319320 }
320321
321322 if (to_thread != curr_thread )
0 commit comments