@@ -683,8 +683,19 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
683683#endif /* RT_THREAD_PRIORITY_MAX > 32 */
684684 rt_thread_ready_priority_group |= thread -> number_mask ;
685685
686- rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
687- & (thread -> tlist ));
686+ /* there is no time slices left(YIELD), inserting thread before ready list*/
687+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
688+ {
689+ rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
690+ & (thread -> tlist ));
691+ }
692+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
693+ else
694+ {
695+ rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
696+ & (thread -> tlist ));
697+ }
698+
688699 cpu_mask = RT_CPU_MASK ^ (1 << cpu_id );
689700 rt_hw_ipi_send (RT_SCHEDULE_IPI , cpu_mask );
690701 }
@@ -697,8 +708,18 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
697708#endif /* RT_THREAD_PRIORITY_MAX > 32 */
698709 pcpu -> priority_group |= thread -> number_mask ;
699710
700- rt_list_insert_before (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
701- & (thread -> tlist ));
711+ /* there is no time slices left(YIELD), inserting thread before ready list*/
712+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
713+ {
714+ rt_list_insert_before (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
715+ & (thread -> tlist ));
716+ }
717+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
718+ else
719+ {
720+ rt_list_insert_after (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
721+ & (thread -> tlist ));
722+ }
702723
703724 if (cpu_id != bind_cpu )
704725 {
@@ -733,9 +754,18 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
733754
734755 /* READY thread, insert to ready queue */
735756 thread -> stat = RT_THREAD_READY | (thread -> stat & ~RT_THREAD_STAT_MASK );
736- /* insert thread to ready list */
737- rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
738- & (thread -> tlist ));
757+ /* there is no time slices left(YIELD), inserting thread before ready list*/
758+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
759+ {
760+ rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
761+ & (thread -> tlist ));
762+ }
763+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
764+ else
765+ {
766+ rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
767+ & (thread -> tlist ));
768+ }
739769
740770 RT_DEBUG_LOG (RT_DEBUG_SCHEDULER , ("insert thread[%.*s], the priority: %d\n" ,
741771 RT_NAME_MAX , thread -> name , thread -> current_priority ));
0 commit comments