@@ -355,7 +355,6 @@ void rt_schedule(void)
355
355
{
356
356
rt_schedule_insert_thread (current_thread );
357
357
}
358
- current_thread -> stat &= ~RT_THREAD_STAT_YIELD_MASK ;
359
358
}
360
359
to_thread -> oncpu = cpu_id ;
361
360
if (to_thread != current_thread )
@@ -455,7 +454,6 @@ void rt_schedule(void)
455
454
{
456
455
need_insert_from_thread = 1 ;
457
456
}
458
- rt_current_thread -> stat &= ~RT_THREAD_STAT_YIELD_MASK ;
459
457
}
460
458
461
459
if (to_thread != rt_current_thread )
@@ -669,9 +667,6 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
669
667
goto __exit ;
670
668
}
671
669
672
- /* READY thread, insert to ready queue */
673
- thread -> stat = RT_THREAD_READY | (thread -> stat & ~RT_THREAD_STAT_MASK );
674
-
675
670
cpu_id = rt_hw_cpu_id ();
676
671
bind_cpu = thread -> bind_cpu ;
677
672
@@ -683,16 +678,24 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
683
678
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
684
679
rt_thread_ready_priority_group |= thread -> number_mask ;
685
680
686
- /* there is no time slices left(YIELD), inserting thread before ready list*/
687
- if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
681
+ if ((thread -> stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
688
682
{
683
+ /* there is no time slices left(YIELD), inserting thread before ready list*/
684
+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) == RT_THREAD_STAT_YIELD )
685
+ {
689
686
rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
690
687
& (thread -> tlist ));
688
+ }
689
+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
690
+ else
691
+ {
692
+ rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
693
+ & (thread -> tlist ));
694
+ }
691
695
}
692
- /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
693
696
else
694
697
{
695
- rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
698
+ rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
696
699
& (thread -> tlist ));
697
700
}
698
701
@@ -708,13 +711,21 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
708
711
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
709
712
pcpu -> priority_group |= thread -> number_mask ;
710
713
711
- /* there is no time slices left(YIELD), inserting thread before ready list*/
712
- if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
714
+ if ((thread -> stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
713
715
{
716
+ /* there is no time slices left(YIELD), inserting thread before ready list*/
717
+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) == RT_THREAD_STAT_YIELD )
718
+ {
714
719
rt_list_insert_before (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
715
- & (thread -> tlist ));
720
+ & (thread -> tlist ));
721
+ }
722
+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
723
+ else
724
+ {
725
+ rt_list_insert_after (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
726
+ & (thread -> tlist ));
727
+ }
716
728
}
717
- /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
718
729
else
719
730
{
720
731
rt_list_insert_after (& (rt_cpu_index (bind_cpu )-> priority_table [thread -> current_priority ]),
@@ -727,7 +738,10 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
727
738
rt_hw_ipi_send (RT_SCHEDULE_IPI , cpu_mask );
728
739
}
729
740
}
730
-
741
+ /* clear YIELD status*/
742
+ thread -> stat &= ~RT_THREAD_STAT_YIELD_MASK ;
743
+ /* READY thread, insert to ready queue */
744
+ thread -> stat = RT_THREAD_READY | (thread -> stat & ~RT_THREAD_STAT_MASK );
731
745
RT_DEBUG_LOG (RT_DEBUG_SCHEDULER , ("insert thread[%.*s], the priority: %d\n" ,
732
746
RT_NAME_MAX , thread -> name , thread -> current_priority ));
733
747
@@ -752,21 +766,31 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
752
766
goto __exit ;
753
767
}
754
768
755
- /* READY thread, insert to ready queue */
756
- thread -> stat = RT_THREAD_READY | (thread -> stat & ~RT_THREAD_STAT_MASK );
757
- /* there is no time slices left(YIELD), inserting thread before ready list*/
758
- if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) != 0 )
769
+ if ((thread -> stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
759
770
{
760
- rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
761
- & (thread -> tlist ));
771
+ /* there is no time slices left(YIELD), inserting thread before ready list*/
772
+ if ((thread -> stat & RT_THREAD_STAT_YIELD_MASK ) == RT_THREAD_STAT_YIELD )
773
+ {
774
+ rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
775
+ & (thread -> tlist ));
776
+ }
777
+ /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
778
+ else
779
+ {
780
+ rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
781
+ & (thread -> tlist ));
782
+ }
762
783
}
763
- /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
764
784
else
765
785
{
766
- rt_list_insert_after (& (rt_thread_priority_table [thread -> current_priority ]),
786
+ rt_list_insert_before (& (rt_thread_priority_table [thread -> current_priority ]),
767
787
& (thread -> tlist ));
768
- }
769
788
789
+ }
790
+ /* clear YIELD status*/
791
+ thread -> stat &= ~RT_THREAD_STAT_YIELD_MASK ;
792
+ /* READY thread, insert to ready queue */
793
+ thread -> stat = RT_THREAD_READY | (thread -> stat & ~RT_THREAD_STAT_MASK );
770
794
RT_DEBUG_LOG (RT_DEBUG_SCHEDULER , ("insert thread[%.*s], the priority: %d\n" ,
771
795
RT_NAME_MAX , thread -> name , thread -> current_priority ));
772
796
0 commit comments