Skip to content

Commit 7c4b539

Browse files
committed
fix: patch for the time slice scheduler
1 parent 3e2beeb commit 7c4b539

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

src/scheduler.c

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ void rt_schedule(void)
355355
{
356356
rt_schedule_insert_thread(current_thread);
357357
}
358-
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
359358
}
360359
to_thread->oncpu = cpu_id;
361360
if (to_thread != current_thread)
@@ -455,7 +454,6 @@ void rt_schedule(void)
455454
{
456455
need_insert_from_thread = 1;
457456
}
458-
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
459457
}
460458

461459
if (to_thread != rt_current_thread)
@@ -669,9 +667,6 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
669667
goto __exit;
670668
}
671669

672-
/* READY thread, insert to ready queue */
673-
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
674-
675670
cpu_id = rt_hw_cpu_id();
676671
bind_cpu = thread->bind_cpu ;
677672

@@ -683,16 +678,24 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
683678
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
684679
rt_thread_ready_priority_group |= thread->number_mask;
685680

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)
688682
{
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+
{
689686
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
690687
&(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+
}
691695
}
692-
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
693696
else
694697
{
695-
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
698+
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
696699
&(thread->tlist));
697700
}
698701

@@ -708,13 +711,21 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
708711
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
709712
pcpu->priority_group |= thread->number_mask;
710713

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)
713715
{
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+
{
714719
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+
}
716728
}
717-
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
718729
else
719730
{
720731
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)
727738
rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
728739
}
729740
}
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);
731745
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n",
732746
RT_NAME_MAX, thread->name, thread->current_priority));
733747

@@ -752,21 +766,31 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
752766
goto __exit;
753767
}
754768

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)
759770
{
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+
}
762783
}
763-
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
764784
else
765785
{
766-
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
786+
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
767787
&(thread->tlist));
768-
}
769788

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);
770794
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n",
771795
RT_NAME_MAX, thread->name, thread->current_priority));
772796

0 commit comments

Comments
 (0)