@@ -890,6 +890,24 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
890
890
BaseType_t xPriorityDropped = pdFALSE ;
891
891
#endif
892
892
893
+ /* A new task is created and a running task with the same priority yields
894
+ * itself to run the new task. When a running task yields itself, it is still
895
+ * in the ready list. This running task will be selected before the new task
896
+ * since the new task is always added to the end of the ready list.
897
+ * The other problem is that the running task still in the same position of
898
+ * the ready list when it yields itself. It is possible that it will be selected
899
+ * earlier then other tasks which waits longer than this task.
900
+ *
901
+ * To fix these problems, the running task should be put to the end of the
902
+ * ready list before searching for the ready task in the ready list. */
903
+ if ( listIS_CONTAINED_WITHIN ( & ( pxReadyTasksLists [ pxCurrentTCBs [ xCoreID ]-> uxPriority ] ),
904
+ & pxCurrentTCBs [ xCoreID ]-> xStateListItem ) == pdTRUE )
905
+ {
906
+ uxListRemove ( & pxCurrentTCBs [ xCoreID ]-> xStateListItem );
907
+ vListInsertEnd ( & ( pxReadyTasksLists [ pxCurrentTCBs [ xCoreID ]-> uxPriority ] ),
908
+ & pxCurrentTCBs [ xCoreID ]-> xStateListItem );
909
+ }
910
+
893
911
while ( xTaskScheduled == pdFALSE )
894
912
{
895
913
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
@@ -970,10 +988,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
970
988
971
989
if ( xTaskScheduled != pdFALSE )
972
990
{
973
- /* Once a task has been selected to run on this core,
974
- * move it to the end of the ready task list. */
975
- uxListRemove ( pxIterator );
976
- vListInsertEnd ( pxReadyList , pxIterator );
991
+ /* A task has been selected to run on this core. */
977
992
break ;
978
993
}
979
994
}
0 commit comments